Chromium Code Reviews| 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 }, | |
| 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', [startIndex, endIndex]); | |
| 72 }, | |
| 73 | |
| 74 addEventListener: function(eventType, callback, capture) { | |
| 75 if (! this.listeners[eventType]) | |
|
dmazzoni
2014/04/01 17:05:25
Nit: no space after !
David Tseng
2014/04/01 21:27:15
Done.
| |
| 76 this.listeners[eventType] = []; | |
| 77 this.listeners[eventType].push([callback, capture]); | |
| 78 }, | |
| 79 | |
| 80 // TODO(dtseng/aboxhall): Implement. | |
| 81 removeEventListener: function(callback) { | |
|
dmazzoni
2014/04/01 17:05:25
Should this take eventType and capture as paramete
David Tseng
2014/04/01 21:27:15
Added as part of TODO. I'm not sure if we want to
| |
| 82 }, | |
| 83 | |
| 84 /* @private */ | |
| 85 performAction: function(actionType, opt_args) { | |
|
aboxhall
2014/04/01 17:49:51
Use performAction_ naming scheme for private metho
David Tseng
2014/04/01 21:27:15
Removed the private annotation and added the under
| |
| 86 // Not yet initialized. | |
|
dmazzoni
2014/04/01 17:05:25
Nit: indent
David Tseng
2014/04/01 21:27:15
Done.
| |
| 87 if (!this.owner.processId || | |
| 88 !this.owner.routingId || | |
| 89 !this.wrapper.id) | |
| 90 return; | |
| 91 automationInternal.performAction(this.owner.processId, | |
| 92 this.owner.routingId, | |
| 93 this.wrapper.id, | |
| 94 actionType, | |
| 95 opt_args); | |
| 96 }, | |
| 97 | |
| 98 /* @private */ | |
| 99 updateEventListeners: function(eventType) { | |
|
aboxhall
2014/04/01 17:49:51
notifyEventListeners_ ?
David Tseng
2014/04/01 21:27:15
Notify is fine. Actually not private though since
| |
| 100 var listeners = this.listeners[eventType]; | |
| 101 if (!listeners) | |
| 102 return; | |
| 103 // TODO(dtseng/aboxhall): Implement capture/bubble. | |
| 104 for (var i = 0; i < listeners.length; i++) { | |
| 105 var listener = listeners[i][0]; | |
| 106 listener(); | |
| 107 } | |
| 108 }, | |
| 55 }; | 109 }; |
| 56 | 110 |
| 57 | |
| 58 var AutomationNode = utils.expose('AutomationNode', | 111 var AutomationNode = utils.expose('AutomationNode', |
| 59 AutomationNodeImpl, | 112 AutomationNodeImpl, |
| 60 ['parent', | 113 ['parent', |
| 61 'firstChild', | 114 'firstChild', |
| 62 'lastChild', | 115 'lastChild', |
| 63 'children', | 116 'children', |
| 64 'previousSibling', | 117 'previousSibling', |
| 65 'nextSibling']); | 118 'nextSibling', |
| 119 'doDefault', | |
| 120 'focus', | |
| 121 'makeVisible', | |
| 122 'setSelection', | |
| 123 'addEventListener', | |
| 124 'removeEventListener']); | |
| 66 exports.AutomationNode = AutomationNode; | 125 exports.AutomationNode = AutomationNode; |
| OLD | NEW |