| 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..282285e44c5bbd20d77212f32a63927c0f1ec508 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,241 @@
|
| // 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;
|
| + 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))
|
| + 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>}
|
| + */
|
| + properties: function()
|
| + {
|
| + return this._properties || null;
|
| + },
|
| +
|
| + /**
|
| + * @return {?WebInspector.AccessibilityNode}
|
| + */
|
| + parentNode: function()
|
| + {
|
| + if (!this._parentId)
|
| + return null;
|
| + return this._accessibilityModel.axNodeForId(this._parentId);
|
| + },
|
| +
|
| + /**
|
| + * @return {boolean}
|
| + */
|
| + isDOMNode: function()
|
| + {
|
| + return !!this._domNodeId;
|
| + },
|
| +
|
| + /**
|
| + * @return {?WebInspector.DOMNode}
|
| + */
|
| + domNode: function()
|
| + {
|
| + return this._domNode || null;
|
| + },
|
| +
|
| + /**
|
| + * @param {?WebInspector.DOMNode} domNode
|
| + */
|
| + _setDOMNode: function(domNode)
|
| + {
|
| + this._domNode = domNode;
|
| + if (domNode)
|
| + this._accessibilityModel.setAXNodeForDOMNode(domNode, this);
|
| + },
|
| +
|
| + /**
|
| + * @return {!Promise<?WebInspector.DOMNode>}
|
| + */
|
| + resolveDOMNode: function()
|
| + {
|
| + if (this._domNode)
|
| + return Promise.resolve(this._domNode);
|
| + if (!this._domNodeId)
|
| + return Promise.resolve(/** @type {?WebInspector.DOMNode} */ (null));
|
| +
|
| + var deferredNode = new WebInspector.DeferredDOMNode(this.target(), this._domNodeId);
|
| + return deferredNode.resolvePromise()
|
| + .then((domNode) => {
|
| + this._setDOMNode(domNode);
|
| + return domNode;
|
| + });
|
| + },
|
| +
|
| + /**
|
| + * @return {?number}
|
| + */
|
| + domNodeId: function()
|
| + {
|
| + return this._domNodeId || null;
|
| + },
|
| +
|
| + /**
|
| + * @return {!Array<!WebInspector.AccessibilityNode>}
|
| + */
|
| + children: function()
|
| + {
|
| + var children = [];
|
| + if (!this._childIds)
|
| + return children;
|
| +
|
| + for (var childId of this._childIds) {
|
| + var child = this._accessibilityModel.axNodeForId(childId);
|
| + if (child)
|
| + children.push(child);
|
| + }
|
| +
|
| + return children;
|
| + },
|
| +
|
| + /**
|
| + * @return {number}
|
| + */
|
| + numChildren: function()
|
| + {
|
| + if (!this._childIds)
|
| + return 0;
|
| + return this._childIds.length;
|
| + },
|
| +
|
| + /**
|
| + * @return {boolean}
|
| + */
|
| + hasOnlyUnloadedChildren: function()
|
| + {
|
| + if (!this._childIds || !this._childIds.length)
|
| + return false;
|
| +
|
| + return !this._childIds.some((id) => this._accessibilityModel.axNodeForId(id) !== undefined);
|
| + },
|
| +
|
| + /**
|
| + * Build debugging string for this subtree
|
| + * @param {!WebInspector.AccessibilityNode} inspectedNode
|
| + * @param {string=} leadingSpace
|
| + * @return {string}
|
| + */
|
| + printSelfAndChildren: function(inspectedNode, leadingSpace)
|
| + {
|
| + var string = leadingSpace || "";
|
| + if (this._role)
|
| + string += this._role.value;
|
| + else
|
| + string += "<no role>";
|
| + string += (this._name ? " " + this._name.value : "");
|
| + string += " " + this._id;
|
| + if (this._domNode)
|
| + string += " (" + this._domNode.nodeName() + ")";
|
| + if (this === inspectedNode)
|
| + string += " *";
|
| + for (var child of this.children())
|
| + string += "\n" + child.printSelfAndChildren(inspectedNode, (leadingSpace || "") + " ");
|
| + return string;
|
| + },
|
| +
|
| + __proto__: WebInspector.SDKObject.prototype
|
| +};
|
|
|
| /**
|
| * @constructor
|
| @@ -12,31 +247,121 @@ WebInspector.AccessibilityModel = function(target)
|
| {
|
| WebInspector.SDKModel.call(this, WebInspector.AccessibilityModel, target);
|
| this._agent = target.accessibilityAgent();
|
| +
|
| + /** @type {!Map<string, !WebInspector.AccessibilityNode>} */
|
| + this._axIdToAXNode = new Map();
|
| + this._domNodeToAXNode = new Map();
|
| };
|
|
|
| WebInspector.AccessibilityModel.prototype = {
|
| /**
|
| - * @param {!DOMAgent.NodeId} nodeId
|
| - * @return {!Promise.<?Array<!AccessibilityAgent.AXNode>>}
|
| + * @param {!WebInspector.DOMNode} node
|
| + * @return {!Promise<?WebInspector.AccessibilityNode>}
|
| + */
|
| + setDOMNode: function(node)
|
| + {
|
| + this._axIdToAXNode.clear();
|
| + this._inspectedDOMNode = node;
|
| +
|
| + return this._requestPartialAXTree(node);
|
| + },
|
| +
|
| + /**
|
| + * @return {?WebInspector.AccessibilityNode}
|
| */
|
| - getAXNodeChain: function(nodeId)
|
| + getInspectedAXNode: function()
|
| + {
|
| + this.logTree();
|
| + return this._domNodeToAXNode.get(this._inspectedDOMNode);
|
| + },
|
| +
|
| + /**
|
| + * @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)
|
| + {
|
| + this._axIdToAXNode.set(axId, axNode);
|
| + },
|
| +
|
| + /**
|
| + * @param {!WebInspector.DOMNode} domNode
|
| + * @return {?WebInspector.AccessibilityNode}
|
| + */
|
| + axNodeForDOMNode: function(domNode)
|
| + {
|
| + return this._domNodeToAXNode.get(domNode);
|
| + },
|
| +
|
| + /**
|
| + * @param {!WebInspector.DOMNode} domNode
|
| + * @param {!WebInspector.AccessibilityNode} axNode
|
| + */
|
| + setAXNodeForDOMNode: function(domNode, axNode)
|
| + {
|
| + this._domNodeToAXNode.set(domNode, axNode);
|
| + },
|
| +
|
| + logTree: function()
|
| + {
|
| + var inspectedNode = this._domNodeToAXNode.get(this._inspectedDOMNode);
|
| + if (!inspectedNode)
|
| + return;
|
| + var rootNode = inspectedNode;
|
| + while (rootNode.parentNode())
|
| + rootNode = rootNode.parentNode();
|
| + console.log(rootNode.printSelfAndChildren(inspectedNode));
|
| + },
|
| +
|
| + /**
|
| + * @param {!WebInspector.DOMNode} node
|
| + * @return {!Promise<?WebInspector.AccessibilityNode>}
|
| + */
|
| + _requestPartialAXTree: function(node)
|
| {
|
| /**
|
| + * @this {WebInspector.AccessibilityModel}
|
| * @param {?string} error
|
| - * @param {!Array<!AccessibilityAgent.AXNode>=} nodes
|
| - * @return {?Array<!AccessibilityAgent.AXNode>}
|
| + * @param {!Array<!AccessibilityAgent.AXNode>=} payloads
|
| */
|
| - 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;
|
| +
|
| + for (var payload of payloads)
|
| + new WebInspector.AccessibilityNode(this, payload);
|
| }
|
| - return this._agent.getAXNodeChain(nodeId, true, parsePayload);
|
| + return this._agent.getPartialAXTree(node.id, parsePayload.bind(this));
|
| + },
|
| +
|
| + /**
|
| + * @return {!Promise}
|
| + */
|
| + resolveAllDOMNodes: function()
|
| + {
|
| + var promises = [];
|
| + for (var axNode of this._axIdToAXNode.values())
|
| + promises.push(axNode.resolveDOMNode());
|
| + return Promise.all(promises);
|
| },
|
|
|
| __proto__: WebInspector.SDKModel.prototype
|
| -}
|
| +};
|
|
|
| WebInspector.AccessibilityModel._symbol = Symbol("AccessibilityModel");
|
| /**
|
|
|