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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.AccessibilityNode = class extends WebInspector.SDKObject { 7 Accessibility.AccessibilityNode = class extends SDK.SDKObject {
8 /** 8 /**
9 * @param {!WebInspector.AccessibilityModel} accessibilityModel 9 * @param {!Accessibility.AccessibilityModel} accessibilityModel
10 * @param {!Protocol.Accessibility.AXNode} payload 10 * @param {!Protocol.Accessibility.AXNode} payload
11 */ 11 */
12 constructor(accessibilityModel, payload) { 12 constructor(accessibilityModel, payload) {
13 super(accessibilityModel.target()); 13 super(accessibilityModel.target());
14 this._accessibilityModel = accessibilityModel; 14 this._accessibilityModel = accessibilityModel;
15 this._agent = accessibilityModel._agent; 15 this._agent = accessibilityModel._agent;
16 16
17 this._id = payload.nodeId; 17 this._id = payload.nodeId;
18 accessibilityModel._setAXNodeForAXId(this._id, this); 18 accessibilityModel._setAXNodeForAXId(this._id, this);
19 if (payload.backendDOMNodeId) { 19 if (payload.backendDOMNodeId) {
20 accessibilityModel._setAXNodeForBackendDOMNodeId(payload.backendDOMNodeId, this); 20 accessibilityModel._setAXNodeForBackendDOMNodeId(payload.backendDOMNodeId, this);
21 this._backendDOMNodeId = payload.backendDOMNodeId; 21 this._backendDOMNodeId = payload.backendDOMNodeId;
22 this._deferredDOMNode = 22 this._deferredDOMNode =
23 new WebInspector.DeferredDOMNode(this.target(), 23 new SDK.DeferredDOMNode(this.target(),
24 payload.backendDOMNodeId); 24 payload.backendDOMNodeId);
25 } else { 25 } else {
26 this._backendDOMNodeId = null; 26 this._backendDOMNodeId = null;
27 this._deferredDOMNode = null; 27 this._deferredDOMNode = null;
28 } 28 }
29 this._ignored = payload.ignored; 29 this._ignored = payload.ignored;
30 if (this._ignored && 'ignoredReasons' in payload) 30 if (this._ignored && 'ignoredReasons' in payload)
31 this._ignoredReasons = payload.ignoredReasons; 31 this._ignoredReasons = payload.ignoredReasons;
32 32
33 this._role = payload.role || null; 33 this._role = payload.role || null;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 /** 100 /**
101 * @return {?Array<!Protocol.Accessibility.AXProperty>} 101 * @return {?Array<!Protocol.Accessibility.AXProperty>}
102 */ 102 */
103 properties() { 103 properties() {
104 return this._properties || null; 104 return this._properties || null;
105 } 105 }
106 106
107 /** 107 /**
108 * @return {?WebInspector.AccessibilityNode} 108 * @return {?Accessibility.AccessibilityNode}
109 */ 109 */
110 parentNode() { 110 parentNode() {
111 return this._parentNode; 111 return this._parentNode;
112 } 112 }
113 113
114 /** 114 /**
115 * @param {?WebInspector.AccessibilityNode} parentNode 115 * @param {?Accessibility.AccessibilityNode} parentNode
116 */ 116 */
117 _setParentNode(parentNode) { 117 _setParentNode(parentNode) {
118 this._parentNode = parentNode; 118 this._parentNode = parentNode;
119 } 119 }
120 120
121 /** 121 /**
122 * @return {boolean} 122 * @return {boolean}
123 */ 123 */
124 isDOMNode() { 124 isDOMNode() {
125 return !!this._backendDOMNodeId; 125 return !!this._backendDOMNodeId;
126 } 126 }
127 127
128 /** 128 /**
129 * @return {?number} 129 * @return {?number}
130 */ 130 */
131 backendDOMNodeId() { 131 backendDOMNodeId() {
132 return this._backendDOMNodeId; 132 return this._backendDOMNodeId;
133 } 133 }
134 134
135 /** 135 /**
136 * @return {?WebInspector.DeferredDOMNode} 136 * @return {?SDK.DeferredDOMNode}
137 */ 137 */
138 deferredDOMNode() { 138 deferredDOMNode() {
139 return this._deferredDOMNode; 139 return this._deferredDOMNode;
140 } 140 }
141 141
142 /** 142 /**
143 * @return {!Array<!WebInspector.AccessibilityNode>} 143 * @return {!Array<!Accessibility.AccessibilityNode>}
144 */ 144 */
145 children() { 145 children() {
146 var children = []; 146 var children = [];
147 if (!this._childIds) 147 if (!this._childIds)
148 return children; 148 return children;
149 149
150 for (var childId of this._childIds) { 150 for (var childId of this._childIds) {
151 var child = this._accessibilityModel.axNodeForId(childId); 151 var child = this._accessibilityModel.axNodeForId(childId);
152 if (child) 152 if (child)
153 children.push(child); 153 children.push(child);
(...skipping 16 matching lines...) Expand all
170 */ 170 */
171 hasOnlyUnloadedChildren() { 171 hasOnlyUnloadedChildren() {
172 if (!this._childIds || !this._childIds.length) 172 if (!this._childIds || !this._childIds.length)
173 return false; 173 return false;
174 174
175 return !this._childIds.some((id) => this._accessibilityModel.axNodeForId(id) !== undefined); 175 return !this._childIds.some((id) => this._accessibilityModel.axNodeForId(id) !== undefined);
176 } 176 }
177 177
178 /** 178 /**
179 * TODO(aboxhall): Remove once protocol is stable. 179 * TODO(aboxhall): Remove once protocol is stable.
180 * @param {!WebInspector.AccessibilityNode} inspectedNode 180 * @param {!Accessibility.AccessibilityNode} inspectedNode
181 * @param {string=} leadingSpace 181 * @param {string=} leadingSpace
182 * @return {string} 182 * @return {string}
183 */ 183 */
184 printSelfAndChildren(inspectedNode, leadingSpace) { 184 printSelfAndChildren(inspectedNode, leadingSpace) {
185 var string = leadingSpace || ''; 185 var string = leadingSpace || '';
186 if (this._role) 186 if (this._role)
187 string += this._role.value; 187 string += this._role.value;
188 else 188 else
189 string += '<no role>'; 189 string += '<no role>';
190 string += (this._name ? ' ' + this._name.value : ''); 190 string += (this._name ? ' ' + this._name.value : '');
191 string += ' ' + this._id; 191 string += ' ' + this._id;
192 if (this._domNode) 192 if (this._domNode)
193 string += ' (' + this._domNode.nodeName() + ')'; 193 string += ' (' + this._domNode.nodeName() + ')';
194 if (this === inspectedNode) 194 if (this === inspectedNode)
195 string += ' *'; 195 string += ' *';
196 for (var child of this.children()) 196 for (var child of this.children())
197 string += '\n' + child.printSelfAndChildren(inspectedNode, (leadingSpace | | '') + ' '); 197 string += '\n' + child.printSelfAndChildren(inspectedNode, (leadingSpace | | '') + ' ');
198 return string; 198 return string;
199 } 199 }
200 }; 200 };
201 201
202 /** 202 /**
203 * @unrestricted 203 * @unrestricted
204 */ 204 */
205 WebInspector.AccessibilityModel = class extends WebInspector.SDKModel { 205 Accessibility.AccessibilityModel = class extends SDK.SDKModel {
206 /** 206 /**
207 * @param {!WebInspector.Target} target 207 * @param {!SDK.Target} target
208 */ 208 */
209 constructor(target) { 209 constructor(target) {
210 super(WebInspector.AccessibilityModel, target); 210 super(Accessibility.AccessibilityModel, target);
211 this._agent = target.accessibilityAgent(); 211 this._agent = target.accessibilityAgent();
212 212
213 /** @type {!Map<string, !WebInspector.AccessibilityNode>} */ 213 /** @type {!Map<string, !Accessibility.AccessibilityNode>} */
214 this._axIdToAXNode = new Map(); 214 this._axIdToAXNode = new Map();
215 this._backendDOMNodeIdToAXNode = new Map(); 215 this._backendDOMNodeIdToAXNode = new Map();
216 } 216 }
217 217
218 /** 218 /**
219 * @param {!WebInspector.Target} target 219 * @param {!SDK.Target} target
220 * @return {!WebInspector.AccessibilityModel} 220 * @return {!Accessibility.AccessibilityModel}
221 */ 221 */
222 static fromTarget(target) { 222 static fromTarget(target) {
223 if (!target[WebInspector.AccessibilityModel._symbol]) 223 if (!target[Accessibility.AccessibilityModel._symbol])
224 target[WebInspector.AccessibilityModel._symbol] = new WebInspector.Accessi bilityModel(target); 224 target[Accessibility.AccessibilityModel._symbol] = new Accessibility.Acces sibilityModel(target);
225 225
226 return target[WebInspector.AccessibilityModel._symbol]; 226 return target[Accessibility.AccessibilityModel._symbol];
227 } 227 }
228 228
229 clear() { 229 clear() {
230 this._axIdToAXNode.clear(); 230 this._axIdToAXNode.clear();
231 } 231 }
232 232
233 /** 233 /**
234 * @param {!WebInspector.DOMNode} node 234 * @param {!SDK.DOMNode} node
235 * @return {!Promise} 235 * @return {!Promise}
236 */ 236 */
237 requestPartialAXTree(node) { 237 requestPartialAXTree(node) {
238 /** 238 /**
239 * @this {WebInspector.AccessibilityModel} 239 * @this {Accessibility.AccessibilityModel}
240 * @param {?string} error 240 * @param {?string} error
241 * @param {!Array<!Protocol.Accessibility.AXNode>=} payloads 241 * @param {!Array<!Protocol.Accessibility.AXNode>=} payloads
242 */ 242 */
243 function parsePayload(error, payloads) { 243 function parsePayload(error, payloads) {
244 if (error) { 244 if (error) {
245 console.error('AccessibilityAgent.getAXNodeChain(): ' + error); 245 console.error('AccessibilityAgent.getAXNodeChain(): ' + error);
246 return null; 246 return null;
247 } 247 }
248 248
249 if (!payloads) 249 if (!payloads)
250 return; 250 return;
251 251
252 for (var payload of payloads) 252 for (var payload of payloads)
253 new WebInspector.AccessibilityNode(this, payload); 253 new Accessibility.AccessibilityNode(this, payload);
254 254
255 for (var axNode of this._axIdToAXNode.values()) { 255 for (var axNode of this._axIdToAXNode.values()) {
256 for (var axChild of axNode.children()) { 256 for (var axChild of axNode.children()) {
257 axChild._setParentNode(axNode); 257 axChild._setParentNode(axNode);
258 } 258 }
259 } 259 }
260 } 260 }
261 return this._agent.getPartialAXTree(node.id, true, parsePayload.bind(this)); 261 return this._agent.getPartialAXTree(node.id, true, parsePayload.bind(this));
262 } 262 }
263 263
264 /** 264 /**
265 * @param {string} axId 265 * @param {string} axId
266 * @return {?WebInspector.AccessibilityNode} 266 * @return {?Accessibility.AccessibilityNode}
267 */ 267 */
268 axNodeForId(axId) { 268 axNodeForId(axId) {
269 return this._axIdToAXNode.get(axId); 269 return this._axIdToAXNode.get(axId);
270 } 270 }
271 271
272 /** 272 /**
273 * @param {string} axId 273 * @param {string} axId
274 * @param {!WebInspector.AccessibilityNode} axNode 274 * @param {!Accessibility.AccessibilityNode} axNode
275 */ 275 */
276 _setAXNodeForAXId(axId, axNode) { 276 _setAXNodeForAXId(axId, axNode) {
277 this._axIdToAXNode.set(axId, axNode); 277 this._axIdToAXNode.set(axId, axNode);
278 } 278 }
279 279
280 /** 280 /**
281 * @param {?WebInspector.DOMNode} domNode 281 * @param {?SDK.DOMNode} domNode
282 * @return {?WebInspector.AccessibilityNode} 282 * @return {?Accessibility.AccessibilityNode}
283 */ 283 */
284 axNodeForDOMNode(domNode) { 284 axNodeForDOMNode(domNode) {
285 if (!domNode) 285 if (!domNode)
286 return null; 286 return null;
287 return this._backendDOMNodeIdToAXNode.get(domNode.backendNodeId()); 287 return this._backendDOMNodeIdToAXNode.get(domNode.backendNodeId());
288 } 288 }
289 289
290 /** 290 /**
291 * @param {number} backendDOMNodeId 291 * @param {number} backendDOMNodeId
292 * @param {!WebInspector.AccessibilityNode} axNode 292 * @param {!Accessibility.AccessibilityNode} axNode
293 */ 293 */
294 _setAXNodeForBackendDOMNodeId(backendDOMNodeId, axNode) { 294 _setAXNodeForBackendDOMNodeId(backendDOMNodeId, axNode) {
295 this._backendDOMNodeIdToAXNode.set(backendDOMNodeId, 295 this._backendDOMNodeIdToAXNode.set(backendDOMNodeId,
296 axNode); 296 axNode);
297 } 297 }
298 298
299 // TODO(aboxhall): Remove once protocol is stable. 299 // TODO(aboxhall): Remove once protocol is stable.
300 /** 300 /**
301 * @param {!WebInspector.DOMNode} inspectedNode 301 * @param {!SDK.DOMNode} inspectedNode
302 */ 302 */
303 logTree(inspectedNode) { 303 logTree(inspectedNode) {
304 var rootNode = inspectedNode; 304 var rootNode = inspectedNode;
305 while (rootNode.parentNode()) 305 while (rootNode.parentNode())
306 rootNode = rootNode.parentNode(); 306 rootNode = rootNode.parentNode();
307 console.log(rootNode.printSelfAndChildren(inspectedNode)); 307 console.log(rootNode.printSelfAndChildren(inspectedNode));
308 } 308 }
309 }; 309 };
310 310
311 WebInspector.AccessibilityModel._symbol = Symbol('AccessibilityModel'); 311 Accessibility.AccessibilityModel._symbol = Symbol('AccessibilityModel');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698