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 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 makeVisible: function() { | 88 makeVisible: function() { |
89 this.performAction_('makeVisible'); | 89 this.performAction_('makeVisible'); |
90 }, | 90 }, |
91 | 91 |
92 setSelection: function(startIndex, endIndex) { | 92 setSelection: function(startIndex, endIndex) { |
93 this.performAction_('setSelection', | 93 this.performAction_('setSelection', |
94 { startIndex: startIndex, | 94 { startIndex: startIndex, |
95 endIndex: endIndex }); | 95 endIndex: endIndex }); |
96 }, | 96 }, |
97 | 97 |
| 98 querySelector: function(selector, callback) { |
| 99 automationInternal.querySelector( |
| 100 { processID: this.rootImpl.processID, |
| 101 routingID: this.rootImpl.routingID, |
| 102 automationNodeID: this.id, |
| 103 selector: selector }, |
| 104 this.querySelectorCallback_.bind(this, callback)); |
| 105 }, |
| 106 |
98 addEventListener: function(eventType, callback, capture) { | 107 addEventListener: function(eventType, callback, capture) { |
99 this.removeEventListener(eventType, callback); | 108 this.removeEventListener(eventType, callback); |
100 if (!this.listeners[eventType]) | 109 if (!this.listeners[eventType]) |
101 this.listeners[eventType] = []; | 110 this.listeners[eventType] = []; |
102 this.listeners[eventType].push({callback: callback, capture: !!capture}); | 111 this.listeners[eventType].push({callback: callback, capture: !!capture}); |
103 }, | 112 }, |
104 | 113 |
105 // TODO(dtseng/aboxhall): Check this impl against spec. | 114 // TODO(dtseng/aboxhall): Check this impl against spec. |
106 removeEventListener: function(eventType, callback) { | 115 removeEventListener: function(eventType, callback) { |
107 if (this.listeners[eventType]) { | 116 if (this.listeners[eventType]) { |
(...skipping 21 matching lines...) Expand all Loading... |
129 // - bubbling: starting from the target's parent, going back up to the root. | 138 // - bubbling: starting from the target's parent, going back up to the root. |
130 // At any stage, a listener may call stopPropagation() on the event, which | 139 // At any stage, a listener may call stopPropagation() on the event, which |
131 // will immediately stop event propagation through this path. | 140 // will immediately stop event propagation through this path. |
132 if (this.dispatchEventAtCapturing_(event, path)) { | 141 if (this.dispatchEventAtCapturing_(event, path)) { |
133 if (this.dispatchEventAtTargeting_(event, path)) | 142 if (this.dispatchEventAtTargeting_(event, path)) |
134 this.dispatchEventAtBubbling_(event, path); | 143 this.dispatchEventAtBubbling_(event, path); |
135 } | 144 } |
136 }, | 145 }, |
137 | 146 |
138 toString: function() { | 147 toString: function() { |
139 return 'node id=' + this.id + | 148 var impl = privates(this).impl; |
| 149 if (!impl) |
| 150 impl = this; |
| 151 return 'node id=' + impl.id + |
140 ' role=' + this.role + | 152 ' role=' + this.role + |
141 ' state=' + $JSON.stringify(this.state) + | 153 ' state=' + $JSON.stringify(this.state) + |
142 ' parentID=' + this.parentID + | 154 ' parentID=' + impl.parentID + |
143 ' childIds=' + $JSON.stringify(this.childIds) + | 155 ' childIds=' + $JSON.stringify(impl.childIds) + |
144 ' attributes=' + $JSON.stringify(this.attributes); | 156 ' attributes=' + $JSON.stringify(this.attributes); |
145 }, | 157 }, |
146 | 158 |
147 dispatchEventAtCapturing_: function(event, path) { | 159 dispatchEventAtCapturing_: function(event, path) { |
148 privates(event).impl.eventPhase = Event.CAPTURING_PHASE; | 160 privates(event).impl.eventPhase = Event.CAPTURING_PHASE; |
149 for (var i = path.length - 1; i >= 0; i--) { | 161 for (var i = path.length - 1; i >= 0; i--) { |
150 this.fireEventListeners_(path[i], event); | 162 this.fireEventListeners_(path[i], event); |
151 if (privates(event).impl.propagationStopped) | 163 if (privates(event).impl.propagationStopped) |
152 return false; | 164 return false; |
153 } | 165 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 if (!IsInteractPermitted()) { | 216 if (!IsInteractPermitted()) { |
205 throw new Error(actionType + ' requires {"desktop": true} or' + | 217 throw new Error(actionType + ' requires {"desktop": true} or' + |
206 ' {"interact": true} in the "automation" manifest key.'); | 218 ' {"interact": true} in the "automation" manifest key.'); |
207 } | 219 } |
208 | 220 |
209 automationInternal.performAction({ processID: this.rootImpl.processID, | 221 automationInternal.performAction({ processID: this.rootImpl.processID, |
210 routingID: this.rootImpl.routingID, | 222 routingID: this.rootImpl.routingID, |
211 automationNodeID: this.id, | 223 automationNodeID: this.id, |
212 actionType: actionType }, | 224 actionType: actionType }, |
213 opt_args || {}); | 225 opt_args || {}); |
| 226 }, |
| 227 |
| 228 querySelectorCallback_: function(userCallback, resultAutomationNodeID) { |
| 229 // resultAutomationNodeID could be zero or undefined or (unlikely) null; |
| 230 // they all amount to the same thing here, which is that no node was |
| 231 // returned. |
| 232 if (!resultAutomationNodeID) { |
| 233 userCallback(null); |
| 234 return; |
| 235 } |
| 236 var resultNode = this.rootImpl.get(resultAutomationNodeID); |
| 237 if (!resultNode) { |
| 238 logging.WARNING('Query selector result not in tree: ' + |
| 239 resultAutomationNodeID); |
| 240 userCallback(null); |
| 241 } |
| 242 userCallback(resultNode); |
214 } | 243 } |
215 }; | 244 }; |
216 | 245 |
217 // Maps an attribute to its default value in an invalidated node. | 246 // Maps an attribute to its default value in an invalidated node. |
218 // These attributes are taken directly from the Automation idl. | 247 // These attributes are taken directly from the Automation idl. |
219 var AutomationAttributeDefaults = { | 248 var AutomationAttributeDefaults = { |
220 'id': -1, | 249 'id': -1, |
221 'role': '', | 250 'role': '', |
222 'state': {}, | 251 'state': {}, |
223 'location': { left: 0, top: 0, width: 0, height: 0 } | 252 'location': { left: 0, top: 0, width: 0, height: 0 } |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 'firstChild', | 621 'firstChild', |
593 'lastChild', | 622 'lastChild', |
594 'children', | 623 'children', |
595 'previousSibling', | 624 'previousSibling', |
596 'nextSibling', | 625 'nextSibling', |
597 'doDefault', | 626 'doDefault', |
598 'focus', | 627 'focus', |
599 'makeVisible', | 628 'makeVisible', |
600 'setSelection', | 629 'setSelection', |
601 'addEventListener', | 630 'addEventListener', |
602 'removeEventListener'], | 631 'removeEventListener', |
| 632 'querySelector', |
| 633 'toString'], |
603 readonly: ['isRootNode', | 634 readonly: ['isRootNode', |
604 'role', | 635 'role', |
605 'state', | 636 'state', |
606 'location', | 637 'location', |
607 'attributes', | 638 'attributes', |
608 'root'] }); | 639 'root'] }); |
609 | 640 |
610 var AutomationRootNode = utils.expose('AutomationRootNode', | 641 var AutomationRootNode = utils.expose('AutomationRootNode', |
611 AutomationRootNodeImpl, | 642 AutomationRootNodeImpl, |
612 { superclass: AutomationNode, | 643 { superclass: AutomationNode, |
613 functions: ['load'], | 644 functions: ['load', |
| 645 'toString'], |
614 readonly: ['loaded'] }); | 646 readonly: ['loaded'] }); |
615 | 647 |
616 exports.AutomationNode = AutomationNode; | 648 exports.AutomationNode = AutomationNode; |
617 exports.AutomationRootNode = AutomationRootNode; | 649 exports.AutomationRootNode = AutomationRootNode; |
OLD | NEW |