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 if (resultAutomationNodeID == 0) { | |
230 userCallback(null); | |
231 return; | |
232 } | |
233 var resultNode = this.rootImpl.get(resultAutomationNodeID); | |
234 if (!resultNode) { | |
dmazzoni
2014/10/30 23:32:42
Do you want to return here? It looks like you're c
aboxhall
2014/10/31 20:32:22
I think that's WAI - they need to know that they d
| |
235 logging.WARNING('Query selector result not in tree: ' + | |
236 resultAutomationNodeID) | |
237 } | |
238 userCallback(resultNode); | |
214 } | 239 } |
215 }; | 240 }; |
216 | 241 |
217 // Maps an attribute to its default value in an invalidated node. | 242 // Maps an attribute to its default value in an invalidated node. |
218 // These attributes are taken directly from the Automation idl. | 243 // These attributes are taken directly from the Automation idl. |
219 var AutomationAttributeDefaults = { | 244 var AutomationAttributeDefaults = { |
220 'id': -1, | 245 'id': -1, |
221 'role': '', | 246 'role': '', |
222 'state': {}, | 247 'state': {}, |
223 'location': { left: 0, top: 0, width: 0, height: 0 } | 248 'location': { left: 0, top: 0, width: 0, height: 0 } |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 'firstChild', | 617 'firstChild', |
593 'lastChild', | 618 'lastChild', |
594 'children', | 619 'children', |
595 'previousSibling', | 620 'previousSibling', |
596 'nextSibling', | 621 'nextSibling', |
597 'doDefault', | 622 'doDefault', |
598 'focus', | 623 'focus', |
599 'makeVisible', | 624 'makeVisible', |
600 'setSelection', | 625 'setSelection', |
601 'addEventListener', | 626 'addEventListener', |
602 'removeEventListener'], | 627 'removeEventListener', |
628 'querySelector', | |
629 'toString'], | |
603 readonly: ['isRootNode', | 630 readonly: ['isRootNode', |
604 'role', | 631 'role', |
605 'state', | 632 'state', |
606 'location', | 633 'location', |
607 'attributes', | 634 'attributes', |
608 'root'] }); | 635 'root'] }); |
609 | 636 |
610 var AutomationRootNode = utils.expose('AutomationRootNode', | 637 var AutomationRootNode = utils.expose('AutomationRootNode', |
611 AutomationRootNodeImpl, | 638 AutomationRootNodeImpl, |
612 { superclass: AutomationNode, | 639 { superclass: AutomationNode, |
613 functions: ['load'], | 640 functions: ['load', |
641 'toString'], | |
614 readonly: ['loaded'] }); | 642 readonly: ['loaded'] }); |
615 | 643 |
616 exports.AutomationNode = AutomationNode; | 644 exports.AutomationNode = AutomationNode; |
617 exports.AutomationRootNode = AutomationRootNode; | 645 exports.AutomationRootNode = AutomationRootNode; |
OLD | NEW |