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

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: Preliminary cleanup Created 4 years, 5 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.AXARIAAttributesSubPane = function()
dgozman 2016/07/18 22:38:19 ARIAAttributesPane
aboxhall 2016/07/19 17:20:54 Done.
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.AXARIAAttributesSubPane.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 foundARIAAttr = false;
dgozman 2016/07/18 22:38:19 Avoid abbreviations: attr -> attribute. I'd call t
aboxhall 2016/07/19 17:20:54 Done.
31 var attributes = node.attributes();
32 for (var i = 0; i < attributes.length; ++i) {
33 var attribute = attributes[i];
34 if (WebInspector.AXARIAAttributesSubPane.ARIAAttributes.indexOf(attr ibute.name) < 0)
35 continue;
36 this._treeOutline.appendChild(new WebInspector.ARIAAttributesTreeEle ment(this, attribute, target));
37 foundARIAAttr = true;
38 }
39
40 if (foundARIAAttr) {
dgozman 2016/07/18 22:38:20 Can just check |this._treeOutline.rootElement().ch
aboxhall 2016/07/19 17:20:53 Done.
41 this._noPropertiesInfo.classList.add("hidden");
42 this._treeOutline.element.classList.remove("hidden");
43 } else {
44 this._noPropertiesInfo.classList.remove("hidden");
45 this._treeOutline.element.classList.add("hidden");
dgozman 2016/07/18 22:38:19 Use toggle instead: this._treeOutline.element.clas
aboxhall 2016/07/19 17:20:54 Nice, TIL. Done.
46 }
47 },
48
49 __proto__: WebInspector.AccessibilitySubPane.prototype
50 };
51
52 /**
53 * @constructor
54 * @extends {WebInspector.AXNodePropertyTreeElement}
55 * @param {!WebInspector.AXARIAAttributesSubPane} parentPane
56 * @param {!Object} attribute
dgozman 2016/07/18 22:38:19 Let's make it a typedef. I've found that DOMNode.a
aboxhall 2016/07/19 17:20:53 Done.
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
67 WebInspector.ARIAAttributesTreeElement.prototype = {
68 /**
69 * @override
70 */
71 onattach: function()
72 {
73 this._populateListItem();
74 this.listItemElement.addEventListener("click", this._mouseClick.bind(thi s));
75 },
76
77 _populateListItem: function() {
dgozman 2016/07/18 22:38:20 { on next line
aboxhall 2016/07/19 17:20:54 Done.
78 this.listItemElement.removeChildren();
79 this.appendNameElement(this._attribute.name);
80 this.listItemElement.createChild("span", "separator").textContent = ":\u 00A0";
81 this.appendAttributeValueElement(this._attribute.value);
82 },
83
84 /**
85 * @override
86 * @param {string} name
87 */
88 appendNameElement: function(name)
89 {
90 this.nameElement = createElement("span");
dgozman 2016/07/18 22:38:20 _nameElement
aboxhall 2016/07/19 17:20:54 Done.
91 this.nameElement.textContent = name;
92 this.nameElement.classList.add("ax-name");
93 this.nameElement.classList.add("monospace");
94 this.listItemElement.appendChild(this.nameElement);
95 },
96
97 /**
98 * @param {string} value
99 * @return {?Element}
dgozman 2016/07/18 22:38:19 - !Element - Is it used at all? Let's not return a
aboxhall 2016/07/19 17:20:54 Done.
100 */
101 appendAttributeValueElement: function(value)
102 {
103 this.valueElement = WebInspector.ARIAAttributesTreeElement.createARIAVal ueElement(value);
dgozman 2016/07/18 22:38:19 _valueElement
aboxhall 2016/07/19 17:20:53 Done.
104 this.listItemElement.appendChild(this.valueElement);
105 return this.valueElement;
106 },
107
108 _mouseClick: function(event)
dgozman 2016/07/18 22:38:20 Annotate please.
aboxhall 2016/07/19 17:20:54 Done.
109 {
110 event.consume(true);
111
112 if (event.target === this.listItemElement)
113 return;
114
115 this.startEditing();
116 },
117
118 startEditing: function()
dgozman 2016/07/18 22:38:19 All these editing methods should be private.
aboxhall 2016/07/19 17:20:54 Done.
119 {
120 var valueElement = this.valueElement;
121
122 if (WebInspector.isBeingEdited(valueElement))
123 return;
124
125 var previousContent = valueElement.textContent;
126
127 if (valueElement.parentElement)
128 valueElement.parentElement.classList.add("child-editing");
129
130 /**
131 * @param {string} previousContent
132 * @param {!Event} event
133 * @this {WebInspector.ARIAAttributesTreeElement}
134 */
135 function blurListener(previousContent, event)
136 {
137 var text = event.target.textContent;
138 text = this.value || text;
dgozman 2016/07/18 22:38:20 What is |this.value| ?
aboxhall 2016/07/19 17:20:54 Ugh, should have been this._attribute.value, but I
139 this.editingCommitted(text, previousContent);
140 }
141
142 this._prompt = new WebInspector.AXARIAAttributesSubPane.ARIAAttributePro mpt(this);
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
dgozman 2016/07/18 22:38:19 nit: extra blank line
aboxhall 2016/07/19 17:20:53 Done.
159
160 /**
161 * @param {string} userInput
162 * @param {string} previousContent
163 */
164 editingCommitted: function(userInput, previousContent)
165 {
166 this._removePrompt();
167 this.editingEnded();
168
169 // Make the changes to the attribute
170 if (userInput !== previousContent) {
171 var newText = this._attribute.name + '="' + userInput + '"';
172 this._parentPane.node().setAttribute(this._attribute.name, newText);
dgozman 2016/07/18 22:38:19 Let's use setAttributeValue to not craft html here
aboxhall 2016/07/19 17:20:54 Done.
173 }
174 },
175
176 editingEnded: function()
177 {
178 var editedElement = this.valueElement;
179 // The proxyElement has been deleted, no need to remove listener.
180 if (editedElement.parentElement)
181 editedElement.parentElement.classList.remove("child-editing");
dgozman 2016/07/18 22:38:20 Is "child-editing" used anywhere?
aboxhall 2016/07/19 17:20:54 Hm, doesn't look like it.
182 },
183
184 editingCancelled: function()
185 {
186 this._removePrompt();
187 this._populateListItem();
188 this.editingEnded();
189 },
190
191 /**
192 * @param {string} previousContent
193 * @param {!Event} event
194 */
195 _editingValueKeyDown: function(previousContent, event)
196 {
197 if (event.handled)
198 return;
199
200 var result;
201
202 if (isEnterKey(event)) {
203 result = "commit";
204 event.preventDefault();
205 } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || event.keyIdentifier === "U+001B") {
206 result = "cancel";
207 }
208
209 if (result) {
210 switch (result) {
211 case "cancel":
212 this.editingCancelled();
dgozman 2016/07/18 22:38:19 Just call this instead of |result = "commit"|.
aboxhall 2016/07/19 17:20:54 Done.
213 break;
214 case "commit":
215 this.editingCommitted(event.target.textContent, result);
dgozman 2016/07/18 22:38:19 Same for cancel.
aboxhall 2016/07/19 17:20:54 Done.
216 break;
217 }
218
219 event.consume();
dgozman 2016/07/18 22:38:20 And consume in both cases. Note: consume(true) wil
aboxhall 2016/07/19 17:20:53 Done.
220 return;
221 }
222 },
223
224 __proto__: WebInspector.AXNodePropertyTreeElement.prototype
225 };
226
227 /**
228 * @param {string} value
229 * @return {!Element}
230 */
231 WebInspector.ARIAAttributesTreeElement.createARIAValueElement = function(value)
232 {
233 var valueElement = createElementWithClass("span", "monospace");
234 // TODO(aboxhall): quotation marks?
235 valueElement.setTextContentTruncatedIfNeeded(value || "");
236 return valueElement;
237 };
238
239 /**
240 * @constructor
241 * TODO: completions; see StylesSidebarPane.js
242 * @extends {WebInspector.TextPrompt}
243 * @param {!WebInspector.ARIAAttributesTreeElement} treeElement
244 */
245 WebInspector.AXARIAAttributesSubPane.ARIAAttributePrompt = function(treeElement)
246 {
247 WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this) );
248
249 this._treeElement = treeElement;
250 };
251
252 WebInspector.AXARIAAttributesSubPane.ARIAAttributePrompt.prototype = {
253 /**
254 * @param {!Element} proxyElement
255 * @param {string} text
256 * @param {number} cursorOffset
257 * @param {!Range} wordRange
258 * @param {boolean} force
259 * @param {function(!Array.<string>, number=)} completionsReadyCallback
260 */
261 _buildPropertyCompletions: function(proxyElement, text, cursorOffset, wordRa nge, force, completionsReadyCallback)
262 {
263 // TODO(aboxhall): replace placeholder implementation with real implemen tation
264
265 var prefix = wordRange.toString().toLowerCase();
dgozman 2016/07/18 22:38:20 Let's remove this code for now, until we have an i
aboxhall 2016/07/19 17:20:54 Done.
266 if (!prefix && !force && (proxyElement.textContent.length)) {
267 completionsReadyCallback([]);
268 return;
269 }
270
271 var results = [];
272 completionsReadyCallback(results, 0);
273 },
274
275 __proto__: WebInspector.TextPrompt.prototype
276 }
277
278
279 WebInspector.AXARIAAttributesSubPane.ARIAAttributes = [
dgozman 2016/07/18 22:38:20 WebInspector.ARIAAttributesPane._attributes
aboxhall 2016/07/19 17:20:54 Done.
280 "role",
281 "aria-busy",
282 "aria-checked",
283 "aria-disabled",
284 "aria-expanded",
285 "aria-grabbed",
286 "aria-hidden",
287 "aria-invalid",
288 "aria-pressed",
289 "aria-selected",
290 "aria-activedescendant",
291 "aria-atomic",
292 "aria-autocomplete",
293 "aria-controls",
294 "aria-describedby",
295 "aria-dropeffect",
296 "aria-flowto",
297 "aria-haspopup",
298 "aria-label",
299 "aria-labelledby",
300 "aria-level",
301 "aria-live",
302 "aria-multiline",
303 "aria-multiselectable",
304 "aria-orientation",
305 "aria-owns",
306 "aria-posinset",
307 "aria-readonly",
308 "aria-relevant",
309 "aria-required",
310 "aria-setsize",
311 "aria-sort",
312 "aria-valuemax",
313 "aria-valuemin",
314 "aria-valuenow",
315 "aria-valuetext",
316 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698