Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.SDKObject} | |
| 8 * @param {!WebInspector.AccessibilityModel} accessibilityModel | |
| 9 * @param {!AccessibilityAgent.AXNode} payload | |
| 10 */ | |
| 11 WebInspector.AccessibilityNode = function(accessibilityModel, payload) | |
| 12 { | |
| 13 WebInspector.SDKObject.call(this, accessibilityModel.target()); | |
| 14 this._accessibilityModel = accessibilityModel; | |
| 15 this._agent = accessibilityModel._agent; | |
| 16 | |
| 17 this._id = payload.nodeId; | |
| 18 accessibilityModel.setAXNodeForAXId(this._id, this); | |
| 19 | |
| 20 this._ignored = payload.ignored; | |
| 21 if (this._ignored && "ignoredReasons" in payload) | |
| 22 this._ignoredReasons = payload.ignoredReasons; | |
| 23 | |
| 24 if ("role" in payload) | |
| 25 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.
| |
| 26 if ("name" in payload) | |
| 27 this._name = payload.name; | |
| 28 if ("description" in payload) | |
| 29 this._description = payload.description; | |
| 30 if ("value" in payload) | |
| 31 this._value = payload.value; | |
| 32 if ("properties" in payload) | |
| 33 this._properties = payload.properties; | |
| 34 if ("parentId" in payload) | |
| 35 this._parentId = payload.parentId; | |
| 36 if ("childIds" in payload) | |
| 37 this._childIds = payload.childIds; | |
| 38 if ("domNodeId" in payload) | |
| 39 this._domNodeId = payload.domNodeId; | |
| 40 }; | |
| 41 | |
| 42 WebInspector.AccessibilityNode.prototype = { | |
| 43 /** | |
| 44 * @return {boolean} | |
| 45 */ | |
| 46 ignored: function() | |
| 47 { | |
| 48 return this._ignored; | |
| 49 }, | |
| 50 | |
| 51 /** | |
| 52 * @return {?Array<!AccessibilityAgent.AXProperty>} | |
| 53 */ | |
| 54 ignoredReasons: function() | |
| 55 { | |
| 56 return this._ignoredReasons || null; | |
| 57 }, | |
| 58 | |
| 59 /** | |
| 60 * @return {?AccessibilityAgent.AXValue} | |
| 61 */ | |
| 62 role: function() | |
| 63 { | |
| 64 return this._role || null; | |
| 65 }, | |
| 66 | |
| 67 /** | |
| 68 * @return {!Array<!AccessibilityAgent.AXProperty>} | |
| 69 */ | |
| 70 coreProperties: function() | |
| 71 { | |
| 72 var properties = []; | |
| 73 for (var propertyName of ["name", "description", "value"]) { | |
| 74 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.
| |
| 75 continue; | |
| 76 properties.push(/** @type {!AccessibilityAgent.AXProperty} */ ({name : propertyName, value: this["_" + propertyName]})); | |
| 77 } | |
| 78 return properties; | |
| 79 }, | |
| 80 | |
| 81 /** | |
| 82 * @return {?AccessibilityAgent.AXValue} | |
| 83 */ | |
| 84 name: function() | |
| 85 { | |
| 86 return this._name || null; | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * @return {?AccessibilityAgent.AXValue} | |
| 91 */ | |
| 92 description: function() | |
| 93 { | |
| 94 return this._description || null; | |
| 95 }, | |
| 96 | |
| 97 /** | |
| 98 * @return {?AccessibilityAgent.AXValue} | |
| 99 */ | |
| 100 value: function() | |
| 101 { | |
| 102 return this._value || null; | |
| 103 }, | |
| 104 | |
| 105 /** | |
| 106 * @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.
| |
| 107 */ | |
| 108 properties: function() | |
| 109 { | |
| 110 return this._properties || null; | |
| 111 }, | |
| 112 | |
| 113 /** | |
| 114 * @return {?WebInspector.AccessibilityNode} | |
| 115 */ | |
| 116 parentNode: function() | |
| 117 { | |
| 118 if (!this._parentId) | |
| 119 return null; | |
| 120 return this._accessibilityModel.axNodeForId(this._parentId); | |
| 121 }, | |
| 122 | |
| 123 __proto__: WebInspector.SDKObject.prototype | |
| 124 }; | |
| 5 | 125 |
| 6 /** | 126 /** |
| 7 * @constructor | 127 * @constructor |
| 8 * @extends {WebInspector.SDKModel} | 128 * @extends {WebInspector.SDKModel} |
| 9 * @param {!WebInspector.Target} target | 129 * @param {!WebInspector.Target} target |
| 10 */ | 130 */ |
| 11 WebInspector.AccessibilityModel = function(target) | 131 WebInspector.AccessibilityModel = function(target) |
| 12 { | 132 { |
| 13 WebInspector.SDKModel.call(this, WebInspector.AccessibilityModel, target); | 133 WebInspector.SDKModel.call(this, WebInspector.AccessibilityModel, target); |
| 14 this._agent = target.accessibilityAgent(); | 134 this._agent = target.accessibilityAgent(); |
| 135 | |
| 136 /** @type {!Map<string, !WebInspector.AccessibilityNode>} */ | |
| 137 this._axIdToAXNode = new Map(); | |
| 15 }; | 138 }; |
| 16 | 139 |
| 17 WebInspector.AccessibilityModel.prototype = { | 140 WebInspector.AccessibilityModel.prototype = { |
| 141 | |
| 18 /** | 142 /** |
| 19 * @param {!DOMAgent.NodeId} nodeId | 143 * @param {string} axId |
| 20 * @return {!Promise.<?Array<!AccessibilityAgent.AXNode>>} | 144 * @return {?WebInspector.AccessibilityNode} |
| 21 */ | 145 */ |
| 22 getAXNodeChain: function(nodeId) | 146 axNodeForId: function(axId) |
| 23 { | 147 { |
| 148 return this._axIdToAXNode.get(axId); | |
| 149 }, | |
| 150 | |
| 151 /** | |
| 152 * @param {string} axId | |
| 153 * @param {!WebInspector.AccessibilityNode} axNode | |
| 154 */ | |
| 155 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.
| |
| 156 { | |
| 157 this._axIdToAXNode.set(axId, axNode); | |
| 158 }, | |
| 159 | |
| 160 /** | |
| 161 * @param {!WebInspector.DOMNode} node | |
| 162 * @return {!Promise<?Array<!WebInspector.AccessibilityNode>>} | |
| 163 */ | |
| 164 getAXNodeChain: function(node) | |
| 165 { | |
| 166 this._axIdToAXNode.clear(); | |
| 167 | |
| 24 /** | 168 /** |
| 169 * @this {WebInspector.AccessibilityModel} | |
| 25 * @param {?string} error | 170 * @param {?string} error |
| 26 * @param {!Array<!AccessibilityAgent.AXNode>=} nodes | 171 * @param {!Array<!AccessibilityAgent.AXNode>=} payloads |
| 27 * @return {?Array<!AccessibilityAgent.AXNode>} | 172 * @return {?Array<!WebInspector.AccessibilityNode>} |
| 28 */ | 173 */ |
| 29 function parsePayload(error, nodes) | 174 function parsePayload(error, payloads) |
| 30 { | 175 { |
| 31 if (error) | 176 if (error) { |
| 32 console.error("AccessibilityAgent.getAXNodeChain(): " + error); | 177 console.error("AccessibilityAgent.getAXNodeChain(): " + error); |
| 33 return nodes || null; | 178 return null; |
| 179 } | |
| 180 | |
| 181 if (!payloads) | |
| 182 return null; | |
| 183 | |
| 184 var nodes = []; | |
| 185 for (var payload of payloads) | |
| 186 nodes.push(new WebInspector.AccessibilityNode(this, payload)); | |
| 187 | |
| 188 return nodes; | |
| 34 } | 189 } |
| 35 return this._agent.getAXNodeChain(nodeId, true, parsePayload); | 190 return this._agent.getAXNodeChain(node.id, true, parsePayload.bind(this) ); |
| 36 }, | 191 }, |
| 37 | 192 |
| 38 __proto__: WebInspector.SDKModel.prototype | 193 __proto__: WebInspector.SDKModel.prototype |
| 39 } | 194 }; |
| 40 | 195 |
| 41 WebInspector.AccessibilityModel._symbol = Symbol("AccessibilityModel"); | 196 WebInspector.AccessibilityModel._symbol = Symbol("AccessibilityModel"); |
| 42 /** | 197 /** |
| 43 * @param {!WebInspector.Target} target | 198 * @param {!WebInspector.Target} target |
| 44 * @return {!WebInspector.AccessibilityModel} | 199 * @return {!WebInspector.AccessibilityModel} |
| 45 */ | 200 */ |
| 46 WebInspector.AccessibilityModel.fromTarget = function(target) | 201 WebInspector.AccessibilityModel.fromTarget = function(target) |
| 47 { | 202 { |
| 48 if (!target[WebInspector.AccessibilityModel._symbol]) | 203 if (!target[WebInspector.AccessibilityModel._symbol]) |
| 49 target[WebInspector.AccessibilityModel._symbol] = new WebInspector.Acces sibilityModel(target); | 204 target[WebInspector.AccessibilityModel._symbol] = new WebInspector.Acces sibilityModel(target); |
| 50 | 205 |
| 51 return target[WebInspector.AccessibilityModel._symbol]; | 206 return target[WebInspector.AccessibilityModel._symbol]; |
| 52 } | 207 } |
| OLD | NEW |