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

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

Issue 2390783006: [DevTools] Accessibility: Show siblings and children of selected node (Closed)
Patch Set: Handle indirect children better 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 side-by-side diff with in-line comments
Download patch
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 be0cb24e25431f030364963efa83abee814758ac..616de7b482233673956de0d415050e40066d4011 100644
--- a/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityModel.js
@@ -28,7 +28,7 @@ WebInspector.AccessibilityNode = function(accessibilityModel, payload)
this._properties = payload.properties || null;
this._parentId = payload.parentId || null;
this._childIds = payload.childIds || null;
- this._domNodeId = payload.domNodeId || null;
+ this._backendDomNodeId = payload.backendDomNodeId || null;
};
WebInspector.AccessibilityNode.prototype = {
@@ -115,6 +115,113 @@ WebInspector.AccessibilityNode.prototype = {
return this._accessibilityModel.axNodeForId(this._parentId);
},
+ /**
+ * @return {boolean}
+ */
+ isDOMNode: function()
+ {
+ return !!this._backendDomNodeId;
+ },
+
+ /**
+ * @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._backendDomNodeId)
+ return Promise.resolve(/** @type {?WebInspector.DOMNode} */ (null));
+
+ var deferredNode = new WebInspector.DeferredDOMNode(this.target(), this._backendDomNodeId);
+ return deferredNode.resolvePromise()
+ .then((domNode) => {
+ this._setDOMNode(domNode);
+ return domNode;
+ });
+ },
+
+ /**
+ * @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);
+ },
+
+ /**
+ * TODO(aboxhall): Remove once protocol is stable.
+ * @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
};
@@ -130,41 +237,32 @@ WebInspector.AccessibilityModel = function(target)
/** @type {!Map<string, !WebInspector.AccessibilityNode>} */
this._axIdToAXNode = new Map();
+ this._domNodeToAXNode = new Map();
};
WebInspector.AccessibilityModel.prototype = {
-
/**
- * @param {string} axId
- * @return {?WebInspector.AccessibilityNode}
+ * @param {!WebInspector.DOMNode} node
+ * @return {!Promise<?WebInspector.AccessibilityNode>}
*/
- axNodeForId: function(axId)
+ setDOMNode: function(node)
dgozman 2016/10/31 21:36:30 setDOMNode is a strange api for a model. It should
aboxhall 2016/10/31 22:45:15 The reason is that the model is centered on the in
{
- return this._axIdToAXNode.get(axId);
- },
+ this._axIdToAXNode.clear();
+ this._inspectedDOMNode = node;
- /**
- * @param {string} axId
- * @param {!WebInspector.AccessibilityNode} axNode
- */
- _setAXNodeForAXId: function(axId, axNode)
- {
- this._axIdToAXNode.set(axId, axNode);
+ return this._requestPartialAXTree(node);
},
/**
* @param {!WebInspector.DOMNode} node
- * @return {!Promise<?Array<!WebInspector.AccessibilityNode>>}
+ * @return {!Promise}
*/
- getAXNodeChain: function(node)
+ _requestPartialAXTree: function(node)
{
- this._axIdToAXNode.clear();
-
/**
* @this {WebInspector.AccessibilityModel}
* @param {?string} error
* @param {!Array<!AccessibilityAgent.AXNode>=} payloads
- * @return {?Array<!WebInspector.AccessibilityNode>}
*/
function parsePayload(error, payloads)
{
@@ -174,15 +272,79 @@ WebInspector.AccessibilityModel.prototype = {
}
if (!payloads)
- return null;
+ return;
- var nodes = [];
for (var payload of payloads)
- nodes.push(new WebInspector.AccessibilityNode(this, payload));
-
- return nodes;
+ new WebInspector.AccessibilityNode(this, payload);
}
- return this._agent.getAXNodeChain(node.id, true, parsePayload.bind(this));
+ return this._agent.getPartialAXTree(node.id, true, parsePayload.bind(this));
+ },
+
+ /**
+ * @return {?WebInspector.AccessibilityNode}
+ */
+ getInspectedAXNode: function()
+ {
+ 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);
+ },
+
+ // TODO(aboxhall): Remove once protocol is stable.
+ 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));
+ },
+
+ /**
+ * @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

Powered by Google App Engine
This is Rietveld 408576698