| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 var AutomationEvent = require('automationEvent').AutomationEvent; | 5 var AutomationEvent = require('automationEvent').AutomationEvent; |
| 6 var automationInternal = | 6 var automationInternal = |
| 7 require('binding').Binding.create('automationInternal').generate(); | 7 require('binding').Binding.create('automationInternal').generate(); |
| 8 var IsInteractPermitted = | 8 var IsInteractPermitted = |
| 9 requireNative('automationInternal').IsInteractPermitted; | 9 requireNative('automationInternal').IsInteractPermitted; |
| 10 | 10 |
| 11 /** |
| 12 * @param {number} axTreeID The id of the accessibility tree. |
| 13 * @return {?number} The id of the root node. |
| 14 */ |
| 15 var GetRootID = requireNative('automationInternal').GetRootID; |
| 16 |
| 17 /** |
| 18 * @param {number} axTreeID The id of the accessibility tree. |
| 19 * @param {number} nodeID The id of a node. |
| 20 * @return {?number} The id of the node's parent, or undefined if it's the |
| 21 * root of its tree or if the tree or node wasn't found. |
| 22 */ |
| 23 var GetParentID = requireNative('automationInternal').GetParentID; |
| 24 |
| 25 /** |
| 26 * @param {number} axTreeID The id of the accessibility tree. |
| 27 * @param {number} nodeID The id of a node. |
| 28 * @return {?number} The number of children of the node, or undefined if |
| 29 * the tree or node wasn't found. |
| 30 */ |
| 31 var GetChildCount = requireNative('automationInternal').GetChildCount; |
| 32 |
| 33 /** |
| 34 * @param {number} axTreeID The id of the accessibility tree. |
| 35 * @param {number} nodeID The id of a node. |
| 36 * @param {number} childIndex An index of a child of this node. |
| 37 * @return {?number} The id of the child at the given index, or undefined |
| 38 * if the tree or node or child at that index wasn't found. |
| 39 */ |
| 40 var GetChildIDAtIndex = requireNative('automationInternal').GetChildIDAtIndex; |
| 41 |
| 42 /** |
| 43 * @param {number} axTreeID The id of the accessibility tree. |
| 44 * @param {number} nodeID The id of a node. |
| 45 * @return {?number} The index of this node in its parent, or undefined if |
| 46 * the tree or node or node parent wasn't found. |
| 47 */ |
| 48 var GetIndexInParent = requireNative('automationInternal').GetIndexInParent; |
| 49 |
| 50 /** |
| 51 * @param {number} axTreeID The id of the accessibility tree. |
| 52 * @param {number} nodeID The id of a node. |
| 53 * @return {?Object} An object with a string key for every state flag set, |
| 54 * or undefined if the tree or node or node parent wasn't found. |
| 55 */ |
| 56 var GetState = requireNative('automationInternal').GetState; |
| 57 |
| 58 /** |
| 59 * @param {number} axTreeID The id of the accessibility tree. |
| 60 * @param {number} nodeID The id of a node. |
| 61 * @return {string} The role of the node, or undefined if the tree or |
| 62 * node wasn't found. |
| 63 */ |
| 64 var GetRole = requireNative('automationInternal').GetRole; |
| 65 |
| 66 /** |
| 67 * @param {number} axTreeID The id of the accessibility tree. |
| 68 * @param {number} nodeID The id of a node. |
| 69 * @return {?automation.Rect} The location of the node, or undefined if |
| 70 * the tree or node wasn't found. |
| 71 */ |
| 72 var GetLocation = requireNative('automationInternal').GetLocation; |
| 73 |
| 74 /** |
| 75 * @param {number} axTreeID The id of the accessibility tree. |
| 76 * @param {number} nodeID The id of a node. |
| 77 * @param {string} attr The name of a string attribute. |
| 78 * @return {?string} The value of this attribute, or undefined if the tree, |
| 79 * node, or attribute wasn't found. |
| 80 */ |
| 81 var GetStringAttribute = requireNative('automationInternal').GetStringAttribute; |
| 82 |
| 83 /** |
| 84 * @param {number} axTreeID The id of the accessibility tree. |
| 85 * @param {number} nodeID The id of a node. |
| 86 * @param {string} attr The name of an attribute. |
| 87 * @return {?boolean} The value of this attribute, or undefined if the tree, |
| 88 * node, or attribute wasn't found. |
| 89 */ |
| 90 var GetBoolAttribute = requireNative('automationInternal').GetBoolAttribute; |
| 91 |
| 92 /** |
| 93 * @param {number} axTreeID The id of the accessibility tree. |
| 94 * @param {number} nodeID The id of a node. |
| 95 * @param {string} attr The name of an attribute. |
| 96 * @return {?number} The value of this attribute, or undefined if the tree, |
| 97 * node, or attribute wasn't found. |
| 98 */ |
| 99 var GetIntAttribute = requireNative('automationInternal').GetIntAttribute; |
| 100 |
| 101 /** |
| 102 * @param {number} axTreeID The id of the accessibility tree. |
| 103 * @param {number} nodeID The id of a node. |
| 104 * @param {string} attr The name of an attribute. |
| 105 * @return {?number} The value of this attribute, or undefined if the tree, |
| 106 * node, or attribute wasn't found. |
| 107 */ |
| 108 var GetFloatAttribute = requireNative('automationInternal').GetFloatAttribute; |
| 109 |
| 110 /** |
| 111 * @param {number} axTreeID The id of the accessibility tree. |
| 112 * @param {number} nodeID The id of a node. |
| 113 * @param {string} attr The name of an attribute. |
| 114 * @return {?Array.<number>} The value of this attribute, or undefined |
| 115 * if the tree, node, or attribute wasn't found. |
| 116 */ |
| 117 var GetIntListAttribute = |
| 118 requireNative('automationInternal').GetIntListAttribute; |
| 119 |
| 11 var lastError = require('lastError'); | 120 var lastError = require('lastError'); |
| 12 var logging = requireNative('logging'); | 121 var logging = requireNative('logging'); |
| 13 var schema = requireNative('automationInternal').GetSchemaAdditions(); | 122 var schema = requireNative('automationInternal').GetSchemaAdditions(); |
| 14 var utils = require('utils'); | 123 var utils = require('utils'); |
| 15 | 124 |
| 16 /** | 125 /** |
| 17 * A single node in the Automation tree. | 126 * A single node in the Automation tree. |
| 18 * @param {AutomationRootNodeImpl} root The root of the tree. | 127 * @param {AutomationRootNodeImpl} root The root of the tree. |
| 19 * @constructor | 128 * @constructor |
| 20 */ | 129 */ |
| 21 function AutomationNodeImpl(root) { | 130 function AutomationNodeImpl(root) { |
| 22 this.rootImpl = root; | 131 this.rootImpl = root; |
| 23 this.childIds = []; | 132 this.childIds = []; |
| 24 // Public attributes. No actual data gets set on this object. | 133 // Public attributes. No actual data gets set on this object. |
| 25 this.attributes = {}; | |
| 26 // Internal object holding all attributes. | |
| 27 this.attributesInternal = {}; | |
| 28 this.listeners = {}; | 134 this.listeners = {}; |
| 29 this.location = { left: 0, top: 0, width: 0, height: 0 }; | |
| 30 } | 135 } |
| 31 | 136 |
| 32 AutomationNodeImpl.prototype = { | 137 AutomationNodeImpl.prototype = { |
| 138 treeID: -1, |
| 33 id: -1, | 139 id: -1, |
| 34 role: '', | 140 role: '', |
| 35 state: { busy: true }, | 141 state: { busy: true }, |
| 36 isRootNode: false, | 142 isRootNode: false, |
| 37 | 143 |
| 38 get root() { | 144 get root() { |
| 39 return this.rootImpl.wrapper; | 145 return this.rootImpl.wrapper; |
| 40 }, | 146 }, |
| 41 | 147 |
| 42 get parent() { | 148 get parent() { |
| 43 return this.hostTree || this.rootImpl.get(this.parentID); | 149 if (this.hostNode) |
| 150 return this.hostNode; |
| 151 var parentID = GetParentID(this.treeID, this.id); |
| 152 return this.rootImpl.get(parentID); |
| 153 }, |
| 154 |
| 155 get state() { |
| 156 return GetState(this.treeID, this.id); |
| 157 }, |
| 158 |
| 159 get role() { |
| 160 return GetRole(this.treeID, this.id); |
| 161 }, |
| 162 |
| 163 get location() { |
| 164 return GetLocation(this.treeID, this.id); |
| 165 }, |
| 166 |
| 167 get indexInParent() { |
| 168 return GetIndexInParent(this.treeID, this.id); |
| 169 }, |
| 170 |
| 171 get childTree() { |
| 172 var childTreeID = GetIntAttribute(this.treeID, this.id, 'childTreeId'); |
| 173 if (childTreeID) |
| 174 return AutomationRootNodeImpl.get(childTreeID); |
| 44 }, | 175 }, |
| 45 | 176 |
| 46 get firstChild() { | 177 get firstChild() { |
| 47 return this.childTree || this.rootImpl.get(this.childIds[0]); | 178 if (this.childTree) |
| 179 return this.childTree; |
| 180 if (!GetChildCount(this.treeID, this.id)) |
| 181 return undefined; |
| 182 var firstChildID = GetChildIDAtIndex(this.treeID, this.id, 0); |
| 183 return this.rootImpl.get(firstChildID); |
| 48 }, | 184 }, |
| 49 | 185 |
| 50 get lastChild() { | 186 get lastChild() { |
| 51 var childIds = this.childIds; | 187 if (this.childTree) |
| 52 return this.childTree || this.rootImpl.get(childIds[childIds.length - 1]); | 188 return this.childTree; |
| 189 var count = GetChildCount(this.treeID, this.id); |
| 190 if (!count) |
| 191 return undefined; |
| 192 var lastChildID = GetChildIDAtIndex(this.treeID, this.id, count - 1); |
| 193 return this.rootImpl.get(lastChildID); |
| 53 }, | 194 }, |
| 54 | 195 |
| 55 get children() { | 196 get children() { |
| 56 if (this.childTree) | 197 if (this.childTree) |
| 57 return [this.childTree]; | 198 return [this.childTree]; |
| 58 | 199 |
| 59 var children = []; | 200 var children = []; |
| 60 for (var i = 0, childID; childID = this.childIds[i]; i++) { | 201 var count = GetChildCount(this.treeID, this.id); |
| 61 logging.CHECK(this.rootImpl.get(childID)); | 202 for (var i = 0; i < count; ++i) { |
| 62 children.push(this.rootImpl.get(childID)); | 203 var childID = GetChildIDAtIndex(this.treeID, this.id, i); |
| 204 var child = this.rootImpl.get(childID); |
| 205 children.push(child); |
| 63 } | 206 } |
| 64 return children; | 207 return children; |
| 65 }, | 208 }, |
| 66 | 209 |
| 67 get previousSibling() { | 210 get previousSibling() { |
| 68 var parent = this.parent; | 211 var parent = this.parent; |
| 69 if (parent && this.indexInParent > 0) | 212 var indexInParent = GetIndexInParent(this.treeID, this.id); |
| 70 return parent.children[this.indexInParent - 1]; | 213 if (parent && indexInParent > 0) |
| 214 return parent.children[indexInParent - 1]; |
| 71 return undefined; | 215 return undefined; |
| 72 }, | 216 }, |
| 73 | 217 |
| 74 get nextSibling() { | 218 get nextSibling() { |
| 75 var parent = this.parent; | 219 var parent = this.parent; |
| 76 if (parent && this.indexInParent < parent.children.length) | 220 var indexInParent = GetIndexInParent(this.treeID, this.id); |
| 77 return parent.children[this.indexInParent + 1]; | 221 if (parent && indexInParent < parent.children.length) |
| 222 return parent.children[indexInParent + 1]; |
| 78 return undefined; | 223 return undefined; |
| 79 }, | 224 }, |
| 80 | 225 |
| 81 doDefault: function() { | 226 doDefault: function() { |
| 82 this.performAction_('doDefault'); | 227 this.performAction_('doDefault'); |
| 83 }, | 228 }, |
| 84 | 229 |
| 85 focus: function() { | 230 focus: function() { |
| 86 this.performAction_('focus'); | 231 this.performAction_('focus'); |
| 87 }, | 232 }, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 var eventPhase = event.eventPhase; | 357 var eventPhase = event.eventPhase; |
| 213 for (var i = 0; i < listeners.length; i++) { | 358 for (var i = 0; i < listeners.length; i++) { |
| 214 if (eventPhase == Event.CAPTURING_PHASE && !listeners[i].capture) | 359 if (eventPhase == Event.CAPTURING_PHASE && !listeners[i].capture) |
| 215 continue; | 360 continue; |
| 216 if (eventPhase == Event.BUBBLING_PHASE && listeners[i].capture) | 361 if (eventPhase == Event.BUBBLING_PHASE && listeners[i].capture) |
| 217 continue; | 362 continue; |
| 218 | 363 |
| 219 try { | 364 try { |
| 220 listeners[i].callback(event); | 365 listeners[i].callback(event); |
| 221 } catch (e) { | 366 } catch (e) { |
| 222 console.error('Error in event handler for ' + event.type + | 367 logging.WARN('Error in event handler for ' + event.type + |
| 223 'during phase ' + eventPhase + ': ' + | 368 ' during phase ' + eventPhase + ': ' + |
| 224 e.message + '\nStack trace: ' + e.stack); | 369 e.message + '\nStack trace: ' + e.stack); |
| 225 } | 370 } |
| 226 } | 371 } |
| 227 }, | 372 }, |
| 228 | 373 |
| 229 performAction_: function(actionType, opt_args) { | 374 performAction_: function(actionType, opt_args) { |
| 230 // Not yet initialized. | 375 // Not yet initialized. |
| 231 if (this.rootImpl.treeID === undefined || | 376 if (this.rootImpl.treeID === undefined || |
| 232 this.id === undefined) { | 377 this.id === undefined) { |
| 233 return; | 378 return; |
| 234 } | 379 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 return false; | 450 return false; |
| 306 | 451 |
| 307 if ('state' in params) { | 452 if ('state' in params) { |
| 308 for (var state in params.state) { | 453 for (var state in params.state) { |
| 309 if (params.state[state] != (state in this.state)) | 454 if (params.state[state] != (state in this.state)) |
| 310 return false; | 455 return false; |
| 311 } | 456 } |
| 312 } | 457 } |
| 313 if ('attributes' in params) { | 458 if ('attributes' in params) { |
| 314 for (var attribute in params.attributes) { | 459 for (var attribute in params.attributes) { |
| 315 if (!(attribute in this.attributesInternal)) | |
| 316 return false; | |
| 317 | |
| 318 var attrValue = params.attributes[attribute]; | 460 var attrValue = params.attributes[attribute]; |
| 319 if (typeof attrValue != 'object') { | 461 if (typeof attrValue != 'object') { |
| 320 if (this.attributesInternal[attribute] !== attrValue) | 462 if (this[attribute] !== attrValue) |
| 321 return false; | 463 return false; |
| 322 } else if (attrValue instanceof RegExp) { | 464 } else if (attrValue instanceof RegExp) { |
| 323 if (typeof this.attributesInternal[attribute] != 'string') | 465 if (typeof this[attribute] != 'string') |
| 324 return false; | 466 return false; |
| 325 if (!attrValue.test(this.attributesInternal[attribute])) | 467 if (!attrValue.test(this[attribute])) |
| 326 return false; | 468 return false; |
| 327 } else { | 469 } else { |
| 328 // TODO(aboxhall): handle intlist case. | 470 // TODO(aboxhall): handle intlist case. |
| 329 return false; | 471 return false; |
| 330 } | 472 } |
| 331 } | 473 } |
| 332 } | 474 } |
| 333 return true; | 475 return true; |
| 334 } | 476 } |
| 335 }; | 477 }; |
| 336 | 478 |
| 337 // Maps an attribute to its default value in an invalidated node. | 479 var publicAttributes = []; |
| 338 // These attributes are taken directly from the Automation idl. | |
| 339 var AutomationAttributeDefaults = { | |
| 340 'id': -1, | |
| 341 'role': '', | |
| 342 'state': {}, | |
| 343 'location': { left: 0, top: 0, width: 0, height: 0 } | |
| 344 }; | |
| 345 | 480 |
| 346 | 481 function defineStringAttribute(attributeName) { |
| 347 var AutomationAttributeTypes = [ | 482 publicAttributes.push(attributeName); |
| 348 'boolAttributes', | 483 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 349 'floatAttributes', | 484 get: function() { |
| 350 'htmlAttributes', | 485 return GetStringAttribute(this.treeID, this.id, attributeName); |
| 351 'intAttributes', | 486 } |
| 352 'intlistAttributes', | 487 }); |
| 353 'stringAttributes' | |
| 354 ]; | |
| 355 | |
| 356 /** | |
| 357 * Maps an attribute name to another attribute who's value is an id or an array | |
| 358 * of ids referencing an AutomationNode. | |
| 359 * @param {!Object<string>} | |
| 360 * @const | |
| 361 */ | |
| 362 var ATTRIBUTE_NAME_TO_ID_ATTRIBUTE = { | |
| 363 'aria-activedescendant': 'activedescendantId', | |
| 364 'aria-controls': 'controlsIds', | |
| 365 'aria-describedby': 'describedbyIds', | |
| 366 'aria-flowto': 'flowtoIds', | |
| 367 'aria-labelledby': 'labelledbyIds', | |
| 368 'aria-owns': 'ownsIds' | |
| 369 }; | |
| 370 | |
| 371 /** | |
| 372 * A set of attributes ignored in the automation API. | |
| 373 * @param {!Object<boolean>} | |
| 374 * @const | |
| 375 */ | |
| 376 var ATTRIBUTE_BLACKLIST = {'activedescendantId': true, | |
| 377 'childTreeId': true, | |
| 378 'controlsIds': true, | |
| 379 'describedbyIds': true, | |
| 380 'flowtoIds': true, | |
| 381 'labelledbyIds': true, | |
| 382 'ownsIds': true | |
| 383 }; | |
| 384 | |
| 385 function defaultStringAttribute(opt_defaultVal) { | |
| 386 return { default: undefined, reflectFrom: 'stringAttributes' }; | |
| 387 } | 488 } |
| 388 | 489 |
| 389 function defaultIntAttribute(opt_defaultVal) { | 490 defineStringAttribute('accessKey'); |
| 390 var defaultVal = (opt_defaultVal !== undefined) ? opt_defaultVal : 0; | 491 defineStringAttribute('action'); |
| 391 return { default: defaultVal, reflectFrom: 'intAttributes' }; | 492 defineStringAttribute('ariaInvalidValue'); |
| 493 defineStringAttribute('autoComplete'); |
| 494 defineStringAttribute('containerLiveRelevant'); |
| 495 defineStringAttribute('containerLiveStatus'); |
| 496 defineStringAttribute('description'); |
| 497 defineStringAttribute('display'); |
| 498 defineStringAttribute('docDoctype'); |
| 499 defineStringAttribute('docMimetype'); |
| 500 defineStringAttribute('docTitle'); |
| 501 defineStringAttribute('docUrl'); |
| 502 defineStringAttribute('dropeffect'); |
| 503 defineStringAttribute('help'); |
| 504 defineStringAttribute('htmlTag'); |
| 505 defineStringAttribute('liveRelevant'); |
| 506 defineStringAttribute('liveStatus'); |
| 507 defineStringAttribute('name'); |
| 508 defineStringAttribute('placeholder'); |
| 509 defineStringAttribute('shortcut'); |
| 510 defineStringAttribute('textInputType'); |
| 511 defineStringAttribute('url'); |
| 512 defineStringAttribute('value'); |
| 513 |
| 514 function defineBoolAttribute(attributeName) { |
| 515 publicAttributes.push(attributeName); |
| 516 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 517 get: function() { |
| 518 return GetBoolAttribute(this.treeID, this.id, attributeName); |
| 519 } |
| 520 }); |
| 392 } | 521 } |
| 393 | 522 |
| 394 function defaultFloatAttribute(opt_defaultVal) { | 523 defineBoolAttribute('ariaReadonly'); |
| 395 var defaultVal = (opt_defaultVal !== undefined) ? opt_defaultVal : 0; | 524 defineBoolAttribute('buttonMixed'); |
| 396 return { default: defaultVal, reflectFrom: 'floatAttributes' }; | 525 defineBoolAttribute('canSetValue'); |
| 526 defineBoolAttribute('canvasHasFallback'); |
| 527 defineBoolAttribute('containerLiveAtomic'); |
| 528 defineBoolAttribute('containerLiveBusy'); |
| 529 defineBoolAttribute('docLoaded'); |
| 530 defineBoolAttribute('grabbed'); |
| 531 defineBoolAttribute('isAxTreeHost'); |
| 532 defineBoolAttribute('liveAtomic'); |
| 533 defineBoolAttribute('liveBusy'); |
| 534 defineBoolAttribute('updateLocationOnly'); |
| 535 |
| 536 function defineIntAttribute(attributeName) { |
| 537 publicAttributes.push(attributeName); |
| 538 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 539 get: function() { |
| 540 return GetIntAttribute(this.treeID, this.id, attributeName); |
| 541 } |
| 542 }); |
| 397 } | 543 } |
| 398 | 544 |
| 399 function defaultBoolAttribute(opt_defaultVal) { | 545 defineIntAttribute('backgroundColor'); |
| 400 var defaultVal = (opt_defaultVal !== undefined) ? opt_defaultVal : false; | 546 defineIntAttribute('color'); |
| 401 return { default: defaultVal, reflectFrom: 'boolAttributes' }; | 547 defineIntAttribute('colorValue'); |
| 548 defineIntAttribute('hierarchicalLevel'); |
| 549 defineIntAttribute('invalidState'); |
| 550 defineIntAttribute('posInSet'); |
| 551 defineIntAttribute('scrollX'); |
| 552 defineIntAttribute('scrollXMax'); |
| 553 defineIntAttribute('scrollXMin'); |
| 554 defineIntAttribute('scrollY'); |
| 555 defineIntAttribute('scrollYMax'); |
| 556 defineIntAttribute('scrollYMin'); |
| 557 defineIntAttribute('setSize'); |
| 558 defineIntAttribute('sortDirection'); |
| 559 defineIntAttribute('tableCellColumnIndex'); |
| 560 defineIntAttribute('tableCellColumnSpan'); |
| 561 defineIntAttribute('tableCellRowIndex'); |
| 562 defineIntAttribute('tableCellRowSpan'); |
| 563 defineIntAttribute('tableColumnCount'); |
| 564 defineIntAttribute('tableColumnIndex'); |
| 565 defineIntAttribute('tableRowCount'); |
| 566 defineIntAttribute('tableRowIndex'); |
| 567 defineIntAttribute('textDirection'); |
| 568 defineIntAttribute('textSelEnd'); |
| 569 defineIntAttribute('textSelStart'); |
| 570 defineIntAttribute('textStyle'); |
| 571 |
| 572 function defineNodeRefAttribute(srcAttributeName, dstAttributeName) { |
| 573 publicAttributes.push(dstAttributeName); |
| 574 Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { |
| 575 get: function() { |
| 576 var id = GetIntAttribute(this.treeID, this.id, srcAttributeName); |
| 577 if (id) |
| 578 return this.rootImpl.get(id); |
| 579 else |
| 580 return undefined; |
| 581 } |
| 582 }); |
| 402 } | 583 } |
| 403 | 584 |
| 404 function defaultHtmlAttribute(opt_defaultVal) { | 585 defineNodeRefAttribute('activedescendantId', 'activedescendant'); |
| 405 var defaultVal = (opt_defaultVal !== undefined) ? opt_defaultVal : ''; | 586 defineNodeRefAttribute('tableColumnHeaderId', 'tableColumnHeader'); |
| 406 return { default: defaultVal, reflectFrom: 'htmlAttributes' }; | 587 defineNodeRefAttribute('tableHeaderId', 'tableHeader'); |
| 588 defineNodeRefAttribute('tableRowHeaderId', 'tableRowHeader'); |
| 589 defineNodeRefAttribute('titleUiElement', 'titleUIElement'); |
| 590 |
| 591 function defineIntListAttribute(attributeName) { |
| 592 publicAttributes.push(attributeName); |
| 593 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 594 get: function() { |
| 595 return GetIntListAttribute(this.treeID, this.id, attributeName); |
| 596 } |
| 597 }); |
| 407 } | 598 } |
| 408 | 599 |
| 409 function defaultIntListAttribute(opt_defaultVal) { | 600 defineIntListAttribute('characterOffsets'); |
| 410 var defaultVal = (opt_defaultVal !== undefined) ? opt_defaultVal : []; | 601 defineIntListAttribute('lineBreaks'); |
| 411 return { default: defaultVal, reflectFrom: 'intlistAttributes' }; | 602 defineIntListAttribute('wordEnds'); |
| 603 defineIntListAttribute('wordStarts'); |
| 604 |
| 605 function defineNodeRefListAttribute(srcAttributeName, dstAttributeName) { |
| 606 publicAttributes.push(dstAttributeName); |
| 607 Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { |
| 608 get: function() { |
| 609 var ids = GetIntListAttribute(this.treeID, this.id, srcAttributeName); |
| 610 if (!ids) |
| 611 return undefined; |
| 612 var result = []; |
| 613 for (var i = 0; i < ids.length; ++i) { |
| 614 var node = this.rootImpl.get(ids[i]); |
| 615 if (node) |
| 616 result.push(node); |
| 617 } |
| 618 return result; |
| 619 } |
| 620 }); |
| 412 } | 621 } |
| 413 | 622 |
| 414 function defaultNodeRefAttribute(idAttribute, opt_defaultVal) { | 623 defineNodeRefListAttribute('cellIds', 'cells'); |
| 415 var defaultVal = (opt_defaultVal !== undefined) ? opt_defaultVal : null; | 624 defineNodeRefListAttribute('controlsIds', 'controls'); |
| 416 return { default: defaultVal, | 625 defineNodeRefListAttribute('describedbyIds', 'describedBy'); |
| 417 idFrom: 'intAttributes', | 626 defineNodeRefListAttribute('flowtoIds', 'flowTo'); |
| 418 idAttribute: idAttribute, | 627 defineNodeRefListAttribute('labelledbyIds', 'labelledBy'); |
| 419 isRef: true }; | 628 defineNodeRefListAttribute('uniqueCellIds', 'uniqueCells'); |
| 629 |
| 630 function defineFloatAttribute(attributeName) { |
| 631 publicAttributes.push(attributeName); |
| 632 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 633 get: function() { |
| 634 return GetFloatAttribute(this.treeID, this.id, attributeName); |
| 635 } |
| 636 }); |
| 420 } | 637 } |
| 421 | 638 |
| 422 function defaultNodeRefListAttribute(idAttribute, opt_defaultVal) { | 639 defineFloatAttribute('docLoadingProgress'); |
| 423 var defaultVal = (opt_defaultVal !== undefined) ? opt_defaultVal : []; | 640 defineFloatAttribute('valueForRange'); |
| 424 return { default: [], | 641 defineFloatAttribute('minValueForRange'); |
| 425 idFrom: 'intlistAttributes', | 642 defineFloatAttribute('maxValueForRange'); |
| 426 idAttribute: idAttribute, | 643 defineFloatAttribute('fontSize'); |
| 427 isRef: true }; | |
| 428 } | |
| 429 | |
| 430 // Maps an attribute to its default value in an invalidated node. | |
| 431 // These attributes are taken directly from the Automation idl. | |
| 432 var DefaultMixinAttributes = { | |
| 433 description: defaultStringAttribute(), | |
| 434 help: defaultStringAttribute(), | |
| 435 name: defaultStringAttribute(), | |
| 436 value: defaultStringAttribute(), | |
| 437 htmlTag: defaultStringAttribute(), | |
| 438 hierarchicalLevel: defaultIntAttribute(), | |
| 439 controls: defaultNodeRefListAttribute('controlsIds'), | |
| 440 describedby: defaultNodeRefListAttribute('describedbyIds'), | |
| 441 flowto: defaultNodeRefListAttribute('flowtoIds'), | |
| 442 labelledby: defaultNodeRefListAttribute('labelledbyIds'), | |
| 443 owns: defaultNodeRefListAttribute('ownsIds'), | |
| 444 wordStarts: defaultIntListAttribute(), | |
| 445 wordEnds: defaultIntListAttribute() | |
| 446 }; | |
| 447 | |
| 448 var ActiveDescendantMixinAttribute = { | |
| 449 activedescendant: defaultNodeRefAttribute('activedescendantId') | |
| 450 }; | |
| 451 | |
| 452 var LinkMixinAttributes = { | |
| 453 url: defaultStringAttribute() | |
| 454 }; | |
| 455 | |
| 456 var DocumentMixinAttributes = { | |
| 457 docUrl: defaultStringAttribute(), | |
| 458 docTitle: defaultStringAttribute(), | |
| 459 docLoaded: defaultStringAttribute(), | |
| 460 docLoadingProgress: defaultFloatAttribute() | |
| 461 }; | |
| 462 | |
| 463 var ScrollableMixinAttributes = { | |
| 464 scrollX: defaultIntAttribute(), | |
| 465 scrollXMin: defaultIntAttribute(), | |
| 466 scrollXMax: defaultIntAttribute(), | |
| 467 scrollY: defaultIntAttribute(), | |
| 468 scrollYMin: defaultIntAttribute(), | |
| 469 scrollYMax: defaultIntAttribute() | |
| 470 }; | |
| 471 | |
| 472 var EditableTextMixinAttributes = { | |
| 473 textSelStart: defaultIntAttribute(-1), | |
| 474 textSelEnd: defaultIntAttribute(-1), | |
| 475 textInputType: defaultStringAttribute() | |
| 476 }; | |
| 477 | |
| 478 var RangeMixinAttributes = { | |
| 479 valueForRange: defaultFloatAttribute(), | |
| 480 minValueForRange: defaultFloatAttribute(), | |
| 481 maxValueForRange: defaultFloatAttribute() | |
| 482 }; | |
| 483 | |
| 484 var TableMixinAttributes = { | |
| 485 tableRowCount: defaultIntAttribute(), | |
| 486 tableColumnCount: defaultIntAttribute() | |
| 487 }; | |
| 488 | |
| 489 var TableCellMixinAttributes = { | |
| 490 tableCellColumnIndex: defaultIntAttribute(), | |
| 491 tableCellColumnSpan: defaultIntAttribute(1), | |
| 492 tableCellRowIndex: defaultIntAttribute(), | |
| 493 tableCellRowSpan: defaultIntAttribute(1) | |
| 494 }; | |
| 495 | |
| 496 var LiveRegionMixinAttributes = { | |
| 497 containerLiveAtomic: defaultBoolAttribute(), | |
| 498 containerLiveBusy: defaultBoolAttribute(), | |
| 499 containerLiveRelevant: defaultStringAttribute(), | |
| 500 containerLiveStatus: defaultStringAttribute(), | |
| 501 }; | |
| 502 | 644 |
| 503 /** | 645 /** |
| 504 * AutomationRootNode. | 646 * AutomationRootNode. |
| 505 * | 647 * |
| 506 * An AutomationRootNode is the javascript end of an AXTree living in the | 648 * An AutomationRootNode is the javascript end of an AXTree living in the |
| 507 * browser. AutomationRootNode handles unserializing incremental updates from | 649 * browser. AutomationRootNode handles unserializing incremental updates from |
| 508 * the source AXTree. Each update contains node data that form a complete tree | 650 * the source AXTree. Each update contains node data that form a complete tree |
| 509 * after applying the update. | 651 * after applying the update. |
| 510 * | 652 * |
| 511 * A brief note about ids used through this class. The source AXTree assigns | 653 * A brief note about ids used through this class. The source AXTree assigns |
| 512 * unique ids per node and we use these ids to build a hash to the actual | 654 * unique ids per node and we use these ids to build a hash to the actual |
| 513 * AutomationNode object. | 655 * AutomationNode object. |
| 514 * Thus, tree traversals amount to a lookup in our hash. | 656 * Thus, tree traversals amount to a lookup in our hash. |
| 515 * | 657 * |
| 516 * The tree itself is identified by the accessibility tree id of the | 658 * The tree itself is identified by the accessibility tree id of the |
| 517 * renderer widget host. | 659 * renderer widget host. |
| 518 * @constructor | 660 * @constructor |
| 519 */ | 661 */ |
| 520 function AutomationRootNodeImpl(treeID) { | 662 function AutomationRootNodeImpl(treeID) { |
| 521 AutomationNodeImpl.call(this, this); | 663 AutomationNodeImpl.call(this, this); |
| 522 this.treeID = treeID; | 664 this.treeID = treeID; |
| 523 this.axNodeDataCache_ = {}; | 665 this.axNodeDataCache_ = {}; |
| 524 } | 666 } |
| 525 | 667 |
| 668 AutomationRootNodeImpl.idToAutomationRootNode_ = {}; |
| 669 |
| 670 AutomationRootNodeImpl.get = function(treeID) { |
| 671 var result = AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; |
| 672 if (result) |
| 673 return result; |
| 674 return undefined; |
| 675 } |
| 676 |
| 677 AutomationRootNodeImpl.getOrCreate = function(treeID) { |
| 678 if (AutomationRootNodeImpl.idToAutomationRootNode_[treeID]) |
| 679 return AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; |
| 680 var result = new AutomationRootNode(treeID); |
| 681 AutomationRootNodeImpl.idToAutomationRootNode_[treeID] = result; |
| 682 return result; |
| 683 } |
| 684 |
| 685 AutomationRootNodeImpl.destroy = function(treeID) { |
| 686 delete AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; |
| 687 } |
| 688 |
| 526 AutomationRootNodeImpl.prototype = { | 689 AutomationRootNodeImpl.prototype = { |
| 527 __proto__: AutomationNodeImpl.prototype, | 690 __proto__: AutomationNodeImpl.prototype, |
| 528 | 691 |
| 529 isRootNode: true, | 692 isRootNode: true, |
| 530 treeID: -1, | 693 treeID: -1, |
| 531 | 694 |
| 695 get id() { |
| 696 return GetRootID(this.treeID); |
| 697 }, |
| 698 |
| 532 get: function(id) { | 699 get: function(id) { |
| 533 if (id == undefined) | 700 if (id == undefined) |
| 534 return undefined; | 701 return undefined; |
| 535 | 702 |
| 536 return this.axNodeDataCache_[id]; | 703 if (id == this.id) |
| 537 }, | 704 return this.wrapper; |
| 538 | 705 |
| 539 unserialize: function(update) { | 706 var obj = this.axNodeDataCache_[id]; |
| 540 var updateState = { pendingNodes: {}, newNodes: {} }; | 707 if (obj) |
| 541 var oldRootId = this.id; | 708 return obj; |
| 542 | 709 |
| 543 if (update.nodeIdToClear < 0) { | 710 obj = new AutomationNode(this); |
| 544 logging.WARNING('Bad nodeIdToClear: ' + update.nodeIdToClear); | 711 privates(obj).impl.treeID = this.treeID; |
| 545 lastError.set('automation', | 712 privates(obj).impl.id = id; |
| 546 'Bad update received on automation tree', | 713 this.axNodeDataCache_[id] = obj; |
| 547 null, | |
| 548 chrome); | |
| 549 return false; | |
| 550 } else if (update.nodeIdToClear > 0) { | |
| 551 var nodeToClear = this.axNodeDataCache_[update.nodeIdToClear]; | |
| 552 if (!nodeToClear) { | |
| 553 logging.WARNING('Bad nodeIdToClear: ' + update.nodeIdToClear + | |
| 554 ' (not in cache)'); | |
| 555 lastError.set('automation', | |
| 556 'Bad update received on automation tree', | |
| 557 null, | |
| 558 chrome); | |
| 559 return false; | |
| 560 } | |
| 561 if (nodeToClear === this.wrapper) { | |
| 562 this.invalidate_(nodeToClear); | |
| 563 } else { | |
| 564 var children = nodeToClear.children; | |
| 565 for (var i = 0; i < children.length; i++) | |
| 566 this.invalidate_(children[i]); | |
| 567 var nodeToClearImpl = privates(nodeToClear).impl; | |
| 568 nodeToClearImpl.childIds = [] | |
| 569 updateState.pendingNodes[nodeToClearImpl.id] = nodeToClear; | |
| 570 } | |
| 571 } | |
| 572 | 714 |
| 573 for (var i = 0; i < update.nodes.length; i++) { | 715 return obj; |
| 574 if (!this.updateNode_(update.nodes[i], updateState)) | |
| 575 return false; | |
| 576 } | |
| 577 | |
| 578 if (Object.keys(updateState.pendingNodes).length > 0) { | |
| 579 logging.WARNING('Nodes left pending by the update: ' + | |
| 580 $JSON.stringify(updateState.pendingNodes)); | |
| 581 lastError.set('automation', | |
| 582 'Bad update received on automation tree', | |
| 583 null, | |
| 584 chrome); | |
| 585 return false; | |
| 586 } | |
| 587 | |
| 588 // Notify tree change observers of new nodes. | |
| 589 // TODO(dmazzoni): Notify tree change observers of changed nodes, | |
| 590 // and handle subtreeCreated and nodeCreated properly. | |
| 591 var observers = automationUtil.treeChangeObservers; | |
| 592 if (observers.length > 0) { | |
| 593 for (var nodeId in updateState.newNodes) { | |
| 594 var node = updateState.newNodes[nodeId]; | |
| 595 var treeChange = | |
| 596 {target: node, type: schema.TreeChangeType.nodeCreated}; | |
| 597 for (var i = 0; i < observers.length; i++) { | |
| 598 try { | |
| 599 observers[i](treeChange); | |
| 600 } catch (e) { | |
| 601 console.error('Error in tree change observer for ' + | |
| 602 treeChange.type + ': ' + e.message + | |
| 603 '\nStack trace: ' + e.stack); | |
| 604 } | |
| 605 } | |
| 606 } | |
| 607 } | |
| 608 | |
| 609 return true; | |
| 610 }, | 716 }, |
| 611 | 717 |
| 612 destroy: function() { | 718 destroy: function() { |
| 613 if (this.hostTree) | 719 if (this.hostTree) |
| 614 this.hostTree.childTree = undefined; | 720 this.hostTree.childTree = undefined; |
| 615 this.hostTree = undefined; | 721 this.hostTree = undefined; |
| 616 | 722 |
| 617 this.dispatchEvent(schema.EventType.destroyed); | 723 this.dispatchEvent(schema.EventType.destroyed); |
| 618 this.invalidate_(this.wrapper); | |
| 619 }, | 724 }, |
| 620 | 725 |
| 621 onAccessibilityEvent: function(eventParams) { | 726 onAccessibilityEvent: function(eventParams) { |
| 622 if (!this.unserialize(eventParams.update)) { | |
| 623 logging.WARNING('unserialization failed'); | |
| 624 return false; | |
| 625 } | |
| 626 | |
| 627 var targetNode = this.get(eventParams.targetID); | 727 var targetNode = this.get(eventParams.targetID); |
| 628 if (targetNode) { | 728 if (targetNode) { |
| 629 var targetNodeImpl = privates(targetNode).impl; | 729 var targetNodeImpl = privates(targetNode).impl; |
| 630 targetNodeImpl.dispatchEvent(eventParams.eventType); | 730 targetNodeImpl.dispatchEvent(eventParams.eventType); |
| 631 } else { | 731 } else { |
| 632 logging.WARNING('Got ' + eventParams.eventType + | 732 logging.WARNING('Got ' + eventParams.eventType + |
| 633 ' event on unknown node: ' + eventParams.targetID + | 733 ' event on unknown node: ' + eventParams.targetID + |
| 634 '; this: ' + this.id); | 734 '; this: ' + this.id); |
| 635 } | 735 } |
| 636 return true; | 736 return true; |
| 637 }, | 737 }, |
| 638 | 738 |
| 639 toString: function() { | 739 toString: function() { |
| 640 function toStringInternal(node, indent) { | 740 function toStringInternal(node, indent) { |
| 641 if (!node) | 741 if (!node) |
| 642 return ''; | 742 return ''; |
| 643 var output = | 743 var output = |
| 644 new Array(indent).join(' ') + | 744 new Array(indent).join(' ') + |
| 645 AutomationNodeImpl.prototype.toString.call(node) + | 745 AutomationNodeImpl.prototype.toString.call(node) + |
| 646 '\n'; | 746 '\n'; |
| 647 indent += 2; | 747 indent += 2; |
| 648 for (var i = 0; i < node.children.length; i++) | 748 for (var i = 0; i < node.children.length; i++) |
| 649 output += toStringInternal(node.children[i], indent); | 749 output += toStringInternal(node.children[i], indent); |
| 650 return output; | 750 return output; |
| 651 } | 751 } |
| 652 return toStringInternal(this, 0); | 752 return toStringInternal(this, 0); |
| 653 }, | 753 }, |
| 654 | |
| 655 invalidate_: function(node) { | |
| 656 if (!node) | |
| 657 return; | |
| 658 | |
| 659 // Notify tree change observers of the removed node. | |
| 660 var observers = automationUtil.treeChangeObservers; | |
| 661 if (observers.length > 0) { | |
| 662 var treeChange = {target: node, type: schema.TreeChangeType.nodeRemoved}; | |
| 663 for (var i = 0; i < observers.length; i++) { | |
| 664 try { | |
| 665 observers[i](treeChange); | |
| 666 } catch (e) { | |
| 667 console.error('Error in tree change observer for ' + treeChange.type + | |
| 668 ': ' + e.message + '\nStack trace: ' + e.stack); | |
| 669 } | |
| 670 } | |
| 671 } | |
| 672 | |
| 673 var children = node.children; | |
| 674 | |
| 675 for (var i = 0, child; child = children[i]; i++) { | |
| 676 // Do not invalidate into subrooted nodes. | |
| 677 // TODO(dtseng): Revisit logic once out of proc iframes land. | |
| 678 if (child.root != node.root) | |
| 679 continue; | |
| 680 this.invalidate_(child); | |
| 681 } | |
| 682 | |
| 683 // Retrieve the internal AutomationNodeImpl instance for this node. | |
| 684 // This object is not accessible outside of bindings code, but we can access | |
| 685 // it here. | |
| 686 var nodeImpl = privates(node).impl; | |
| 687 var id = nodeImpl.id; | |
| 688 for (var key in AutomationAttributeDefaults) { | |
| 689 nodeImpl[key] = AutomationAttributeDefaults[key]; | |
| 690 } | |
| 691 | |
| 692 nodeImpl.attributesInternal = {}; | |
| 693 for (var key in DefaultMixinAttributes) { | |
| 694 var mixinAttribute = DefaultMixinAttributes[key]; | |
| 695 if (!mixinAttribute.isRef) | |
| 696 nodeImpl.attributesInternal[key] = mixinAttribute.default; | |
| 697 } | |
| 698 nodeImpl.childIds = []; | |
| 699 nodeImpl.id = id; | |
| 700 delete this.axNodeDataCache_[id]; | |
| 701 }, | |
| 702 | |
| 703 deleteOldChildren_: function(node, newChildIds) { | |
| 704 // Create a set of child ids in |src| for fast lookup, and return false | |
| 705 // if a duplicate is found; | |
| 706 var newChildIdSet = {}; | |
| 707 for (var i = 0; i < newChildIds.length; i++) { | |
| 708 var childId = newChildIds[i]; | |
| 709 if (newChildIdSet[childId]) { | |
| 710 logging.WARNING('Node ' + privates(node).impl.id + | |
| 711 ' has duplicate child id ' + childId); | |
| 712 lastError.set('automation', | |
| 713 'Bad update received on automation tree', | |
| 714 null, | |
| 715 chrome); | |
| 716 return false; | |
| 717 } | |
| 718 newChildIdSet[newChildIds[i]] = true; | |
| 719 } | |
| 720 | |
| 721 // Delete the old children. | |
| 722 var nodeImpl = privates(node).impl; | |
| 723 var oldChildIds = nodeImpl.childIds; | |
| 724 for (var i = 0; i < oldChildIds.length;) { | |
| 725 var oldId = oldChildIds[i]; | |
| 726 if (!newChildIdSet[oldId]) { | |
| 727 this.invalidate_(this.axNodeDataCache_[oldId]); | |
| 728 oldChildIds.splice(i, 1); | |
| 729 } else { | |
| 730 i++; | |
| 731 } | |
| 732 } | |
| 733 nodeImpl.childIds = oldChildIds; | |
| 734 | |
| 735 return true; | |
| 736 }, | |
| 737 | |
| 738 createNewChildren_: function(node, newChildIds, updateState) { | |
| 739 logging.CHECK(node); | |
| 740 var success = true; | |
| 741 | |
| 742 for (var i = 0; i < newChildIds.length; i++) { | |
| 743 var childId = newChildIds[i]; | |
| 744 var childNode = this.axNodeDataCache_[childId]; | |
| 745 if (childNode) { | |
| 746 if (childNode.parent != node) { | |
| 747 var parentId = -1; | |
| 748 if (childNode.parent) { | |
| 749 var parentImpl = privates(childNode.parent).impl; | |
| 750 parentId = parentImpl.id; | |
| 751 } | |
| 752 // This is a serious error - nodes should never be reparented. | |
| 753 // If this case occurs, continue so this node isn't left in an | |
| 754 // inconsistent state, but return failure at the end. | |
| 755 logging.WARNING('Node ' + childId + ' reparented from ' + | |
| 756 parentId + ' to ' + privates(node).impl.id); | |
| 757 lastError.set('automation', | |
| 758 'Bad update received on automation tree', | |
| 759 null, | |
| 760 chrome); | |
| 761 success = false; | |
| 762 continue; | |
| 763 } | |
| 764 } else { | |
| 765 childNode = new AutomationNode(this); | |
| 766 this.axNodeDataCache_[childId] = childNode; | |
| 767 privates(childNode).impl.id = childId; | |
| 768 updateState.pendingNodes[childId] = childNode; | |
| 769 updateState.newNodes[childId] = childNode; | |
| 770 } | |
| 771 privates(childNode).impl.indexInParent = i; | |
| 772 privates(childNode).impl.parentID = privates(node).impl.id; | |
| 773 } | |
| 774 | |
| 775 return success; | |
| 776 }, | |
| 777 | |
| 778 setData_: function(node, nodeData) { | |
| 779 var nodeImpl = privates(node).impl; | |
| 780 | |
| 781 // TODO(dtseng): Make into set listing all hosting node roles. | |
| 782 if (nodeData.role == schema.RoleType.webView) { | |
| 783 if (nodeImpl.childTreeID !== nodeData.intAttributes.childTreeId) | |
| 784 nodeImpl.pendingChildFrame = true; | |
| 785 | |
| 786 if (nodeImpl.pendingChildFrame) { | |
| 787 nodeImpl.childTreeID = nodeData.intAttributes.childTreeId; | |
| 788 automationUtil.storeTreeCallback(nodeImpl.childTreeID, function(root) { | |
| 789 nodeImpl.pendingChildFrame = false; | |
| 790 nodeImpl.childTree = root; | |
| 791 privates(root).impl.hostTree = node; | |
| 792 if (root.attributes.docLoadingProgress == 1) | |
| 793 privates(root).impl.dispatchEvent(schema.EventType.loadComplete); | |
| 794 nodeImpl.dispatchEvent(schema.EventType.childrenChanged); | |
| 795 }); | |
| 796 automationInternal.enableFrame(nodeImpl.childTreeID); | |
| 797 } | |
| 798 } | |
| 799 for (var key in AutomationAttributeDefaults) { | |
| 800 if (key in nodeData) | |
| 801 nodeImpl[key] = nodeData[key]; | |
| 802 else | |
| 803 nodeImpl[key] = AutomationAttributeDefaults[key]; | |
| 804 } | |
| 805 | |
| 806 // Set all basic attributes. | |
| 807 this.mixinAttributes_(nodeImpl, DefaultMixinAttributes, nodeData); | |
| 808 | |
| 809 // If this is a rootWebArea or webArea, set document attributes. | |
| 810 if (nodeData.role == schema.RoleType.rootWebArea || | |
| 811 nodeData.role == schema.RoleType.webArea) { | |
| 812 this.mixinAttributes_(nodeImpl, DocumentMixinAttributes, nodeData); | |
| 813 } | |
| 814 | |
| 815 // If this is a scrollable area, set scrollable attributes. | |
| 816 for (var scrollAttr in ScrollableMixinAttributes) { | |
| 817 var spec = ScrollableMixinAttributes[scrollAttr]; | |
| 818 if (this.findAttribute_(scrollAttr, spec, nodeData) !== undefined) { | |
| 819 this.mixinAttributes_(nodeImpl, ScrollableMixinAttributes, nodeData); | |
| 820 break; | |
| 821 } | |
| 822 } | |
| 823 | |
| 824 // If this is inside a live region, set live region mixins. | |
| 825 var attr = 'containerLiveStatus'; | |
| 826 var spec = LiveRegionMixinAttributes[attr]; | |
| 827 if (this.findAttribute_(attr, spec, nodeData) !== undefined) { | |
| 828 this.mixinAttributes_(nodeImpl, LiveRegionMixinAttributes, nodeData); | |
| 829 } | |
| 830 | |
| 831 // If this is a link, set link attributes | |
| 832 if (nodeData.role == 'link') { | |
| 833 this.mixinAttributes_(nodeImpl, LinkMixinAttributes, nodeData); | |
| 834 } | |
| 835 | |
| 836 // If this is an editable text area, set editable text attributes. | |
| 837 if (nodeData.role == schema.RoleType.textField || | |
| 838 nodeData.role == schema.RoleType.spinButton) { | |
| 839 this.mixinAttributes_(nodeImpl, EditableTextMixinAttributes, nodeData); | |
| 840 } | |
| 841 | |
| 842 // If this is a range type, set range attributes. | |
| 843 if (nodeData.role == schema.RoleType.progressIndicator || | |
| 844 nodeData.role == schema.RoleType.scrollBar || | |
| 845 nodeData.role == schema.RoleType.slider || | |
| 846 nodeData.role == schema.RoleType.spinButton) { | |
| 847 this.mixinAttributes_(nodeImpl, RangeMixinAttributes, nodeData); | |
| 848 } | |
| 849 | |
| 850 // If this is a table, set table attributes. | |
| 851 if (nodeData.role == schema.RoleType.table) { | |
| 852 this.mixinAttributes_(nodeImpl, TableMixinAttributes, nodeData); | |
| 853 } | |
| 854 | |
| 855 // If this is a table cell, set table cell attributes. | |
| 856 if (nodeData.role == schema.RoleType.cell) { | |
| 857 this.mixinAttributes_(nodeImpl, TableCellMixinAttributes, nodeData); | |
| 858 } | |
| 859 | |
| 860 // If this has an active descendant, expose it. | |
| 861 if ('intAttributes' in nodeData && | |
| 862 'activedescendantId' in nodeData.intAttributes) { | |
| 863 this.mixinAttributes_(nodeImpl, ActiveDescendantMixinAttribute, nodeData); | |
| 864 } | |
| 865 | |
| 866 for (var i = 0; i < AutomationAttributeTypes.length; i++) { | |
| 867 var attributeType = AutomationAttributeTypes[i]; | |
| 868 for (var attributeName in nodeData[attributeType]) { | |
| 869 nodeImpl.attributesInternal[attributeName] = | |
| 870 nodeData[attributeType][attributeName]; | |
| 871 if (ATTRIBUTE_BLACKLIST.hasOwnProperty(attributeName) || | |
| 872 nodeImpl.attributes.hasOwnProperty(attributeName)) { | |
| 873 continue; | |
| 874 } else if ( | |
| 875 ATTRIBUTE_NAME_TO_ID_ATTRIBUTE.hasOwnProperty(attributeName)) { | |
| 876 this.defineReadonlyAttribute_(nodeImpl, | |
| 877 nodeImpl.attributes, | |
| 878 attributeName, | |
| 879 true); | |
| 880 } else { | |
| 881 this.defineReadonlyAttribute_(nodeImpl, | |
| 882 nodeImpl.attributes, | |
| 883 attributeName); | |
| 884 } | |
| 885 } | |
| 886 } | |
| 887 }, | |
| 888 | |
| 889 mixinAttributes_: function(nodeImpl, attributes, nodeData) { | |
| 890 for (var attribute in attributes) { | |
| 891 var spec = attributes[attribute]; | |
| 892 if (spec.isRef) | |
| 893 this.mixinRelationshipAttribute_(nodeImpl, attribute, spec, nodeData); | |
| 894 else | |
| 895 this.mixinAttribute_(nodeImpl, attribute, spec, nodeData); | |
| 896 } | |
| 897 }, | |
| 898 | |
| 899 mixinAttribute_: function(nodeImpl, attribute, spec, nodeData) { | |
| 900 var value = this.findAttribute_(attribute, spec, nodeData); | |
| 901 if (value === undefined) | |
| 902 value = spec.default; | |
| 903 nodeImpl.attributesInternal[attribute] = value; | |
| 904 this.defineReadonlyAttribute_(nodeImpl, nodeImpl, attribute); | |
| 905 }, | |
| 906 | |
| 907 mixinRelationshipAttribute_: function(nodeImpl, attribute, spec, nodeData) { | |
| 908 var idAttribute = spec.idAttribute; | |
| 909 var idValue = spec.default; | |
| 910 if (spec.idFrom in nodeData) { | |
| 911 idValue = idAttribute in nodeData[spec.idFrom] | |
| 912 ? nodeData[spec.idFrom][idAttribute] : idValue; | |
| 913 } | |
| 914 | |
| 915 // Ok to define a list attribute with an empty list, but not a | |
| 916 // single ref with a null ID. | |
| 917 if (idValue === null) | |
| 918 return; | |
| 919 | |
| 920 nodeImpl.attributesInternal[idAttribute] = idValue; | |
| 921 this.defineReadonlyAttribute_( | |
| 922 nodeImpl, nodeImpl, attribute, true, idAttribute); | |
| 923 }, | |
| 924 | |
| 925 findAttribute_: function(attribute, spec, nodeData) { | |
| 926 if (!('reflectFrom' in spec)) | |
| 927 return; | |
| 928 var attributeGroup = spec.reflectFrom; | |
| 929 if (!(attributeGroup in nodeData)) | |
| 930 return; | |
| 931 | |
| 932 return nodeData[attributeGroup][attribute]; | |
| 933 }, | |
| 934 | |
| 935 defineReadonlyAttribute_: function( | |
| 936 node, object, attributeName, opt_isIDRef, opt_idAttribute) { | |
| 937 if (attributeName in object) | |
| 938 return; | |
| 939 | |
| 940 if (opt_isIDRef) { | |
| 941 $Object.defineProperty(object, attributeName, { | |
| 942 enumerable: true, | |
| 943 get: function() { | |
| 944 var idAttribute = opt_idAttribute || | |
| 945 ATTRIBUTE_NAME_TO_ID_ATTRIBUTE[attributeName]; | |
| 946 var idValue = node.attributesInternal[idAttribute]; | |
| 947 if (Array.isArray(idValue)) { | |
| 948 return idValue.map(function(current) { | |
| 949 return node.rootImpl.get(current); | |
| 950 }, this); | |
| 951 } | |
| 952 return node.rootImpl.get(idValue); | |
| 953 }.bind(this), | |
| 954 }); | |
| 955 } else { | |
| 956 $Object.defineProperty(object, attributeName, { | |
| 957 enumerable: true, | |
| 958 get: function() { | |
| 959 return node.attributesInternal[attributeName]; | |
| 960 }.bind(this), | |
| 961 }); | |
| 962 } | |
| 963 | |
| 964 if (object instanceof AutomationNodeImpl) { | |
| 965 // Also expose attribute publicly on the wrapper. | |
| 966 $Object.defineProperty(object.wrapper, attributeName, { | |
| 967 enumerable: true, | |
| 968 get: function() { | |
| 969 return object[attributeName]; | |
| 970 }, | |
| 971 }); | |
| 972 | |
| 973 } | |
| 974 }, | |
| 975 | |
| 976 updateNode_: function(nodeData, updateState) { | |
| 977 var node = this.axNodeDataCache_[nodeData.id]; | |
| 978 var didUpdateRoot = false; | |
| 979 if (node) { | |
| 980 delete updateState.pendingNodes[privates(node).impl.id]; | |
| 981 } else { | |
| 982 if (nodeData.role != schema.RoleType.rootWebArea && | |
| 983 nodeData.role != schema.RoleType.desktop) { | |
| 984 logging.WARNING(String(nodeData.id) + | |
| 985 ' is not in the cache and not the new root.'); | |
| 986 lastError.set('automation', | |
| 987 'Bad update received on automation tree', | |
| 988 null, | |
| 989 chrome); | |
| 990 return false; | |
| 991 } | |
| 992 // |this| is an AutomationRootNodeImpl; retrieve the | |
| 993 // AutomationRootNode instance instead. | |
| 994 node = this.wrapper; | |
| 995 didUpdateRoot = true; | |
| 996 updateState.newNodes[this.id] = this.wrapper; | |
| 997 } | |
| 998 this.setData_(node, nodeData); | |
| 999 | |
| 1000 // TODO(aboxhall): send onChanged event? | |
| 1001 logging.CHECK(node); | |
| 1002 if (!this.deleteOldChildren_(node, nodeData.childIds)) { | |
| 1003 if (didUpdateRoot) { | |
| 1004 this.invalidate_(this.wrapper); | |
| 1005 } | |
| 1006 return false; | |
| 1007 } | |
| 1008 var nodeImpl = privates(node).impl; | |
| 1009 | |
| 1010 var success = this.createNewChildren_(node, | |
| 1011 nodeData.childIds, | |
| 1012 updateState); | |
| 1013 nodeImpl.childIds = nodeData.childIds; | |
| 1014 this.axNodeDataCache_[nodeImpl.id] = node; | |
| 1015 | |
| 1016 return success; | |
| 1017 } | |
| 1018 }; | 754 }; |
| 1019 | 755 |
| 1020 | |
| 1021 var AutomationNode = utils.expose('AutomationNode', | 756 var AutomationNode = utils.expose('AutomationNode', |
| 1022 AutomationNodeImpl, | 757 AutomationNodeImpl, |
| 1023 { functions: ['doDefault', | 758 { functions: ['doDefault', |
| 1024 'find', | 759 'find', |
| 1025 'findAll', | 760 'findAll', |
| 1026 'focus', | 761 'focus', |
| 1027 'makeVisible', | 762 'makeVisible', |
| 1028 'matches', | 763 'matches', |
| 1029 'setSelection', | 764 'setSelection', |
| 1030 'showContextMenu', | 765 'showContextMenu', |
| 1031 'addEventListener', | 766 'addEventListener', |
| 1032 'removeEventListener', | 767 'removeEventListener', |
| 1033 'domQuerySelector', | 768 'domQuerySelector', |
| 1034 'toString' ], | 769 'toString' ], |
| 1035 readonly: ['parent', | 770 readonly: publicAttributes.concat( |
| 771 ['parent', |
| 1036 'firstChild', | 772 'firstChild', |
| 1037 'lastChild', | 773 'lastChild', |
| 1038 'children', | 774 'children', |
| 1039 'previousSibling', | 775 'previousSibling', |
| 1040 'nextSibling', | 776 'nextSibling', |
| 1041 'isRootNode', | 777 'isRootNode', |
| 1042 'role', | 778 'role', |
| 1043 'state', | 779 'state', |
| 1044 'location', | 780 'location', |
| 1045 'attributes', | |
| 1046 'indexInParent', | 781 'indexInParent', |
| 1047 'root'] }); | 782 'root']) }); |
| 1048 | 783 |
| 1049 var AutomationRootNode = utils.expose('AutomationRootNode', | 784 var AutomationRootNode = utils.expose('AutomationRootNode', |
| 1050 AutomationRootNodeImpl, | 785 AutomationRootNodeImpl, |
| 1051 { superclass: AutomationNode }); | 786 { superclass: AutomationNode }); |
| 1052 | 787 |
| 788 AutomationRootNode.get = function(treeID) { |
| 789 return AutomationRootNodeImpl.get(treeID); |
| 790 } |
| 791 |
| 792 AutomationRootNode.getOrCreate = function(treeID) { |
| 793 return AutomationRootNodeImpl.getOrCreate(treeID); |
| 794 } |
| 795 |
| 796 AutomationRootNode.destroy = function(treeID) { |
| 797 AutomationRootNodeImpl.destroy(treeID); |
| 798 } |
| 799 |
| 1053 exports.AutomationNode = AutomationNode; | 800 exports.AutomationNode = AutomationNode; |
| 1054 exports.AutomationRootNode = AutomationRootNode; | 801 exports.AutomationRootNode = AutomationRootNode; |
| OLD | NEW |