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