Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/accessibility/ARIAAttributesView.js

Issue 2058323002: Add ARIA panel to accessibility sidebar pane (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test and add test expectation Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @extends {WebInspector.AccessibilitySubPane}
8 */
9 WebInspector.ARIAAttributesPane = function()
10 {
11 WebInspector.AccessibilitySubPane.call(this, WebInspector.UIString("ARIA Att ributes"));
12
13 this._noPropertiesInfo = this.createInfo(WebInspector.UIString("No ARIA attr ibutes"));
14 this._treeOutline = this.createTreeOutline();
15 };
16
17
18 WebInspector.ARIAAttributesPane.prototype = {
19 /**
20 * @override
21 * @param {?WebInspector.DOMNode} node
22 */
23 setNode: function(node)
24 {
25 WebInspector.AccessibilitySubPane.prototype.setNode.call(this, node);
26 this._treeOutline.removeChildren();
27 if (!this.node())
28 return;
29 var target = this.node().target();
30 var attributes = node.attributes();
31 for (var i = 0; i < attributes.length; ++i) {
32 var attribute = attributes[i];
33 if (WebInspector.ARIAAttributesPane._attributes.indexOf(attribute.na me) < 0)
34 continue;
35 this._treeOutline.appendChild(new WebInspector.ARIAAttributesTreeEle ment(this, attribute, target));
36 }
37
38 var foundAttributes = (this._treeOutline.rootElement().childCount() !== 0);
39 this._noPropertiesInfo.classList.toggle("hidden", foundAttributes);
40 this._treeOutline.element.classList.toggle("hidden", !foundAttributes);
41 this._gotNodeForTest();
42 },
43
44 _gotNodeForTest: function() {
dgozman 2016/07/25 17:39:38 style: { on next line.
aboxhall 2016/07/25 19:49:19 Done.
45 // For sniffing in tests.
46 },
47
48 __proto__: WebInspector.AccessibilitySubPane.prototype
49 };
50
51
52 /**
53 * @constructor
54 * @extends {WebInspector.AXNodePropertyTreeElement}
55 * @param {!WebInspector.ARIAAttributesPane} parentPane
56 * @param {!WebInspector.DOMNode.Attribute} attribute
57 * @param {!WebInspector.Target} target
58 */
59 WebInspector.ARIAAttributesTreeElement = function(parentPane, attribute, target)
60 {
61 WebInspector.AXNodePropertyTreeElement.call(this, target);
62
63 this._parentPane = parentPane;
64 this._attribute = attribute;
65
66 this.selectable = false;
67 };
68
69 WebInspector.ARIAAttributesTreeElement.prototype = {
70 /**
71 * @override
72 */
73 onattach: function()
74 {
75 this._populateListItem();
76 this.listItemElement.addEventListener("click", this._mouseClick.bind(thi s));
77 },
78
79 _populateListItem: function()
80 {
81 this.listItemElement.removeChildren();
82 this.appendNameElement(this._attribute.name);
83 this.listItemElement.createChild("span", "separator").textContent = ":\u 00A0";
84 this.appendAttributeValueElement(this._attribute.value);
85 },
86
87 /**
88 * @override
89 * @param {string} name
90 */
91 appendNameElement: function(name)
92 {
93 this._nameElement = createElement("span");
94 this._nameElement.textContent = name;
95 this._nameElement.classList.add("ax-name");
96 this._nameElement.classList.add("monospace");
97 this.listItemElement.appendChild(this._nameElement);
98 },
99
100 /**
101 * @param {string} value
102 */
103 appendAttributeValueElement: function(value)
104 {
105 this._valueElement = WebInspector.ARIAAttributesTreeElement.createARIAVa lueElement(value);
106 this.listItemElement.appendChild(this._valueElement);
107 },
108
109 /**
110 * @param {!Event} event
111 */
112 _mouseClick: function(event)
113 {
114 event.consume(true);
dgozman 2016/07/25 17:39:38 Let's only consume after next if.
aboxhall 2016/07/25 19:49:19 Done.
115
116 if (event.target === this.listItemElement)
117 return;
118
119 this._startEditing();
120 },
121
122 _startEditing: function()
123 {
124 var valueElement = this._valueElement;
125
126 if (WebInspector.isBeingEdited(valueElement))
127 return;
128
129 var previousContent = valueElement.textContent;
130
131 /**
132 * @param {string} previousContent
133 * @param {!Event} event
134 * @this {WebInspector.ARIAAttributesTreeElement}
135 */
136 function blurListener(previousContent, event)
137 {
138 var text = event.target.textContent;
139 this._editingCommitted(text, previousContent);
140 }
141
142 this._prompt = new WebInspector.ARIAAttributesPane.ARIAAttributePrompt(t his);
143 this._prompt.setAutocompletionTimeout(0);
144 var proxyElement = this._prompt.attachAndStartEditing(valueElement, blur Listener.bind(this, previousContent));
145
146 proxyElement.addEventListener("keydown", this._editingValueKeyDown.bind( this, previousContent), false);
147
148 valueElement.getComponentSelection().setBaseAndExtent(valueElement, 0, v alueElement, 1);
149 },
150
151 _removePrompt: function()
152 {
153 if (!this._prompt)
154 return;
155 this._prompt.detach();
156 delete this._prompt;
157 },
158
159 /**
160 * @param {string} userInput
161 * @param {string} previousContent
162 */
163 _editingCommitted: function(userInput, previousContent)
164 {
165 this._removePrompt();
166
167 // Make the changes to the attribute
168 if (userInput !== previousContent)
169 this._parentPane.node().setAttributeValue(this._attribute.name, user Input);
170 },
171
172 _editingCancelled: function()
173 {
174 this._removePrompt();
175 this._populateListItem();
176 },
177
178 /**
179 * @param {string} previousContent
180 * @param {!Event} event
181 */
182 _editingValueKeyDown: function(previousContent, event)
183 {
184 if (event.handled)
185 return;
186
187 if (isEnterKey(event)) {
188 this._editingCommitted(event.target.textContent, previousContent);
189 event.consume();
190 return;
191 }
192
193 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || eve nt.keyIdentifier === "U+001B") {
194 this._editingCancelled();
195 event.consume();
196 return;
197 }
198 },
199
200 __proto__: WebInspector.AXNodePropertyTreeElement.prototype
201 };
202
203 /**
204 * @param {string} value
205 * @return {!Element}
206 */
207 WebInspector.ARIAAttributesTreeElement.createARIAValueElement = function(value)
208 {
209 var valueElement = createElementWithClass("span", "monospace");
210 // TODO(aboxhall): quotation marks?
211 valueElement.setTextContentTruncatedIfNeeded(value || "");
212 return valueElement;
213 };
214
215 /**
216 * @constructor
217 * TODO: completions; see StylesSidebarPane.js
218 * @extends {WebInspector.TextPrompt}
219 * @param {!WebInspector.ARIAAttributesTreeElement} treeElement
220 */
221 WebInspector.ARIAAttributesPane.ARIAAttributePrompt = function(treeElement)
222 {
223 WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this) );
224
225 this._treeElement = treeElement;
226 };
227
228 WebInspector.ARIAAttributesPane.ARIAAttributePrompt.prototype = {
229 /**
230 * @param {!Element} proxyElement
231 * @param {string} text
232 * @param {number} cursorOffset
233 * @param {!Range} wordRange
234 * @param {boolean} force
235 * @param {function(!Array.<string>, number=)} completionsReadyCallback
236 */
237 _buildPropertyCompletions: function(proxyElement, text, cursorOffset, wordRa nge, force, completionsReadyCallback)
238 {
239 // TODO(aboxhall): replace placeholder implementation with real implemen tation
240 completionsReadyCallback([], 0);
241 },
242
243 __proto__: WebInspector.TextPrompt.prototype
244 }
245
246
247 WebInspector.ARIAAttributesPane._attributes = [
248 "role",
249 "aria-busy",
250 "aria-checked",
251 "aria-disabled",
252 "aria-expanded",
253 "aria-grabbed",
254 "aria-hidden",
255 "aria-invalid",
256 "aria-pressed",
257 "aria-selected",
258 "aria-activedescendant",
259 "aria-atomic",
260 "aria-autocomplete",
261 "aria-controls",
262 "aria-describedby",
263 "aria-dropeffect",
264 "aria-flowto",
265 "aria-haspopup",
266 "aria-label",
267 "aria-labelledby",
268 "aria-level",
269 "aria-live",
270 "aria-multiline",
271 "aria-multiselectable",
272 "aria-orientation",
273 "aria-owns",
274 "aria-posinset",
275 "aria-readonly",
276 "aria-relevant",
277 "aria-required",
278 "aria-setsize",
279 "aria-sort",
280 "aria-valuemax",
281 "aria-valuemin",
282 "aria-valuenow",
283 "aria-valuetext",
284 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698