Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js b/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js |
| index b978985e5b62c0e57b2ff154af487fa204c272c0..d3447f37a7af422cd6967098bd4300256c2c2753 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js |
| @@ -2,6 +2,126 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +/** |
| + * @constructor |
| + * @extends {WebInspector.SDKObject} |
| + * @param {!WebInspector.AccessibilityModel} accessibilityModel |
| + * @param {!AccessibilityAgent.AXNode} payload |
| + */ |
| +WebInspector.AccessibilityNode = function(accessibilityModel, payload) |
| +{ |
| + WebInspector.SDKObject.call(this, accessibilityModel.target()); |
| + this._accessibilityModel = accessibilityModel; |
| + this._agent = accessibilityModel._agent; |
| + |
| + this._id = payload.nodeId; |
| + accessibilityModel.setAXNodeForAXId(this._id, this); |
| + |
| + this._ignored = payload.ignored; |
| + if (this._ignored && "ignoredReasons" in payload) |
| + this._ignoredReasons = payload.ignoredReasons; |
| + |
| + if ("role" in payload) |
| + this._role = payload.role; |
|
dgozman
2016/10/19 21:41:29
I'd instead do
this._role = payload.role || null;
aboxhall
2016/10/19 22:46:22
Done.
|
| + if ("name" in payload) |
| + this._name = payload.name; |
| + if ("description" in payload) |
| + this._description = payload.description; |
| + if ("value" in payload) |
| + this._value = payload.value; |
| + if ("properties" in payload) |
| + this._properties = payload.properties; |
| + if ("parentId" in payload) |
| + this._parentId = payload.parentId; |
| + if ("childIds" in payload) |
| + this._childIds = payload.childIds; |
| + if ("domNodeId" in payload) |
| + this._domNodeId = payload.domNodeId; |
| +}; |
| + |
| +WebInspector.AccessibilityNode.prototype = { |
| + /** |
| + * @return {boolean} |
| + */ |
| + ignored: function() |
| + { |
| + return this._ignored; |
| + }, |
| + |
| + /** |
| + * @return {?Array<!AccessibilityAgent.AXProperty>} |
| + */ |
| + ignoredReasons: function() |
| + { |
| + return this._ignoredReasons || null; |
| + }, |
| + |
| + /** |
| + * @return {?AccessibilityAgent.AXValue} |
| + */ |
| + role: function() |
| + { |
| + return this._role || null; |
| + }, |
| + |
| + /** |
| + * @return {!Array<!AccessibilityAgent.AXProperty>} |
| + */ |
| + coreProperties: function() |
| + { |
| + var properties = []; |
| + for (var propertyName of ["name", "description", "value"]) { |
| + if (!("_" + propertyName in this)) |
|
dgozman
2016/10/19 21:41:29
Don't do this. Access properties explicitly:
if (
aboxhall
2016/10/19 22:46:22
Done.
|
| + continue; |
| + properties.push(/** @type {!AccessibilityAgent.AXProperty} */ ({name: propertyName, value: this["_" + propertyName]})); |
| + } |
| + return properties; |
| + }, |
| + |
| + /** |
| + * @return {?AccessibilityAgent.AXValue} |
| + */ |
| + name: function() |
| + { |
| + return this._name || null; |
| + }, |
| + |
| + /** |
| + * @return {?AccessibilityAgent.AXValue} |
| + */ |
| + description: function() |
| + { |
| + return this._description || null; |
| + }, |
| + |
| + /** |
| + * @return {?AccessibilityAgent.AXValue} |
| + */ |
| + value: function() |
| + { |
| + return this._value || null; |
| + }, |
| + |
| + /** |
| + * @return {?Array<!AccessibilityAgent.AXProperty>} |
|
dgozman
2016/10/19 21:41:28
Are you going to convert AXProperty to WebInspecto
aboxhall
2016/10/19 22:46:22
Hm, should probably do that at some point, yeah.
|
| + */ |
| + properties: function() |
| + { |
| + return this._properties || null; |
| + }, |
| + |
| + /** |
| + * @return {?WebInspector.AccessibilityNode} |
| + */ |
| + parentNode: function() |
| + { |
| + if (!this._parentId) |
| + return null; |
| + return this._accessibilityModel.axNodeForId(this._parentId); |
| + }, |
| + |
| + __proto__: WebInspector.SDKObject.prototype |
| +}; |
| /** |
| * @constructor |
| @@ -12,31 +132,66 @@ WebInspector.AccessibilityModel = function(target) |
| { |
| WebInspector.SDKModel.call(this, WebInspector.AccessibilityModel, target); |
| this._agent = target.accessibilityAgent(); |
| + |
| + /** @type {!Map<string, !WebInspector.AccessibilityNode>} */ |
| + this._axIdToAXNode = new Map(); |
| }; |
| WebInspector.AccessibilityModel.prototype = { |
| + |
| + /** |
| + * @param {string} axId |
| + * @return {?WebInspector.AccessibilityNode} |
| + */ |
| + axNodeForId: function(axId) |
| + { |
| + return this._axIdToAXNode.get(axId); |
| + }, |
| + |
| + /** |
| + * @param {string} axId |
| + * @param {!WebInspector.AccessibilityNode} axNode |
| + */ |
| + setAXNodeForAXId: function(axId, axNode) |
|
dgozman
2016/10/19 21:41:28
You can make this _setAXNodeForAXId, it can be cal
aboxhall
2016/10/19 22:46:22
Done.
|
| + { |
| + this._axIdToAXNode.set(axId, axNode); |
| + }, |
| + |
| /** |
| - * @param {!DOMAgent.NodeId} nodeId |
| - * @return {!Promise.<?Array<!AccessibilityAgent.AXNode>>} |
| + * @param {!WebInspector.DOMNode} node |
| + * @return {!Promise<?Array<!WebInspector.AccessibilityNode>>} |
| */ |
| - getAXNodeChain: function(nodeId) |
| + getAXNodeChain: function(node) |
| { |
| + this._axIdToAXNode.clear(); |
| + |
| /** |
| + * @this {WebInspector.AccessibilityModel} |
| * @param {?string} error |
| - * @param {!Array<!AccessibilityAgent.AXNode>=} nodes |
| - * @return {?Array<!AccessibilityAgent.AXNode>} |
| + * @param {!Array<!AccessibilityAgent.AXNode>=} payloads |
| + * @return {?Array<!WebInspector.AccessibilityNode>} |
| */ |
| - function parsePayload(error, nodes) |
| + function parsePayload(error, payloads) |
| { |
| - if (error) |
| + if (error) { |
| console.error("AccessibilityAgent.getAXNodeChain(): " + error); |
| - return nodes || null; |
| + return null; |
| + } |
| + |
| + if (!payloads) |
| + return null; |
| + |
| + var nodes = []; |
| + for (var payload of payloads) |
| + nodes.push(new WebInspector.AccessibilityNode(this, payload)); |
| + |
| + return nodes; |
| } |
| - return this._agent.getAXNodeChain(nodeId, true, parsePayload); |
| + return this._agent.getAXNodeChain(node.id, true, parsePayload.bind(this)); |
| }, |
| __proto__: WebInspector.SDKModel.prototype |
| -} |
| +}; |
| WebInspector.AccessibilityModel._symbol = Symbol("AccessibilityModel"); |
| /** |