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