Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | /** |
| 5 | * @unrestricted |
| 6 | */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 7 | export class AXNodeSubPane extends Accessibility.AccessibilitySubPane { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 8 | constructor() { |
| 9 | super(ls`Computed Properties`); |
| 10 | |
| 11 | this.contentElement.classList.add('ax-subpane'); |
| 12 | |
| 13 | this._noNodeInfo = this.createInfo(ls`No accessibility node`); |
| 14 | this._ignoredInfo = this.createInfo(ls`Accessibility node not exposed`, 'ax-ignored-info hidden'); |
| 15 | |
| 16 | this._treeOutline = this.createTreeOutline(); |
| 17 | this._ignoredReasonsTree = this.createTreeOutline(); |
| 18 | |
| 19 | this.element.classList.add('accessibility-computed'); |
| 20 | this.registerRequiredCSS('accessibility/accessibilityNode.css'); |
Rob Paveza | 84d4144 | 2019-10-10 23:01:09 | [diff] [blame] | 21 | this._treeOutline.setFocusable(true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @param {?Accessibility.AccessibilityNode} axNode |
| 26 | * @override |
| 27 | */ |
| 28 | setAXNode(axNode) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 29 | if (this._axNode === axNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 30 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 31 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 32 | this._axNode = axNode; |
| 33 | |
| 34 | const treeOutline = this._treeOutline; |
| 35 | treeOutline.removeChildren(); |
| 36 | const ignoredReasons = this._ignoredReasonsTree; |
| 37 | ignoredReasons.removeChildren(); |
| 38 | |
| 39 | if (!axNode) { |
| 40 | treeOutline.element.classList.add('hidden'); |
| 41 | this._ignoredInfo.classList.add('hidden'); |
| 42 | ignoredReasons.element.classList.add('hidden'); |
| 43 | |
| 44 | this._noNodeInfo.classList.remove('hidden'); |
| 45 | this.element.classList.add('ax-ignored-node-pane'); |
| 46 | |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | if (axNode.ignored()) { |
| 51 | this._noNodeInfo.classList.add('hidden'); |
| 52 | treeOutline.element.classList.add('hidden'); |
| 53 | this.element.classList.add('ax-ignored-node-pane'); |
| 54 | |
| 55 | this._ignoredInfo.classList.remove('hidden'); |
| 56 | ignoredReasons.element.classList.remove('hidden'); |
| 57 | /** |
| 58 | * @param {!Protocol.Accessibility.AXProperty} property |
| 59 | */ |
| 60 | function addIgnoredReason(property) { |
| 61 | ignoredReasons.appendChild(new Accessibility.AXNodeIgnoredReasonTreeElement( |
| 62 | property, /** @type {!Accessibility.AccessibilityNode} */ (axNode))); |
| 63 | } |
| 64 | const ignoredReasonsArray = /** @type {!Array<!Protocol.Accessibility.AXProperty>} */ (axNode.ignoredReasons()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 65 | for (const reason of ignoredReasonsArray) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 66 | addIgnoredReason(reason); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 67 | } |
| 68 | if (!ignoredReasons.firstChild()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 69 | ignoredReasons.element.classList.add('hidden'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 70 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 71 | return; |
| 72 | } |
| 73 | this.element.classList.remove('ax-ignored-node-pane'); |
| 74 | |
| 75 | this._ignoredInfo.classList.add('hidden'); |
| 76 | ignoredReasons.element.classList.add('hidden'); |
| 77 | this._noNodeInfo.classList.add('hidden'); |
| 78 | |
| 79 | treeOutline.element.classList.remove('hidden'); |
| 80 | |
| 81 | /** |
| 82 | * @param {!Protocol.Accessibility.AXProperty} property |
| 83 | */ |
| 84 | function addProperty(property) { |
| 85 | treeOutline.appendChild(new Accessibility.AXNodePropertyTreePropertyElement( |
| 86 | property, /** @type {!Accessibility.AccessibilityNode} */ (axNode))); |
| 87 | } |
| 88 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 89 | for (const property of axNode.coreProperties()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 90 | addProperty(property); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 91 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 92 | |
| 93 | const roleProperty = /** @type {!Protocol.Accessibility.AXProperty} */ ({name: 'role', value: axNode.role()}); |
| 94 | addProperty(roleProperty); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 95 | for (const property of /** @type {!Array.<!Protocol.Accessibility.AXProperty>} */ (axNode.properties())) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 96 | addProperty(property); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 97 | } |
Rob Paveza | 84d4144 | 2019-10-10 23:01:09 | [diff] [blame] | 98 | |
| 99 | const firstNode = treeOutline.firstChild(); |
| 100 | if (firstNode) { |
| 101 | firstNode.select(/* omitFocus= */ true, /* selectedByUser= */ false); |
| 102 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @override |
| 107 | * @param {?SDK.DOMNode} node |
| 108 | */ |
| 109 | setNode(node) { |
| 110 | super.setNode(node); |
| 111 | this._axNode = null; |
| 112 | } |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 113 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * @unrestricted |
| 117 | */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 118 | export class AXNodePropertyTreeElement extends UI.TreeElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 119 | /** |
| 120 | * @param {!Accessibility.AccessibilityNode} axNode |
| 121 | */ |
| 122 | constructor(axNode) { |
| 123 | // Pass an empty title, the title gets made later in onattach. |
| 124 | super(''); |
| 125 | this._axNode = axNode; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @param {?Protocol.Accessibility.AXValueType} type |
| 130 | * @param {string} value |
| 131 | * @return {!Element} |
| 132 | */ |
| 133 | static createSimpleValueElement(type, value) { |
| 134 | let valueElement; |
| 135 | const AXValueType = Protocol.Accessibility.AXValueType; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 136 | if (!type || type === AXValueType.ValueUndefined || type === AXValueType.ComputedString) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 137 | valueElement = createElement('span'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 138 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 139 | valueElement = createElementWithClass('span', 'monospace'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 140 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 141 | let valueText; |
| 142 | const isStringProperty = type && Accessibility.AXNodePropertyTreeElement.StringProperties.has(type); |
| 143 | if (isStringProperty) { |
| 144 | // Render \n as a nice unicode cr symbol. |
| 145 | valueText = '"' + value.replace(/\n/g, '\u21B5') + '"'; |
| 146 | valueElement._originalTextContent = value; |
| 147 | } else { |
| 148 | valueText = String(value); |
| 149 | } |
| 150 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 151 | if (type && type in Accessibility.AXNodePropertyTreeElement.TypeStyles) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 152 | valueElement.classList.add(Accessibility.AXNodePropertyTreeElement.TypeStyles[type]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 153 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 154 | |
| 155 | valueElement.setTextContentTruncatedIfNeeded(valueText || ''); |
| 156 | |
| 157 | valueElement.title = String(value) || ''; |
| 158 | |
| 159 | return valueElement; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @param {string} tooltip |
| 164 | * @return {!Element} |
| 165 | */ |
| 166 | static createExclamationMark(tooltip) { |
Joel Einbinder | 7fbe24c | 2019-01-24 05:19:01 | [diff] [blame] | 167 | const exclamationElement = createElement('span', 'dt-icon-label'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 168 | exclamationElement.type = 'smallicon-warning'; |
| 169 | exclamationElement.title = tooltip; |
| 170 | return exclamationElement; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * @param {string} name |
| 175 | */ |
| 176 | appendNameElement(name) { |
| 177 | const nameElement = createElement('span'); |
| 178 | const AXAttributes = Accessibility.AccessibilityStrings.AXAttributes; |
| 179 | if (name in AXAttributes) { |
Mandy Chen | ba6de38 | 2019-06-07 21:38:50 | [diff] [blame] | 180 | nameElement.textContent = AXAttributes[name].name; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 181 | nameElement.title = AXAttributes[name].description; |
| 182 | nameElement.classList.add('ax-readable-name'); |
| 183 | } else { |
| 184 | nameElement.textContent = name; |
| 185 | nameElement.classList.add('ax-name'); |
| 186 | nameElement.classList.add('monospace'); |
| 187 | } |
| 188 | this.listItemElement.appendChild(nameElement); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @param {!Protocol.Accessibility.AXValue} value |
| 193 | */ |
| 194 | appendValueElement(value) { |
| 195 | const AXValueType = Protocol.Accessibility.AXValueType; |
| 196 | if (value.type === AXValueType.Idref || value.type === AXValueType.Node || value.type === AXValueType.IdrefList || |
| 197 | value.type === AXValueType.NodeList) { |
| 198 | this.appendRelatedNodeListValueElement(value); |
| 199 | return; |
| 200 | } else if (value.sources) { |
| 201 | const sources = value.sources; |
| 202 | for (let i = 0; i < sources.length; i++) { |
| 203 | const source = sources[i]; |
| 204 | const child = new Accessibility.AXValueSourceTreeElement(source, this._axNode); |
| 205 | this.appendChild(child); |
| 206 | } |
| 207 | this.expand(); |
| 208 | } |
| 209 | const element = Accessibility.AXNodePropertyTreeElement.createSimpleValueElement(value.type, String(value.value)); |
| 210 | this.listItemElement.appendChild(element); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @param {!Protocol.Accessibility.AXRelatedNode} relatedNode |
| 215 | * @param {number} index |
| 216 | */ |
| 217 | appendRelatedNode(relatedNode, index) { |
| 218 | const deferredNode = |
| 219 | new SDK.DeferredDOMNode(this._axNode.accessibilityModel().target(), relatedNode.backendDOMNodeId); |
| 220 | const nodeTreeElement = new Accessibility.AXRelatedNodeSourceTreeElement({deferredNode: deferredNode}, relatedNode); |
| 221 | this.appendChild(nodeTreeElement); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * @param {!Protocol.Accessibility.AXRelatedNode} relatedNode |
| 226 | */ |
| 227 | appendRelatedNodeInline(relatedNode) { |
| 228 | const deferredNode = |
| 229 | new SDK.DeferredDOMNode(this._axNode.accessibilityModel().target(), relatedNode.backendDOMNodeId); |
| 230 | const linkedNode = new Accessibility.AXRelatedNodeElement({deferredNode: deferredNode}, relatedNode); |
| 231 | this.listItemElement.appendChild(linkedNode.render()); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * @param {!Protocol.Accessibility.AXValue} value |
| 236 | */ |
| 237 | appendRelatedNodeListValueElement(value) { |
| 238 | if (value.relatedNodes.length === 1 && !value.value) { |
| 239 | this.appendRelatedNodeInline(value.relatedNodes[0]); |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | value.relatedNodes.forEach(this.appendRelatedNode, this); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 244 | if (value.relatedNodes.length <= 3) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 245 | this.expand(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 246 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 247 | this.collapse(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 248 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 249 | } |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 250 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 251 | |
| 252 | /** @type {!Object<string, string>} */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 253 | export const TypeStyles = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 254 | attribute: 'ax-value-string', |
| 255 | boolean: 'object-value-boolean', |
| 256 | booleanOrUndefined: 'object-value-boolean', |
| 257 | computedString: 'ax-readable-string', |
| 258 | idref: 'ax-value-string', |
| 259 | idrefList: 'ax-value-string', |
| 260 | integer: 'object-value-number', |
| 261 | internalRole: 'ax-internal-role', |
| 262 | number: 'ax-value-number', |
| 263 | role: 'ax-role', |
| 264 | string: 'ax-value-string', |
| 265 | tristate: 'object-value-boolean', |
| 266 | valueUndefined: 'ax-value-undefined' |
| 267 | }; |
| 268 | |
| 269 | /** @type {!Set.<!Protocol.Accessibility.AXValueType>} */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 270 | export const StringProperties = new Set([ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 271 | Protocol.Accessibility.AXValueType.String, Protocol.Accessibility.AXValueType.ComputedString, |
| 272 | Protocol.Accessibility.AXValueType.IdrefList, Protocol.Accessibility.AXValueType.Idref |
| 273 | ]); |
| 274 | |
| 275 | /** |
| 276 | * @unrestricted |
| 277 | */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 278 | export class AXNodePropertyTreePropertyElement extends AXNodePropertyTreeElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 279 | /** |
| 280 | * @param {!Protocol.Accessibility.AXProperty} property |
| 281 | * @param {!Accessibility.AccessibilityNode} axNode |
| 282 | */ |
| 283 | constructor(property, axNode) { |
| 284 | super(axNode); |
| 285 | |
| 286 | this._property = property; |
| 287 | this.toggleOnClick = true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 288 | |
| 289 | this.listItemElement.classList.add('property'); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * @override |
| 294 | */ |
| 295 | onattach() { |
| 296 | this._update(); |
| 297 | } |
| 298 | |
| 299 | _update() { |
| 300 | this.listItemElement.removeChildren(); |
| 301 | |
| 302 | this.appendNameElement(this._property.name); |
| 303 | |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 304 | this.listItemElement.createChild('span', 'separator').textContent = ':\xA0'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 305 | |
| 306 | this.appendValueElement(this._property.value); |
| 307 | } |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 308 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 309 | |
| 310 | /** |
| 311 | * @unrestricted |
| 312 | */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 313 | export class AXValueSourceTreeElement extends AXNodePropertyTreeElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 314 | /** |
| 315 | * @param {!Protocol.Accessibility.AXValueSource} source |
| 316 | * @param {!Accessibility.AccessibilityNode} axNode |
| 317 | */ |
| 318 | constructor(source, axNode) { |
| 319 | super(axNode); |
| 320 | this._source = source; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /** |
| 324 | * @override |
| 325 | */ |
| 326 | onattach() { |
| 327 | this._update(); |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * @param {!Protocol.Accessibility.AXRelatedNode} relatedNode |
| 332 | * @param {number} index |
| 333 | * @param {string} idref |
| 334 | */ |
| 335 | appendRelatedNodeWithIdref(relatedNode, index, idref) { |
| 336 | const deferredNode = |
| 337 | new SDK.DeferredDOMNode(this._axNode.accessibilityModel().target(), relatedNode.backendDOMNodeId); |
| 338 | const nodeTreeElement = |
| 339 | new Accessibility.AXRelatedNodeSourceTreeElement({deferredNode: deferredNode, idref: idref}, relatedNode); |
| 340 | this.appendChild(nodeTreeElement); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * @param {!Protocol.Accessibility.AXValue} value |
| 345 | */ |
| 346 | appendIDRefValueElement(value) { |
| 347 | const relatedNodes = value.relatedNodes; |
| 348 | |
| 349 | const idrefs = value.value.trim().split(/\s+/); |
| 350 | if (idrefs.length === 1) { |
| 351 | const idref = idrefs[0]; |
| 352 | const matchingNode = relatedNodes.find(node => node.idref === idref); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 353 | if (matchingNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 354 | this.appendRelatedNodeWithIdref(matchingNode, 0, idref); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 355 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 356 | this.listItemElement.appendChild(new Accessibility.AXRelatedNodeElement({idref: idref}).render()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 357 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 358 | |
| 359 | } else { |
| 360 | // TODO(aboxhall): exclamation mark if not idreflist type |
| 361 | for (let i = 0; i < idrefs.length; ++i) { |
| 362 | const idref = idrefs[i]; |
| 363 | const matchingNode = relatedNodes.find(node => node.idref === idref); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 364 | if (matchingNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 365 | this.appendRelatedNodeWithIdref(matchingNode, i, idref); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 366 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 367 | this.appendChild(new Accessibility.AXRelatedNodeSourceTreeElement({idref: idref})); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 368 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * @param {!Protocol.Accessibility.AXValue} value |
| 375 | * @override |
| 376 | */ |
| 377 | appendRelatedNodeListValueElement(value) { |
| 378 | const relatedNodes = value.relatedNodes; |
| 379 | const numNodes = relatedNodes.length; |
| 380 | |
| 381 | if (value.type === Protocol.Accessibility.AXValueType.IdrefList || |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 382 | value.type === Protocol.Accessibility.AXValueType.Idref) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 383 | this.appendIDRefValueElement(value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 384 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 385 | super.appendRelatedNodeListValueElement(value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 386 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 387 | |
| 388 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 389 | if (numNodes <= 3) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 390 | this.expand(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 391 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 392 | this.collapse(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 393 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /** |
| 397 | * @param {!Protocol.Accessibility.AXValueSource} source |
| 398 | */ |
| 399 | appendSourceNameElement(source) { |
| 400 | const nameElement = createElement('span'); |
| 401 | const AXValueSourceType = Protocol.Accessibility.AXValueSourceType; |
| 402 | const type = source.type; |
| 403 | switch (type) { |
| 404 | case AXValueSourceType.Attribute: |
| 405 | case AXValueSourceType.Placeholder: |
| 406 | case AXValueSourceType.RelatedElement: |
| 407 | if (source.nativeSource) { |
| 408 | const AXNativeSourceTypes = Accessibility.AccessibilityStrings.AXNativeSourceTypes; |
| 409 | const nativeSource = source.nativeSource; |
Mandy Chen | ba6de38 | 2019-06-07 21:38:50 | [diff] [blame] | 410 | nameElement.textContent = AXNativeSourceTypes[nativeSource].name; |
| 411 | nameElement.title = AXNativeSourceTypes[nativeSource].description; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 412 | nameElement.classList.add('ax-readable-name'); |
| 413 | break; |
| 414 | } |
| 415 | nameElement.textContent = source.attribute; |
| 416 | nameElement.classList.add('ax-name'); |
| 417 | nameElement.classList.add('monospace'); |
| 418 | break; |
| 419 | default: |
| 420 | const AXSourceTypes = Accessibility.AccessibilityStrings.AXSourceTypes; |
| 421 | if (type in AXSourceTypes) { |
Mandy Chen | ba6de38 | 2019-06-07 21:38:50 | [diff] [blame] | 422 | nameElement.textContent = AXSourceTypes[type].name; |
| 423 | nameElement.title = AXSourceTypes[type].description; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 424 | nameElement.classList.add('ax-readable-name'); |
| 425 | } else { |
| 426 | console.warn(type, 'not in AXSourceTypes'); |
Mandy Chen | ba6de38 | 2019-06-07 21:38:50 | [diff] [blame] | 427 | nameElement.textContent = type; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | this.listItemElement.appendChild(nameElement); |
| 431 | } |
| 432 | |
| 433 | _update() { |
| 434 | this.listItemElement.removeChildren(); |
| 435 | |
| 436 | if (this._source.invalid) { |
| 437 | const exclamationMark = Accessibility.AXNodePropertyTreeElement.createExclamationMark(ls`Invalid source.`); |
| 438 | this.listItemElement.appendChild(exclamationMark); |
| 439 | this.listItemElement.classList.add('ax-value-source-invalid'); |
| 440 | } else if (this._source.superseded) { |
| 441 | this.listItemElement.classList.add('ax-value-source-unused'); |
| 442 | } |
| 443 | |
| 444 | this.appendSourceNameElement(this._source); |
| 445 | |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 446 | this.listItemElement.createChild('span', 'separator').textContent = ':\xA0'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 447 | |
| 448 | if (this._source.attributeValue) { |
| 449 | this.appendValueElement(this._source.attributeValue); |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 450 | this.listItemElement.createTextChild('\xA0'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 451 | } else if (this._source.nativeSourceValue) { |
| 452 | this.appendValueElement(this._source.nativeSourceValue); |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 453 | this.listItemElement.createTextChild('\xA0'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 454 | if (this._source.value) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 455 | this.appendValueElement(this._source.value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 456 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 457 | } else if (this._source.value) { |
| 458 | this.appendValueElement(this._source.value); |
| 459 | } else { |
| 460 | const valueElement = Accessibility.AXNodePropertyTreeElement.createSimpleValueElement( |
| 461 | Protocol.Accessibility.AXValueType.ValueUndefined, ls`Not specified`); |
| 462 | this.listItemElement.appendChild(valueElement); |
| 463 | this.listItemElement.classList.add('ax-value-source-unused'); |
| 464 | } |
| 465 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 466 | if (this._source.value && this._source.superseded) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 467 | this.listItemElement.classList.add('ax-value-source-superseded'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 468 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 469 | } |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 470 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 471 | |
| 472 | /** |
| 473 | * @unrestricted |
| 474 | */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 475 | export class AXRelatedNodeSourceTreeElement extends UI.TreeElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 476 | /** |
| 477 | * @param {{deferredNode: (!SDK.DeferredDOMNode|undefined), idref: (string|undefined)}} node |
| 478 | * @param {!Protocol.Accessibility.AXRelatedNode=} value |
| 479 | */ |
| 480 | constructor(node, value) { |
| 481 | super(''); |
| 482 | |
| 483 | this._value = value; |
| 484 | this._axRelatedNodeElement = new Accessibility.AXRelatedNodeElement(node, value); |
Rob Paveza | 84d4144 | 2019-10-10 23:01:09 | [diff] [blame] | 485 | this.selectable = true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /** |
| 489 | * @override |
| 490 | */ |
| 491 | onattach() { |
| 492 | this.listItemElement.appendChild(this._axRelatedNodeElement.render()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 493 | if (!this._value) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 494 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 495 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 496 | |
| 497 | if (this._value.text) { |
| 498 | this.listItemElement.appendChild(Accessibility.AXNodePropertyTreeElement.createSimpleValueElement( |
| 499 | Protocol.Accessibility.AXValueType.ComputedString, this._value.text)); |
| 500 | } |
| 501 | } |
Rob Paveza | 84d4144 | 2019-10-10 23:01:09 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * @override |
| 505 | */ |
| 506 | onenter() { |
| 507 | this._axRelatedNodeElement.revealNode(); |
| 508 | return true; |
| 509 | } |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 510 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 511 | |
| 512 | /** |
| 513 | * @unrestricted |
| 514 | */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 515 | export class AXRelatedNodeElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 516 | /** |
| 517 | * @param {{deferredNode: (!SDK.DeferredDOMNode|undefined), idref: (string|undefined)}} node |
| 518 | * @param {!Protocol.Accessibility.AXRelatedNode=} value |
| 519 | */ |
| 520 | constructor(node, value) { |
| 521 | this._deferredNode = node.deferredNode; |
| 522 | this._idref = node.idref; |
| 523 | this._value = value; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * @return {!Element} |
| 528 | */ |
| 529 | render() { |
| 530 | const element = createElement('span'); |
| 531 | let valueElement; |
| 532 | |
| 533 | if (this._deferredNode) { |
| 534 | valueElement = createElement('span'); |
| 535 | element.appendChild(valueElement); |
Alice Boxhall | 6ac4343 | 2018-11-22 08:24:18 | [diff] [blame] | 536 | this._deferredNode.resolvePromise().then(node => { |
Jeff Fisher | 3f5f19c | 2019-08-28 19:10:02 | [diff] [blame] | 537 | Common.Linkifier.linkify(node, {preventKeyboardFocus: true}) |
| 538 | .then(linkfied => valueElement.appendChild(linkfied)); |
Alice Boxhall | 6ac4343 | 2018-11-22 08:24:18 | [diff] [blame] | 539 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 540 | } else if (this._idref) { |
| 541 | element.classList.add('invalid'); |
| 542 | valueElement = Accessibility.AXNodePropertyTreeElement.createExclamationMark(ls`No node with this ID.`); |
| 543 | valueElement.createTextChild(this._idref); |
| 544 | element.appendChild(valueElement); |
| 545 | } |
| 546 | |
| 547 | return element; |
| 548 | } |
Rob Paveza | 84d4144 | 2019-10-10 23:01:09 | [diff] [blame] | 549 | |
| 550 | /** |
| 551 | * Attempts to cause the node referred to by the related node to be selected in the tree. |
| 552 | */ |
| 553 | revealNode() { |
| 554 | this._deferredNode.resolvePromise().then(node => Common.Revealer.reveal(node)); |
| 555 | } |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 556 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 557 | |
| 558 | /** |
| 559 | * @unrestricted |
| 560 | */ |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 561 | export class AXNodeIgnoredReasonTreeElement extends AXNodePropertyTreeElement { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 562 | /** |
| 563 | * @param {!Protocol.Accessibility.AXProperty} property |
| 564 | * @param {!Accessibility.AccessibilityNode} axNode |
| 565 | */ |
| 566 | constructor(property, axNode) { |
| 567 | super(axNode); |
| 568 | this._property = property; |
| 569 | this._axNode = axNode; |
| 570 | this.toggleOnClick = true; |
| 571 | this.selectable = false; |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * @param {?string} reason |
| 576 | * @param {?Accessibility.AccessibilityNode} axNode |
| 577 | * @return {?Element} |
| 578 | */ |
| 579 | static createReasonElement(reason, axNode) { |
| 580 | let reasonElement = null; |
| 581 | switch (reason) { |
| 582 | case 'activeModalDialog': |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 583 | reasonElement = UI.formatLocalized('Element is hidden by active modal dialog:\xA0', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 584 | break; |
| 585 | case 'ancestorIsLeafNode': |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 586 | reasonElement = UI.formatLocalized('Ancestor\'s children are all presentational:\xA0', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 587 | break; |
| 588 | case 'ariaHiddenElement': { |
| 589 | const ariaHiddenSpan = createElement('span', 'source-code').textContent = 'aria-hidden'; |
| 590 | reasonElement = UI.formatLocalized('Element is %s.', [ariaHiddenSpan]); |
| 591 | break; |
| 592 | } |
| 593 | case 'ariaHiddenSubtree': { |
| 594 | const ariaHiddenSpan = createElement('span', 'source-code').textContent = 'aria-hidden'; |
| 595 | const trueSpan = createElement('span', 'source-code').textContent = 'true'; |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 596 | reasonElement = UI.formatLocalized('%s is %s on ancestor:\xA0', [ariaHiddenSpan, trueSpan]); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 597 | break; |
| 598 | } |
| 599 | case 'emptyAlt': |
| 600 | reasonElement = UI.formatLocalized('Element has empty alt text.', []); |
| 601 | break; |
| 602 | case 'emptyText': |
| 603 | reasonElement = UI.formatLocalized('No text content.', []); |
| 604 | break; |
| 605 | case 'inertElement': |
| 606 | reasonElement = UI.formatLocalized('Element is inert.', []); |
| 607 | break; |
| 608 | case 'inertSubtree': |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 609 | reasonElement = UI.formatLocalized('Element is in an inert subtree from\xA0', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 610 | break; |
| 611 | case 'inheritsPresentation': |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 612 | reasonElement = UI.formatLocalized('Element inherits presentational role from\xA0', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 613 | break; |
| 614 | case 'labelContainer': |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 615 | reasonElement = UI.formatLocalized('Part of label element:\xA0', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 616 | break; |
| 617 | case 'labelFor': |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 618 | reasonElement = UI.formatLocalized('Label for\xA0', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 619 | break; |
| 620 | case 'notRendered': |
| 621 | reasonElement = UI.formatLocalized('Element is not rendered.', []); |
| 622 | break; |
| 623 | case 'notVisible': |
| 624 | reasonElement = UI.formatLocalized('Element is not visible.', []); |
| 625 | break; |
| 626 | case 'presentationalRole': { |
| 627 | const rolePresentationSpan = createElement('span', 'source-code').textContent = 'role=' + axNode.role().value; |
| 628 | reasonElement = UI.formatLocalized('Element has %s.', [rolePresentationSpan]); |
| 629 | break; |
| 630 | } |
| 631 | case 'probablyPresentational': |
| 632 | reasonElement = UI.formatLocalized('Element is presentational.', []); |
| 633 | break; |
| 634 | case 'staticTextUsedAsNameFor': |
Mathias Bynens | 7d8cd34 | 2019-09-17 13:32:10 | [diff] [blame] | 635 | reasonElement = UI.formatLocalized('Static text node is used as name for\xA0', []); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 636 | break; |
| 637 | case 'uninteresting': |
| 638 | reasonElement = UI.formatLocalized('Element not interesting for accessibility.', []); |
| 639 | break; |
| 640 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 641 | if (reasonElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 642 | reasonElement.classList.add('ax-reason'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 643 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 644 | return reasonElement; |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * @override |
| 649 | */ |
| 650 | onattach() { |
| 651 | this.listItemElement.removeChildren(); |
| 652 | |
| 653 | this._reasonElement = |
| 654 | Accessibility.AXNodeIgnoredReasonTreeElement.createReasonElement(this._property.name, this._axNode); |
| 655 | this.listItemElement.appendChild(this._reasonElement); |
| 656 | |
| 657 | const value = this._property.value; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 658 | if (value.type === Protocol.Accessibility.AXValueType.Idref) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 659 | this.appendRelatedNodeListValueElement(value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 660 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 661 | } |
Paul Lewis | f16142c | 2019-11-07 15:56:04 | [diff] [blame^] | 662 | } |
| 663 | |
| 664 | /* Legacy exported object */ |
| 665 | self.Accessibility = self.Accessibility || {}; |
| 666 | |
| 667 | /* Legacy exported object */ |
| 668 | Accessibility = Accessibility || {}; |
| 669 | |
| 670 | /** |
| 671 | * @constructor |
| 672 | */ |
| 673 | Accessibility.AXNodeSubPane = AXNodeSubPane; |
| 674 | |
| 675 | /** |
| 676 | * @constructor |
| 677 | */ |
| 678 | Accessibility.AXNodePropertyTreeElement = AXNodePropertyTreeElement; |
| 679 | |
| 680 | /** @type {!Object<string, string>} */ |
| 681 | Accessibility.AXNodePropertyTreeElement.TypeStyles = TypeStyles; |
| 682 | |
| 683 | /** @type {!Set.<!Protocol.Accessibility.AXValueType>} */ |
| 684 | Accessibility.AXNodePropertyTreeElement.StringProperties = StringProperties; |
| 685 | |
| 686 | /** |
| 687 | * @constructor |
| 688 | */ |
| 689 | Accessibility.AXNodePropertyTreePropertyElement = AXNodePropertyTreePropertyElement; |
| 690 | |
| 691 | /** |
| 692 | * @constructor |
| 693 | */ |
| 694 | Accessibility.AXValueSourceTreeElement = AXValueSourceTreeElement; |
| 695 | |
| 696 | /** |
| 697 | * @constructor |
| 698 | */ |
| 699 | Accessibility.AXRelatedNodeSourceTreeElement = AXRelatedNodeSourceTreeElement; |
| 700 | |
| 701 | /** |
| 702 | * @constructor |
| 703 | */ |
| 704 | Accessibility.AXRelatedNodeElement = AXRelatedNodeElement; |
| 705 | |
| 706 | /** |
| 707 | * @constructor |
| 708 | */ |
| 709 | Accessibility.AXNodeIgnoredReasonTreeElement = AXNodeIgnoredReasonTreeElement; |