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

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: Rebase and fix test 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()
45 {
46 // For sniffing in tests.
47 },
48
49 __proto__: WebInspector.AccessibilitySubPane.prototype
50 };
51
52
53 /**
54 * @constructor
55 * @extends {WebInspector.AXNodePropertyTreeElement}
56 * @param {!WebInspector.ARIAAttributesPane} parentPane
57 * @param {!WebInspector.DOMNode.Attribute} attribute
58 * @param {!WebInspector.Target} target
59 */
60 WebInspector.ARIAAttributesTreeElement = function(parentPane, attribute, target)
61 {
62 WebInspector.AXNodePropertyTreeElement.call(this, target);
63
64 this._parentPane = parentPane;
65 this._attribute = attribute;
66
67 this.selectable = false;
68 };
69
70 WebInspector.ARIAAttributesTreeElement.prototype = {
71 /**
72 * @override
73 */
74 onattach: function()
75 {
76 this._populateListItem();
77 this.listItemElement.addEventListener("click", this._mouseClick.bind(thi s));
78 },
79
80 _populateListItem: function()
81 {
82 this.listItemElement.removeChildren();
83 this.appendNameElement(this._attribute.name);
84 this.listItemElement.createChild("span", "separator").textContent = ":\u 00A0";
85 this.appendAttributeValueElement(this._attribute.value);
86 },
87
88 /**
89 * @override
90 * @param {string} name
91 */
92 appendNameElement: function(name)
93 {
94 this._nameElement = createElement("span");
95 this._nameElement.textContent = name;
96 this._nameElement.classList.add("ax-name");
97 this._nameElement.classList.add("monospace");
98 this.listItemElement.appendChild(this._nameElement);
99 },
100
101 /**
102 * @param {string} value
103 */
104 appendAttributeValueElement: function(value)
105 {
106 this._valueElement = WebInspector.ARIAAttributesTreeElement.createARIAVa lueElement(value);
107 this.listItemElement.appendChild(this._valueElement);
108 },
109
110 /**
111 * @param {!Event} event
112 */
113 _mouseClick: function(event)
114 {
115 if (event.target === this.listItemElement)
116 return;
117
118 event.consume(true);
119
120 this._startEditing();
121 },
122
123 _startEditing: function()
124 {
125 var valueElement = this._valueElement;
126
127 if (WebInspector.isBeingEdited(valueElement))
128 return;
129
130 var previousContent = valueElement.textContent;
131
132 /**
133 * @param {string} previousContent
134 * @param {!Event} event
135 * @this {WebInspector.ARIAAttributesTreeElement}
136 */
137 function blurListener(previousContent, event)
138 {
139 var text = event.target.textContent;
140 this._editingCommitted(text, previousContent);
141 }
142
143 this._prompt = new WebInspector.ARIAAttributesPane.ARIAAttributePrompt(t his);
144 this._prompt.setAutocompletionTimeout(0);
145 var proxyElement = this._prompt.attachAndStartEditing(valueElement, blur Listener.bind(this, previousContent));
146
147 proxyElement.addEventListener("keydown", this._editingValueKeyDown.bind( this, previousContent), false);
148
149 valueElement.getComponentSelection().setBaseAndExtent(valueElement, 0, v alueElement, 1);
150 },
151
152 _removePrompt: function()
153 {
154 if (!this._prompt)
155 return;
156 this._prompt.detach();
157 delete this._prompt;
158 },
159
160 /**
161 * @param {string} userInput
162 * @param {string} previousContent
163 */
164 _editingCommitted: function(userInput, previousContent)
165 {
166 this._removePrompt();
167
168 // Make the changes to the attribute
169 if (userInput !== previousContent)
170 this._parentPane.node().setAttributeValue(this._attribute.name, user Input);
171 },
172
173 _editingCancelled: function()
174 {
175 this._removePrompt();
176 this._populateListItem();
177 },
178
179 /**
180 * @param {string} previousContent
181 * @param {!Event} event
182 */
183 _editingValueKeyDown: function(previousContent, event)
184 {
185 if (event.handled)
186 return;
187
188 if (isEnterKey(event)) {
189 this._editingCommitted(event.target.textContent, previousContent);
190 event.consume();
191 return;
192 }
193
194 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || eve nt.keyIdentifier === "U+001B") {
195 this._editingCancelled();
196 event.consume();
197 return;
198 }
199 },
200
201 __proto__: WebInspector.AXNodePropertyTreeElement.prototype
202 };
203
204 /**
205 * @param {string} value
206 * @return {!Element}
207 */
208 WebInspector.ARIAAttributesTreeElement.createARIAValueElement = function(value)
209 {
210 var valueElement = createElementWithClass("span", "monospace");
211 // TODO(aboxhall): quotation marks?
212 valueElement.setTextContentTruncatedIfNeeded(value || "");
213 return valueElement;
214 };
215
216 /**
217 * @constructor
218 * TODO: completions; see StylesSidebarPane.js
219 * @extends {WebInspector.TextPrompt}
220 * @param {!WebInspector.ARIAAttributesTreeElement} treeElement
221 */
222 WebInspector.ARIAAttributesPane.ARIAAttributePrompt = function(treeElement)
223 {
224 WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this) );
225
226 this._treeElement = treeElement;
227 };
228
229 WebInspector.ARIAAttributesPane.ARIAAttributePrompt.prototype = {
230 /**
231 * @param {!Element} proxyElement
232 * @param {string} text
233 * @param {number} cursorOffset
234 * @param {!Range} wordRange
235 * @param {boolean} force
236 * @param {function(!Array.<string>, number=)} completionsReadyCallback
237 */
238 _buildPropertyCompletions: function(proxyElement, text, cursorOffset, wordRa nge, force, completionsReadyCallback)
239 {
240 // TODO(aboxhall): replace placeholder implementation with real implemen tation
241 completionsReadyCallback([], 0);
242 },
243
244 __proto__: WebInspector.TextPrompt.prototype
245 }
246
247
248 WebInspector.ARIAAttributesPane._attributes = [
249 "role",
250 "aria-busy",
251 "aria-checked",
252 "aria-disabled",
253 "aria-expanded",
254 "aria-grabbed",
255 "aria-hidden",
256 "aria-invalid",
257 "aria-pressed",
258 "aria-selected",
259 "aria-activedescendant",
260 "aria-atomic",
261 "aria-autocomplete",
262 "aria-controls",
263 "aria-describedby",
264 "aria-dropeffect",
265 "aria-flowto",
266 "aria-haspopup",
267 "aria-label",
268 "aria-labelledby",
269 "aria-level",
270 "aria-live",
271 "aria-multiline",
272 "aria-multiselectable",
273 "aria-orientation",
274 "aria-owns",
275 "aria-posinset",
276 "aria-readonly",
277 "aria-relevant",
278 "aria-required",
279 "aria-setsize",
280 "aria-sort",
281 "aria-valuemax",
282 "aria-valuemin",
283 "aria-valuenow",
284 "aria-valuetext",
285 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698