| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * @param {number} axTreeID The id of the accessibility tree. | 74 * @param {number} axTreeID The id of the accessibility tree. |
| 75 * @return {?string} The selection focus affinity. | 75 * @return {?string} The selection focus affinity. |
| 76 */ | 76 */ |
| 77 var GetFocusAffinity = requireNative('automationInternal').GetFocusAffinity; | 77 var GetFocusAffinity = requireNative('automationInternal').GetFocusAffinity; |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * @param {number} axTreeID The id of the accessibility tree. | 80 * @param {number} axTreeID The id of the accessibility tree. |
| 81 * @param {number} nodeID The id of a node. | 81 * @param {number} nodeID The id of a node. |
| 82 * @return {?number} The id of the node's parent, or undefined if it's the | 82 * @return {?Array<number>} An array containing the tree id and node id |
| 83 * of the node's parent, or undefined if it's the |
| 83 * root of its tree or if the tree or node wasn't found. | 84 * root of its tree or if the tree or node wasn't found. |
| 84 */ | 85 */ |
| 85 var GetParentID = requireNative('automationInternal').GetParentID; | 86 var GetParent = requireNative('automationInternal').GetParent; |
| 86 | 87 |
| 87 /** | 88 /** |
| 88 * @param {number} axTreeID The id of the accessibility tree. | 89 * @param {number} axTreeID The id of the accessibility tree. |
| 89 * @param {number} nodeID The id of a node. | 90 * @param {number} nodeID The id of a node. |
| 90 * @return {?number} The number of children of the node, or undefined if | 91 * @return {?number} The number of children of the node, or undefined if |
| 91 * the tree or node wasn't found. | 92 * the tree or node wasn't found. |
| 92 */ | 93 */ |
| 93 var GetChildCount = requireNative('automationInternal').GetChildCount; | 94 var GetChildCount = requireNative('automationInternal').GetChildCount; |
| 94 | 95 |
| 95 /** | 96 /** |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 var logging = requireNative('logging'); | 236 var logging = requireNative('logging'); |
| 236 var utils = require('utils'); | 237 var utils = require('utils'); |
| 237 | 238 |
| 238 /** | 239 /** |
| 239 * A single node in the Automation tree. | 240 * A single node in the Automation tree. |
| 240 * @param {AutomationRootNodeImpl} root The root of the tree. | 241 * @param {AutomationRootNodeImpl} root The root of the tree. |
| 241 * @constructor | 242 * @constructor |
| 242 */ | 243 */ |
| 243 function AutomationNodeImpl(root) { | 244 function AutomationNodeImpl(root) { |
| 244 this.rootImpl = root; | 245 this.rootImpl = root; |
| 245 this.hostNode_ = null; | |
| 246 this.listeners = {__proto__: null}; | 246 this.listeners = {__proto__: null}; |
| 247 } | 247 } |
| 248 | 248 |
| 249 AutomationNodeImpl.prototype = { | 249 AutomationNodeImpl.prototype = { |
| 250 __proto__: null, | 250 __proto__: null, |
| 251 treeID: -1, | 251 treeID: -1, |
| 252 id: -1, | 252 id: -1, |
| 253 isRootNode: false, | 253 isRootNode: false, |
| 254 | 254 |
| 255 detach: function() { | 255 detach: function() { |
| 256 this.rootImpl = null; | 256 this.rootImpl = null; |
| 257 this.hostNode_ = null; | |
| 258 this.listeners = {__proto__: null}; | 257 this.listeners = {__proto__: null}; |
| 259 }, | 258 }, |
| 260 | 259 |
| 261 get root() { | 260 get root() { |
| 262 return this.rootImpl && this.rootImpl.wrapper; | 261 return this.rootImpl && this.rootImpl.wrapper; |
| 263 }, | 262 }, |
| 264 | 263 |
| 265 get parent() { | 264 get parent() { |
| 266 if (!this.rootImpl) | 265 if (!this.rootImpl) |
| 267 return undefined; | 266 return undefined; |
| 268 if (this.hostNode_) | 267 var parentTreeIDAndNodeID = GetParent(this.treeID, this.id); |
| 269 return this.hostNode_; | 268 if (!parentTreeIDAndNodeID) |
| 270 var parentID = GetParentID(this.treeID, this.id); | 269 return undefined; |
| 271 return this.rootImpl.get(parentID); | 270 var parentTreeID = parentTreeIDAndNodeID[0]; |
| 271 var parentNodeID = parentTreeIDAndNodeID[1]; |
| 272 if (parentTreeID == this.treeID) |
| 273 return this.rootImpl.get(parentNodeID); |
| 274 var tree = AutomationRootNodeImpl.get(parentTreeID); |
| 275 if (!tree) |
| 276 return undefined; |
| 277 return tree.get(parentNodeID); |
| 272 }, | 278 }, |
| 273 | 279 |
| 274 get htmlAttributes() { | 280 get htmlAttributes() { |
| 275 return GetHtmlAttributes(this.treeID, this.id) || {}; | 281 return GetHtmlAttributes(this.treeID, this.id) || {}; |
| 276 }, | 282 }, |
| 277 | 283 |
| 278 get state() { | 284 get state() { |
| 279 return GetState(this.treeID, this.id) || {}; | 285 return GetState(this.treeID, this.id) || {}; |
| 280 }, | 286 }, |
| 281 | 287 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 // - bubbling: starting from the target's parent, going back up to the root. | 494 // - bubbling: starting from the target's parent, going back up to the root. |
| 489 // At any stage, a listener may call stopPropagation() on the event, which | 495 // At any stage, a listener may call stopPropagation() on the event, which |
| 490 // will immediately stop event propagation through this path. | 496 // will immediately stop event propagation through this path. |
| 491 if (this.dispatchEventAtCapturing_(event, path)) { | 497 if (this.dispatchEventAtCapturing_(event, path)) { |
| 492 if (this.dispatchEventAtTargeting_(event, path)) | 498 if (this.dispatchEventAtTargeting_(event, path)) |
| 493 this.dispatchEventAtBubbling_(event, path); | 499 this.dispatchEventAtBubbling_(event, path); |
| 494 } | 500 } |
| 495 }, | 501 }, |
| 496 | 502 |
| 497 toString: function() { | 503 toString: function() { |
| 498 var parentID = GetParentID(this.treeID, this.id); | |
| 499 var childTreeID = GetIntAttribute(this.treeID, this.id, 'childTreeId'); | 504 var childTreeID = GetIntAttribute(this.treeID, this.id, 'childTreeId'); |
| 500 var count = GetChildCount(this.treeID, this.id); | 505 var count = GetChildCount(this.treeID, this.id); |
| 501 var childIDs = []; | 506 var childIDs = []; |
| 502 for (var i = 0; i < count; ++i) { | 507 for (var i = 0; i < count; ++i) { |
| 503 var childID = GetChildIDAtIndex(this.treeID, this.id, i); | 508 var childID = GetChildIDAtIndex(this.treeID, this.id, i); |
| 504 $Array.push(childIDs, childID); | 509 $Array.push(childIDs, childID); |
| 505 } | 510 } |
| 506 | 511 |
| 507 var result = 'node id=' + this.id + | 512 var result = 'node id=' + this.id + |
| 508 ' role=' + this.role + | 513 ' role=' + this.role + |
| 509 ' state=' + $JSON.stringify(this.state) + | 514 ' state=' + $JSON.stringify(this.state) + |
| 510 ' parentID=' + parentID + | |
| 511 ' childIds=' + $JSON.stringify(childIDs); | 515 ' childIds=' + $JSON.stringify(childIDs); |
| 512 if (this.hostNode_) { | |
| 513 var hostNodeImpl = privates(this.hostNode_).impl; | |
| 514 result += ' host treeID=' + hostNodeImpl.treeID + | |
| 515 ' host nodeID=' + hostNodeImpl.id; | |
| 516 } | |
| 517 if (childTreeID) | 516 if (childTreeID) |
| 518 result += ' childTreeID=' + childTreeID; | 517 result += ' childTreeID=' + childTreeID; |
| 519 return result; | 518 return result; |
| 520 }, | 519 }, |
| 521 | 520 |
| 522 dispatchEventAtCapturing_: function(event, path) { | 521 dispatchEventAtCapturing_: function(event, path) { |
| 523 privates(event).impl.eventPhase = Event.CAPTURING_PHASE; | 522 privates(event).impl.eventPhase = Event.CAPTURING_PHASE; |
| 524 for (var i = path.length - 1; i >= 0; i--) { | 523 for (var i = path.length - 1; i >= 0; i--) { |
| 525 this.fireEventListeners_(path[i], event); | 524 this.fireEventListeners_(path[i], event); |
| 526 if (privates(event).impl.propagationStopped) | 525 if (privates(event).impl.propagationStopped) |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 * @type {boolean} | 906 * @type {boolean} |
| 908 */ | 907 */ |
| 909 isRootNode: true, | 908 isRootNode: true, |
| 910 | 909 |
| 911 /** | 910 /** |
| 912 * @type {number} | 911 * @type {number} |
| 913 */ | 912 */ |
| 914 treeID: -1, | 913 treeID: -1, |
| 915 | 914 |
| 916 /** | 915 /** |
| 917 * The parent of this node from a different tree. | |
| 918 * @type {?AutomationNode} | |
| 919 * @private | |
| 920 */ | |
| 921 hostNode_: null, | |
| 922 | |
| 923 /** | |
| 924 * A map from id to AutomationNode. | 916 * A map from id to AutomationNode. |
| 925 * @type {Object.<number, AutomationNode>} | 917 * @type {Object.<number, AutomationNode>} |
| 926 * @private | 918 * @private |
| 927 */ | 919 */ |
| 928 axNodeDataCache_: null, | 920 axNodeDataCache_: null, |
| 929 | 921 |
| 930 get id() { | 922 get id() { |
| 931 var result = GetRootID(this.treeID); | 923 var result = GetRootID(this.treeID); |
| 932 | 924 |
| 933 // Don't return undefined, because the id is often passed directly | 925 // Don't return undefined, because the id is often passed directly |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 delete this.axNodeDataCache_[id]; | 1015 delete this.axNodeDataCache_[id]; |
| 1024 }, | 1016 }, |
| 1025 | 1017 |
| 1026 destroy: function() { | 1018 destroy: function() { |
| 1027 this.dispatchEvent('destroyed', 'none'); | 1019 this.dispatchEvent('destroyed', 'none'); |
| 1028 for (var id in this.axNodeDataCache_) | 1020 for (var id in this.axNodeDataCache_) |
| 1029 this.remove(id); | 1021 this.remove(id); |
| 1030 this.detach(); | 1022 this.detach(); |
| 1031 }, | 1023 }, |
| 1032 | 1024 |
| 1033 setHostNode(hostNode) { | |
| 1034 this.hostNode_ = hostNode; | |
| 1035 }, | |
| 1036 | |
| 1037 onAccessibilityEvent: function(eventParams) { | 1025 onAccessibilityEvent: function(eventParams) { |
| 1038 var targetNode = this.get(eventParams.targetID); | 1026 var targetNode = this.get(eventParams.targetID); |
| 1039 if (targetNode) { | 1027 if (targetNode) { |
| 1040 var targetNodeImpl = privates(targetNode).impl; | 1028 var targetNodeImpl = privates(targetNode).impl; |
| 1041 targetNodeImpl.dispatchEvent( | 1029 targetNodeImpl.dispatchEvent( |
| 1042 eventParams.eventType, eventParams.eventFrom, | 1030 eventParams.eventType, eventParams.eventFrom, |
| 1043 eventParams.mouseX, eventParams.mouseY); | 1031 eventParams.mouseX, eventParams.mouseY); |
| 1044 } else { | 1032 } else { |
| 1045 logging.WARNING('Got ' + eventParams.eventType + | 1033 logging.WARNING('Got ' + eventParams.eventType + |
| 1046 ' event on unknown node: ' + eventParams.targetID + | 1034 ' event on unknown node: ' + eventParams.targetID + |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 utils.defineProperty(AutomationRootNode, 'getOrCreate', function(treeID) { | 1127 utils.defineProperty(AutomationRootNode, 'getOrCreate', function(treeID) { |
| 1140 return AutomationRootNodeImpl.getOrCreate(treeID); | 1128 return AutomationRootNodeImpl.getOrCreate(treeID); |
| 1141 }); | 1129 }); |
| 1142 | 1130 |
| 1143 utils.defineProperty(AutomationRootNode, 'destroy', function(treeID) { | 1131 utils.defineProperty(AutomationRootNode, 'destroy', function(treeID) { |
| 1144 AutomationRootNodeImpl.destroy(treeID); | 1132 AutomationRootNodeImpl.destroy(treeID); |
| 1145 }); | 1133 }); |
| 1146 | 1134 |
| 1147 exports.$set('AutomationNode', AutomationNode); | 1135 exports.$set('AutomationNode', AutomationNode); |
| 1148 exports.$set('AutomationRootNode', AutomationRootNode); | 1136 exports.$set('AutomationRootNode', AutomationRootNode); |
| OLD | NEW |