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 automationInternal = | |
6 require('binding').Binding.create('automationInternal').generate(); | |
5 var utils = require('utils'); | 7 var utils = require('utils'); |
6 | 8 |
7 /** | 9 /** |
8 * A single node in the Automation tree. | 10 * A single node in the Automation tree. |
9 * @param {AutomationTree} owner The owning tree. | 11 * @param {AutomationTree} owner The owning tree. |
10 * @constructor | 12 * @constructor |
11 */ | 13 */ |
12 var AutomationNodeImpl = function(owner) { | 14 var AutomationNodeImpl = function(owner) { |
13 this.owner = owner; | 15 this.owner = owner; |
14 this.child_ids = []; | 16 this.child_ids = []; |
15 | |
16 this.attributes = {}; | 17 this.attributes = {}; |
18 this.listeners = {}; | |
17 }; | 19 }; |
18 | 20 |
19 AutomationNodeImpl.prototype = { | 21 AutomationNodeImpl.prototype = { |
20 parent: function() { | 22 parent: function() { |
21 return this.owner.get(this.parent_id); | 23 return this.owner.get(this.parent_id); |
22 }, | 24 }, |
23 | 25 |
24 firstChild: function() { | 26 firstChild: function() { |
25 var node = this.owner.get(this.child_ids[0]); | 27 var node = this.owner.get(this.child_ids[0]); |
26 return node; | 28 return node; |
(...skipping 18 matching lines...) Expand all Loading... | |
45 return parent.children()[this.index_in_parent - 1]; | 47 return parent.children()[this.index_in_parent - 1]; |
46 return undefined; | 48 return undefined; |
47 }, | 49 }, |
48 | 50 |
49 nextSibling: function() { | 51 nextSibling: function() { |
50 var parent = this.parent(); | 52 var parent = this.parent(); |
51 if (parent && this.index_in_parent < parent.children().length) | 53 if (parent && this.index_in_parent < parent.children().length) |
52 return parent.children()[this.index_in_parent + 1]; | 54 return parent.children()[this.index_in_parent + 1]; |
53 return undefined; | 55 return undefined; |
54 }, | 56 }, |
57 | |
58 doDefault: function() { | |
59 this.performAction_('doDefault'); | |
60 }, | |
not at google - send to devlin
2014/04/02 21:52:14
indent -= 2
David Tseng
2014/04/03 01:27:41
Done.
| |
61 | |
62 focus: function() { | |
63 this.performAction_('focus'); | |
64 }, | |
65 | |
66 makeVisible: function() { | |
67 this.performAction_('makeVisible'); | |
68 }, | |
69 | |
70 setSelection: function(startIndex, endIndex) { | |
71 this.performAction_('setSelection', | |
72 {start_index: startIndex, end_index: endIndex}); | |
73 }, | |
74 | |
75 addEventListener: function(eventType, callback, capture) { | |
76 this.removeEventListener(eventType, callback); | |
77 if (!this.listeners[eventType]) | |
78 this.listeners[eventType] = []; | |
79 this.listeners[eventType].push([callback, capture]); | |
80 }, | |
81 | |
82 // TODO(dtseng/aboxhall): Check this impl against spec. | |
not at google - send to devlin
2014/04/02 21:52:14
maybe this is too hacky, and I wish you could just
aboxhall
2014/04/02 22:01:15
That won't work: note that we plan to implement ca
not at google - send to devlin
2014/04/02 22:09:40
Ok.
I hope that eventually you can pull that out
David Tseng
2014/04/02 22:14:56
That's sort of what I think we had in mind; this c
| |
83 removeEventListener: function(eventType, callback) { | |
84 if (this.listeners[eventType]) { | |
85 var listeners = this.listeners[eventType]; | |
86 for (var i = 0; i < listeners.length; i++) { | |
87 if (callback === listeners[i][0]) | |
88 listeners.splice(i, 1); | |
89 } | |
90 } | |
91 }, | |
92 | |
93 notifyEventListeners: function(eventType) { | |
94 var listeners = this.listeners[eventType]; | |
95 if (!listeners) | |
96 return; | |
97 // TODO(dtseng/aboxhall): Implement capture/bubble. | |
98 for (var i = 0; i < listeners.length; i++) | |
99 listeners[i][0](); | |
100 }, | |
101 | |
102 performAction_: function(actionType, opt_args) { | |
103 // Not yet initialized. | |
104 if (!this.owner.processId || | |
105 !this.owner.routingId || | |
106 !this.wrapper.id) | |
107 return; | |
108 automationInternal.performAction(this.owner.processId, | |
109 this.owner.routingId, | |
110 this.wrapper.id, | |
111 actionType, | |
112 opt_args ? opt_args : {}); | |
113 }, | |
55 }; | 114 }; |
56 | 115 |
57 | |
58 var AutomationNode = utils.expose('AutomationNode', | 116 var AutomationNode = utils.expose('AutomationNode', |
59 AutomationNodeImpl, | 117 AutomationNodeImpl, |
60 ['parent', | 118 ['parent', |
61 'firstChild', | 119 'firstChild', |
62 'lastChild', | 120 'lastChild', |
63 'children', | 121 'children', |
64 'previousSibling', | 122 'previousSibling', |
65 'nextSibling']); | 123 'nextSibling', |
124 'doDefault', | |
125 'focus', | |
126 'makeVisible', | |
127 'setSelection', | |
128 'addEventListener', | |
129 'removeEventListener']); | |
66 exports.AutomationNode = AutomationNode; | 130 exports.AutomationNode = AutomationNode; |
OLD | NEW |