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