| 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 exceptionHandler = require('uncaught_exception_handler'); | 8 var exceptionHandler = require('uncaught_exception_handler'); |
| 9 var IsInteractPermitted = | 9 var IsInteractPermitted = |
| 10 requireNative('automationInternal').IsInteractPermitted; | 10 requireNative('automationInternal').IsInteractPermitted; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 */ | 187 */ |
| 188 var GetHtmlAttribute = requireNative('automationInternal').GetHtmlAttribute; | 188 var GetHtmlAttribute = requireNative('automationInternal').GetHtmlAttribute; |
| 189 | 189 |
| 190 var lastError = require('lastError'); | 190 var lastError = require('lastError'); |
| 191 var logging = requireNative('logging'); | 191 var logging = requireNative('logging'); |
| 192 var schema = requireNative('automationInternal').GetSchemaAdditions(); | 192 var schema = requireNative('automationInternal').GetSchemaAdditions(); |
| 193 var utils = require('utils'); | 193 var utils = require('utils'); |
| 194 | 194 |
| 195 /** | 195 /** |
| 196 * A single node in the Automation tree. | 196 * A single node in the Automation tree. |
| 197 * |
| 197 * @param {AutomationRootNodeImpl} root The root of the tree. | 198 * @param {AutomationRootNodeImpl} root The root of the tree. |
| 198 * @constructor | 199 * @constructor |
| 199 */ | 200 */ |
| 200 function AutomationNodeImpl(root) { | 201 function AutomationNodeImpl(root) { |
| 201 this.rootImpl = root; | 202 this.rootImpl = root; |
| 202 // Public attributes. No actual data gets set on this object. | 203 this.listeners = {__proto__: null}; |
| 203 this.listeners = {}; | |
| 204 } | 204 } |
| 205 $Object.setPrototypeOf(AutomationNodeImpl, null); |
| 205 | 206 |
| 206 AutomationNodeImpl.prototype = { | 207 AutomationNodeImpl.prototype = { |
| 208 __proto__: null, |
| 207 treeID: -1, | 209 treeID: -1, |
| 208 id: -1, | 210 id: -1, |
| 209 role: '', | |
| 210 state: { busy: true }, | |
| 211 isRootNode: false, | 211 isRootNode: false, |
| 212 | 212 |
| 213 get root() { | 213 get root() { |
| 214 return this.rootImpl.wrapper; | 214 return this.rootImpl.wrapper; |
| 215 }, | 215 }, |
| 216 | 216 |
| 217 get parent() { | 217 get parent() { |
| 218 if (this.hostNode_) | 218 if (this.hostNode_) |
| 219 return this.hostNode_; | 219 return this.hostNode_; |
| 220 var parentID = GetParentID(this.treeID, this.id); | 220 var parentID = GetParentID(this.treeID, this.id); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 get children() { | 269 get children() { |
| 270 if (this.childTree) | 270 if (this.childTree) |
| 271 return [this.childTree]; | 271 return [this.childTree]; |
| 272 | 272 |
| 273 var children = []; | 273 var children = []; |
| 274 var count = GetChildCount(this.treeID, this.id); | 274 var count = GetChildCount(this.treeID, this.id); |
| 275 for (var i = 0; i < count; ++i) { | 275 for (var i = 0; i < count; ++i) { |
| 276 var childID = GetChildIDAtIndex(this.treeID, this.id, i); | 276 var childID = GetChildIDAtIndex(this.treeID, this.id, i); |
| 277 var child = this.rootImpl.get(childID); | 277 var child = this.rootImpl.get(childID); |
| 278 children.push(child); | 278 $Array.push(children, child); |
| 279 } | 279 } |
| 280 return children; | 280 return children; |
| 281 }, | 281 }, |
| 282 | 282 |
| 283 get previousSibling() { | 283 get previousSibling() { |
| 284 var parent = this.parent; | 284 var parent = this.parent; |
| 285 var indexInParent = GetIndexInParent(this.treeID, this.id); | 285 var indexInParent = GetIndexInParent(this.treeID, this.id); |
| 286 if (parent && indexInParent > 0) | 286 if (parent && indexInParent > 0) |
| 287 return parent.children[indexInParent - 1]; | 287 return parent.children[indexInParent - 1]; |
| 288 return undefined; | 288 return undefined; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 319 | 319 |
| 320 showContextMenu: function() { | 320 showContextMenu: function() { |
| 321 this.performAction_('showContextMenu'); | 321 this.performAction_('showContextMenu'); |
| 322 }, | 322 }, |
| 323 | 323 |
| 324 domQuerySelector: function(selector, callback) { | 324 domQuerySelector: function(selector, callback) { |
| 325 automationInternal.querySelector( | 325 automationInternal.querySelector( |
| 326 { treeID: this.rootImpl.treeID, | 326 { treeID: this.rootImpl.treeID, |
| 327 automationNodeID: this.id, | 327 automationNodeID: this.id, |
| 328 selector: selector }, | 328 selector: selector }, |
| 329 this.domQuerySelectorCallback_.bind(this, callback)); | 329 $Function.bind(this.domQuerySelectorCallback_, this, callback)); |
| 330 }, | 330 }, |
| 331 | 331 |
| 332 find: function(params) { | 332 find: function(params) { |
| 333 return this.findInternal_(params); | 333 return this.findInternal_(params); |
| 334 }, | 334 }, |
| 335 | 335 |
| 336 findAll: function(params) { | 336 findAll: function(params) { |
| 337 return this.findInternal_(params, []); | 337 return this.findInternal_(params, []); |
| 338 }, | 338 }, |
| 339 | 339 |
| 340 matches: function(params) { | 340 matches: function(params) { |
| 341 return this.matchInternal_(params); | 341 return this.matchInternal_(params); |
| 342 }, | 342 }, |
| 343 | 343 |
| 344 addEventListener: function(eventType, callback, capture) { | 344 addEventListener: function(eventType, callback, capture) { |
| 345 this.removeEventListener(eventType, callback); | 345 this.removeEventListener(eventType, callback); |
| 346 if (!this.listeners[eventType]) | 346 if (!this.listeners[eventType]) |
| 347 this.listeners[eventType] = []; | 347 this.listeners[eventType] = []; |
| 348 this.listeners[eventType].push({callback: callback, capture: !!capture}); | 348 $Array.push(this.listeners[eventType], { |
| 349 __proto__: null, |
| 350 callback: callback, |
| 351 capture: !!capture, |
| 352 }); |
| 349 }, | 353 }, |
| 350 | 354 |
| 351 // TODO(dtseng/aboxhall): Check this impl against spec. | 355 // TODO(dtseng/aboxhall): Check this impl against spec. |
| 352 removeEventListener: function(eventType, callback) { | 356 removeEventListener: function(eventType, callback) { |
| 353 if (this.listeners[eventType]) { | 357 if (this.listeners[eventType]) { |
| 354 var listeners = this.listeners[eventType]; | 358 var listeners = this.listeners[eventType]; |
| 355 for (var i = 0; i < listeners.length; i++) { | 359 for (var i = 0; i < listeners.length; i++) { |
| 356 if (callback === listeners[i].callback) | 360 if (callback === listeners[i].callback) |
| 357 listeners.splice(i, 1); | 361 $Array.splice(listeners, i, 1); |
| 358 } | 362 } |
| 359 } | 363 } |
| 360 }, | 364 }, |
| 361 | 365 |
| 362 toJSON: function() { | 366 toJSON: function() { |
| 363 return { treeID: this.treeID, | 367 return { treeID: this.treeID, |
| 364 id: this.id, | 368 id: this.id, |
| 365 role: this.role, | 369 role: this.role, |
| 366 attributes: this.attributes }; | 370 attributes: this.attributes }; |
| 367 }, | 371 }, |
| 368 | 372 |
| 369 dispatchEvent: function(eventType) { | 373 dispatchEvent: function(eventType) { |
| 370 var path = []; | 374 var path = []; |
| 371 var parent = this.parent; | 375 var parent = this.parent; |
| 372 while (parent) { | 376 while (parent) { |
| 373 path.push(parent); | 377 $Array.push(path, parent); |
| 374 parent = parent.parent; | 378 parent = parent.parent; |
| 375 } | 379 } |
| 376 var event = new AutomationEvent(eventType, this.wrapper); | 380 var event = new AutomationEvent(eventType, this.wrapper); |
| 377 | 381 |
| 378 // Dispatch the event through the propagation path in three phases: | 382 // Dispatch the event through the propagation path in three phases: |
| 379 // - capturing: starting from the root and going down to the target's parent | 383 // - capturing: starting from the root and going down to the target's parent |
| 380 // - targeting: dispatching the event on the target itself | 384 // - targeting: dispatching the event on the target itself |
| 381 // - bubbling: starting from the target's parent, going back up to the root. | 385 // - bubbling: starting from the target's parent, going back up to the root. |
| 382 // At any stage, a listener may call stopPropagation() on the event, which | 386 // At any stage, a listener may call stopPropagation() on the event, which |
| 383 // will immediately stop event propagation through this path. | 387 // will immediately stop event propagation through this path. |
| 384 if (this.dispatchEventAtCapturing_(event, path)) { | 388 if (this.dispatchEventAtCapturing_(event, path)) { |
| 385 if (this.dispatchEventAtTargeting_(event, path)) | 389 if (this.dispatchEventAtTargeting_(event, path)) |
| 386 this.dispatchEventAtBubbling_(event, path); | 390 this.dispatchEventAtBubbling_(event, path); |
| 387 } | 391 } |
| 388 }, | 392 }, |
| 389 | 393 |
| 390 toString: function() { | 394 toString: function() { |
| 391 var parentID = GetParentID(this.treeID, this.id); | 395 var parentID = GetParentID(this.treeID, this.id); |
| 392 var childTreeID = GetIntAttribute(this.treeID, this.id, 'childTreeId'); | 396 var childTreeID = GetIntAttribute(this.treeID, this.id, 'childTreeId'); |
| 393 var count = GetChildCount(this.treeID, this.id); | 397 var count = GetChildCount(this.treeID, this.id); |
| 394 var childIDs = []; | 398 var childIDs = []; |
| 395 for (var i = 0; i < count; ++i) { | 399 for (var i = 0; i < count; ++i) { |
| 396 var childID = GetChildIDAtIndex(this.treeID, this.id, i); | 400 var childID = GetChildIDAtIndex(this.treeID, this.id, i); |
| 397 childIDs.push(childID); | 401 $Array.push(childIDs, childID); |
| 398 } | 402 } |
| 399 | 403 |
| 400 var result = 'node id=' + this.id + | 404 var result = 'node id=' + this.id + |
| 401 ' role=' + this.role + | 405 ' role=' + this.role + |
| 402 ' state=' + $JSON.stringify(this.state) + | 406 ' state=' + $JSON.stringify(this.state) + |
| 403 ' parentID=' + parentID + | 407 ' parentID=' + parentID + |
| 404 ' childIds=' + $JSON.stringify(childIDs); | 408 ' childIds=' + $JSON.stringify(childIDs); |
| 405 if (this.hostNode_) { | 409 if (this.hostNode_) { |
| 406 var hostNodeImpl = privates(this.hostNode_).impl; | 410 var hostNodeImpl = privates(this.hostNode_).impl; |
| 407 result += ' host treeID=' + hostNodeImpl.treeID + | 411 result += ' host treeID=' + hostNodeImpl.treeID + |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 userCallback(null); | 497 userCallback(null); |
| 494 } | 498 } |
| 495 userCallback(resultNode); | 499 userCallback(resultNode); |
| 496 }, | 500 }, |
| 497 | 501 |
| 498 findInternal_: function(params, opt_results) { | 502 findInternal_: function(params, opt_results) { |
| 499 var result = null; | 503 var result = null; |
| 500 this.forAllDescendants_(function(node) { | 504 this.forAllDescendants_(function(node) { |
| 501 if (privates(node).impl.matchInternal_(params)) { | 505 if (privates(node).impl.matchInternal_(params)) { |
| 502 if (opt_results) | 506 if (opt_results) |
| 503 opt_results.push(node); | 507 $Array.push(opt_results, node); |
| 504 else | 508 else |
| 505 result = node; | 509 result = node; |
| 506 return !opt_results; | 510 return !opt_results; |
| 507 } | 511 } |
| 508 }); | 512 }); |
| 509 if (opt_results) | 513 if (opt_results) |
| 510 return opt_results; | 514 return opt_results; |
| 511 return result; | 515 return result; |
| 512 }, | 516 }, |
| 513 | 517 |
| 514 /** | 518 /** |
| 515 * Executes a closure for all of this node's descendants, in pre-order. | 519 * Executes a closure for all of this node's descendants, in pre-order. |
| 516 * Early-outs if the closure returns true. | 520 * Early-outs if the closure returns true. |
| 517 * @param {Function(AutomationNode):boolean} closure Closure to be executed | 521 * @param {Function(AutomationNode):boolean} closure Closure to be executed |
| 518 * for each node. Return true to early-out the traversal. | 522 * for each node. Return true to early-out the traversal. |
| 519 */ | 523 */ |
| 520 forAllDescendants_: function(closure) { | 524 forAllDescendants_: function(closure) { |
| 521 var stack = this.wrapper.children.reverse(); | 525 var stack = $Array.reverse(this.wrapper.children); |
| 522 while (stack.length > 0) { | 526 while (stack.length > 0) { |
| 523 var node = stack.pop(); | 527 var node = $Array.pop(stack); |
| 524 if (closure(node)) | 528 if (closure(node)) |
| 525 return; | 529 return; |
| 526 | 530 |
| 527 var children = node.children; | 531 var children = node.children; |
| 528 for (var i = children.length - 1; i >= 0; i--) | 532 for (var i = children.length - 1; i >= 0; i--) |
| 529 stack.push(children[i]); | 533 $Array.push(stack, children[i]); |
| 530 } | 534 } |
| 531 }, | 535 }, |
| 532 | 536 |
| 533 matchInternal_: function(params) { | 537 matchInternal_: function(params) { |
| 534 if (Object.keys(params).length == 0) | 538 if ($Object.keys(params).length === 0) |
| 535 return false; | 539 return false; |
| 536 | 540 |
| 537 if ('role' in params && this.role != params.role) | 541 if ('role' in params && this.role != params.role) |
| 538 return false; | 542 return false; |
| 539 | 543 |
| 540 if ('state' in params) { | 544 if ('state' in params) { |
| 541 for (var state in params.state) { | 545 for (var state in params.state) { |
| 542 if (params.state[state] != (state in this.state)) | 546 if (params.state[state] != (state in this.state)) |
| 543 return false; | 547 return false; |
| 544 } | 548 } |
| 545 } | 549 } |
| 546 if ('attributes' in params) { | 550 if ('attributes' in params) { |
| 547 for (var attribute in params.attributes) { | 551 for (var attribute in params.attributes) { |
| 548 var attrValue = params.attributes[attribute]; | 552 var attrValue = params.attributes[attribute]; |
| 549 if (typeof attrValue != 'object') { | 553 if (typeof attrValue != 'object') { |
| 550 if (this[attribute] !== attrValue) | 554 if (this[attribute] !== attrValue) |
| 551 return false; | 555 return false; |
| 552 } else if (attrValue instanceof RegExp) { | 556 } else if (attrValue instanceof $RegExp.self) { |
| 553 if (typeof this[attribute] != 'string') | 557 if (typeof this[attribute] != 'string') |
| 554 return false; | 558 return false; |
| 555 if (!attrValue.test(this[attribute])) | 559 if (!attrValue.test(this[attribute])) |
| 556 return false; | 560 return false; |
| 557 } else { | 561 } else { |
| 558 // TODO(aboxhall): handle intlist case. | 562 // TODO(aboxhall): handle intlist case. |
| 559 return false; | 563 return false; |
| 560 } | 564 } |
| 561 } | 565 } |
| 562 } | 566 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 'valueForRange', | 657 'valueForRange', |
| 654 'minValueForRange', | 658 'minValueForRange', |
| 655 'maxValueForRange', | 659 'maxValueForRange', |
| 656 'fontSize']; | 660 'fontSize']; |
| 657 | 661 |
| 658 var htmlAttributes = [ | 662 var htmlAttributes = [ |
| 659 ['type', 'inputType']]; | 663 ['type', 'inputType']]; |
| 660 | 664 |
| 661 var publicAttributes = []; | 665 var publicAttributes = []; |
| 662 | 666 |
| 663 stringAttributes.forEach(function (attributeName) { | 667 $Array.forEach(stringAttributes, function(attributeName) { |
| 664 publicAttributes.push(attributeName); | 668 $Array.push(publicAttributes, attributeName); |
| 665 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { | 669 $Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 670 __proto__: null, |
| 666 get: function() { | 671 get: function() { |
| 667 return GetStringAttribute(this.treeID, this.id, attributeName); | 672 return GetStringAttribute(this.treeID, this.id, attributeName); |
| 668 } | 673 } |
| 669 }); | 674 }); |
| 670 }); | 675 }); |
| 671 | 676 |
| 672 boolAttributes.forEach(function (attributeName) { | 677 $Array.forEach(boolAttributes, function(attributeName) { |
| 673 publicAttributes.push(attributeName); | 678 $Array.push(publicAttributes, attributeName); |
| 674 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { | 679 $Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 680 __proto__: null, |
| 675 get: function() { | 681 get: function() { |
| 676 return GetBoolAttribute(this.treeID, this.id, attributeName); | 682 return GetBoolAttribute(this.treeID, this.id, attributeName); |
| 677 } | 683 } |
| 678 }); | 684 }); |
| 679 }); | 685 }); |
| 680 | 686 |
| 681 intAttributes.forEach(function (attributeName) { | 687 $Array.forEach(intAttributes, function(attributeName) { |
| 682 publicAttributes.push(attributeName); | 688 $Array.push(publicAttributes, attributeName); |
| 683 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { | 689 $Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 690 __proto__: null, |
| 684 get: function() { | 691 get: function() { |
| 685 return GetIntAttribute(this.treeID, this.id, attributeName); | 692 return GetIntAttribute(this.treeID, this.id, attributeName); |
| 686 } | 693 } |
| 687 }); | 694 }); |
| 688 }); | 695 }); |
| 689 | 696 |
| 690 nodeRefAttributes.forEach(function (params) { | 697 $Array.forEach(nodeRefAttributes, function(params) { |
| 691 var srcAttributeName = params[0]; | 698 var srcAttributeName = params[0]; |
| 692 var dstAttributeName = params[1]; | 699 var dstAttributeName = params[1]; |
| 693 publicAttributes.push(dstAttributeName); | 700 $Array.push(publicAttributes, dstAttributeName); |
| 694 Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { | 701 $Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { |
| 702 __proto__: null, |
| 695 get: function() { | 703 get: function() { |
| 696 var id = GetIntAttribute(this.treeID, this.id, srcAttributeName); | 704 var id = GetIntAttribute(this.treeID, this.id, srcAttributeName); |
| 697 if (id) | 705 if (id) |
| 698 return this.rootImpl.get(id); | 706 return this.rootImpl.get(id); |
| 699 else | 707 else |
| 700 return undefined; | 708 return undefined; |
| 701 } | 709 } |
| 702 }); | 710 }); |
| 703 }); | 711 }); |
| 704 | 712 |
| 705 intListAttributes.forEach(function (attributeName) { | 713 $Array.forEach(intListAttributes, function(attributeName) { |
| 706 publicAttributes.push(attributeName); | 714 $Array.push(publicAttributes, attributeName); |
| 707 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { | 715 $Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 716 __proto__: null, |
| 708 get: function() { | 717 get: function() { |
| 709 return GetIntListAttribute(this.treeID, this.id, attributeName); | 718 return GetIntListAttribute(this.treeID, this.id, attributeName); |
| 710 } | 719 } |
| 711 }); | 720 }); |
| 712 }); | 721 }); |
| 713 | 722 |
| 714 nodeRefListAttributes.forEach(function (params) { | 723 $Array.forEach(nodeRefListAttributes, function(params) { |
| 715 var srcAttributeName = params[0]; | 724 var srcAttributeName = params[0]; |
| 716 var dstAttributeName = params[1]; | 725 var dstAttributeName = params[1]; |
| 717 publicAttributes.push(dstAttributeName); | 726 $Array.push(publicAttributes, dstAttributeName); |
| 718 Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { | 727 $Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { |
| 728 __proto__: null, |
| 719 get: function() { | 729 get: function() { |
| 720 var ids = GetIntListAttribute(this.treeID, this.id, srcAttributeName); | 730 var ids = GetIntListAttribute(this.treeID, this.id, srcAttributeName); |
| 721 if (!ids) | 731 if (!ids) |
| 722 return undefined; | 732 return undefined; |
| 723 var result = []; | 733 var result = []; |
| 724 for (var i = 0; i < ids.length; ++i) { | 734 for (var i = 0; i < ids.length; ++i) { |
| 725 var node = this.rootImpl.get(ids[i]); | 735 var node = this.rootImpl.get(ids[i]); |
| 726 if (node) | 736 if (node) |
| 727 result.push(node); | 737 $Array.push(result, node); |
| 728 } | 738 } |
| 729 return result; | 739 return result; |
| 730 } | 740 } |
| 731 }); | 741 }); |
| 732 }); | 742 }); |
| 733 | 743 |
| 734 floatAttributes.forEach(function (attributeName) { | 744 $Array.forEach(floatAttributes, function(attributeName) { |
| 735 publicAttributes.push(attributeName); | 745 $Array.push(publicAttributes, attributeName); |
| 736 Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { | 746 $Object.defineProperty(AutomationNodeImpl.prototype, attributeName, { |
| 747 __proto__: null, |
| 737 get: function() { | 748 get: function() { |
| 738 return GetFloatAttribute(this.treeID, this.id, attributeName); | 749 return GetFloatAttribute(this.treeID, this.id, attributeName); |
| 739 } | 750 } |
| 740 }); | 751 }); |
| 741 }); | 752 }); |
| 742 | 753 |
| 743 htmlAttributes.forEach(function (params) { | 754 $Array.forEach(htmlAttributes, function(params) { |
| 744 var srcAttributeName = params[0]; | 755 var srcAttributeName = params[0]; |
| 745 var dstAttributeName = params[1]; | 756 var dstAttributeName = params[1]; |
| 746 publicAttributes.push(dstAttributeName); | 757 $Array.push(publicAttributes, dstAttributeName); |
| 747 Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { | 758 $Object.defineProperty(AutomationNodeImpl.prototype, dstAttributeName, { |
| 759 __proto__: null, |
| 748 get: function() { | 760 get: function() { |
| 749 return GetHtmlAttribute(this.treeID, this.id, srcAttributeName); | 761 return GetHtmlAttribute(this.treeID, this.id, srcAttributeName); |
| 750 } | 762 } |
| 751 }); | 763 }); |
| 752 }); | 764 }); |
| 753 | 765 |
| 754 /** | 766 /** |
| 755 * AutomationRootNode. | 767 * AutomationRootNode. |
| 756 * | 768 * |
| 757 * An AutomationRootNode is the javascript end of an AXTree living in the | 769 * An AutomationRootNode is the javascript end of an AXTree living in the |
| 758 * browser. AutomationRootNode handles unserializing incremental updates from | 770 * browser. AutomationRootNode handles unserializing incremental updates from |
| 759 * the source AXTree. Each update contains node data that form a complete tree | 771 * the source AXTree. Each update contains node data that form a complete tree |
| 760 * after applying the update. | 772 * after applying the update. |
| 761 * | 773 * |
| 762 * A brief note about ids used through this class. The source AXTree assigns | 774 * A brief note about ids used through this class. The source AXTree assigns |
| 763 * unique ids per node and we use these ids to build a hash to the actual | 775 * unique ids per node and we use these ids to build a hash to the actual |
| 764 * AutomationNode object. | 776 * AutomationNode object. |
| 765 * Thus, tree traversals amount to a lookup in our hash. | 777 * Thus, tree traversals amount to a lookup in our hash. |
| 766 * | 778 * |
| 767 * The tree itself is identified by the accessibility tree id of the | 779 * The tree itself is identified by the accessibility tree id of the |
| 768 * renderer widget host. | 780 * renderer widget host. |
| 769 * @constructor | 781 * @constructor |
| 770 */ | 782 */ |
| 771 function AutomationRootNodeImpl(treeID) { | 783 function AutomationRootNodeImpl(treeID) { |
| 772 AutomationNodeImpl.call(this, this); | 784 $Function.call(AutomationNodeImpl, this, this); |
| 773 this.treeID = treeID; | 785 this.treeID = treeID; |
| 774 this.axNodeDataCache_ = {}; | 786 this.axNodeDataCache_ = {__proto__: null}; |
| 775 } | 787 } |
| 788 $Object.setPrototypeOf(AutomationRootNodeImpl, null); |
| 776 | 789 |
| 777 AutomationRootNodeImpl.idToAutomationRootNode_ = {}; | 790 AutomationRootNodeImpl.idToAutomationRootNode_ = {__proto__: null}; |
| 778 | 791 |
| 779 AutomationRootNodeImpl.get = function(treeID) { | 792 AutomationRootNodeImpl.get = function(treeID) { |
| 780 var result = AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; | 793 var result = AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; |
| 781 return result || undefined; | 794 return result || undefined; |
| 782 } | 795 }; |
| 783 | 796 |
| 784 AutomationRootNodeImpl.getOrCreate = function(treeID) { | 797 AutomationRootNodeImpl.getOrCreate = function(treeID) { |
| 785 if (AutomationRootNodeImpl.idToAutomationRootNode_[treeID]) | 798 if (AutomationRootNodeImpl.idToAutomationRootNode_[treeID]) |
| 786 return AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; | 799 return AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; |
| 787 var result = new AutomationRootNode(treeID); | 800 var result = new AutomationRootNode(treeID); |
| 788 AutomationRootNodeImpl.idToAutomationRootNode_[treeID] = result; | 801 AutomationRootNodeImpl.idToAutomationRootNode_[treeID] = result; |
| 789 return result; | 802 return result; |
| 790 } | 803 }; |
| 791 | 804 |
| 792 AutomationRootNodeImpl.destroy = function(treeID) { | 805 AutomationRootNodeImpl.destroy = function(treeID) { |
| 793 delete AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; | 806 delete AutomationRootNodeImpl.idToAutomationRootNode_[treeID]; |
| 794 } | 807 }; |
| 795 | 808 |
| 796 AutomationRootNodeImpl.prototype = { | 809 AutomationRootNodeImpl.prototype = { |
| 797 __proto__: AutomationNodeImpl.prototype, | 810 __proto__: AutomationNodeImpl.prototype, |
| 798 | 811 |
| 799 /** | 812 /** |
| 800 * @type {boolean} | 813 * @type {boolean} |
| 801 */ | 814 */ |
| 802 isRootNode: true, | 815 isRootNode: true, |
| 803 | 816 |
| 804 /** | 817 /** |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 }, | 933 }, |
| 921 | 934 |
| 922 toString: function() { | 935 toString: function() { |
| 923 function toStringInternal(nodeImpl, indent) { | 936 function toStringInternal(nodeImpl, indent) { |
| 924 if (!nodeImpl) | 937 if (!nodeImpl) |
| 925 return ''; | 938 return ''; |
| 926 var output = ''; | 939 var output = ''; |
| 927 if (nodeImpl.isRootNode) | 940 if (nodeImpl.isRootNode) |
| 928 output += indent + 'tree id=' + nodeImpl.treeID + '\n'; | 941 output += indent + 'tree id=' + nodeImpl.treeID + '\n'; |
| 929 output += indent + | 942 output += indent + |
| 930 AutomationNodeImpl.prototype.toString.call(nodeImpl) + | 943 $Function.call(AutomationNodeImpl.prototype.toString, nodeImpl) + '\n'; |
| 931 '\n'; | |
| 932 indent += ' '; | 944 indent += ' '; |
| 933 var children = nodeImpl.children; | 945 var children = nodeImpl.children; |
| 934 for (var i = 0; i < children.length; ++i) | 946 for (var i = 0; i < children.length; ++i) |
| 935 output += toStringInternal(privates(children[i]).impl, indent); | 947 output += toStringInternal(privates(children[i]).impl, indent); |
| 936 return output; | 948 return output; |
| 937 } | 949 } |
| 938 return toStringInternal(this, ''); | 950 return toStringInternal(this, ''); |
| 939 }, | 951 }, |
| 940 }; | 952 }; |
| 941 | 953 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 'docLoadingProgress', | 998 'docLoadingProgress', |
| 987 'anchorObject', | 999 'anchorObject', |
| 988 'anchorOffset', | 1000 'anchorOffset', |
| 989 'focusObject', | 1001 'focusObject', |
| 990 'focusOffset', | 1002 'focusOffset', |
| 991 ], | 1003 ], |
| 992 }); | 1004 }); |
| 993 | 1005 |
| 994 AutomationRootNode.get = function(treeID) { | 1006 AutomationRootNode.get = function(treeID) { |
| 995 return AutomationRootNodeImpl.get(treeID); | 1007 return AutomationRootNodeImpl.get(treeID); |
| 996 } | 1008 }; |
| 997 | 1009 |
| 998 AutomationRootNode.getOrCreate = function(treeID) { | 1010 AutomationRootNode.getOrCreate = function(treeID) { |
| 999 return AutomationRootNodeImpl.getOrCreate(treeID); | 1011 return AutomationRootNodeImpl.getOrCreate(treeID); |
| 1000 } | 1012 }; |
| 1001 | 1013 |
| 1002 AutomationRootNode.destroy = function(treeID) { | 1014 AutomationRootNode.destroy = function(treeID) { |
| 1003 AutomationRootNodeImpl.destroy(treeID); | 1015 AutomationRootNodeImpl.destroy(treeID); |
| 1004 } | 1016 }; |
| 1005 | 1017 |
| 1006 exports.$set('AutomationNode', AutomationNode); | 1018 exports.$set('AutomationNode', AutomationNode); |
| 1007 exports.$set('AutomationRootNode', AutomationRootNode); | 1019 exports.$set('AutomationRootNode', AutomationRootNode); |
| OLD | NEW |