Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: chrome/renderer/resources/extensions/automation/automation_node.js

Issue 203753002: Implement actions for Automation API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable test on Mac. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.childIDs = [];
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.parentID);
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.childIDs[0]);
26 return node; 28 return node;
27 }, 29 },
28 30
29 lastChild: function() { 31 lastChild: function() {
30 var child_ids = this.child_ids; 32 var childIDs = this.childIDs;
31 var node = this.owner.get(child_ids[child_ids.length - 1]); 33 var node = this.owner.get(childIDs[childIDs.length - 1]);
32 return node; 34 return node;
33 }, 35 },
34 36
35 children: function() { 37 children: function() {
36 var children = []; 38 var children = [];
37 for (var i = 0, child_id; child_id = this.child_ids[i]; i++) 39 for (var i = 0, childID; childID = this.childIDs[i]; i++)
38 children.push(this.owner.get(child_id)); 40 children.push(this.owner.get(childID));
39 return children; 41 return children;
40 }, 42 },
41 43
42 previousSibling: function() { 44 previousSibling: function() {
43 var parent = this.parent(); 45 var parent = this.parent();
44 if (parent && this.index_in_parent > 0) 46 if (parent && this.indexInParent > 0)
45 return parent.children()[this.index_in_parent - 1]; 47 return parent.children()[this.indexInParent - 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.indexInParent < parent.children().length)
52 return parent.children()[this.index_in_parent + 1]; 54 return parent.children()[this.indexInParent + 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',
72 {startIndex: startIndex, endIndex: 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.
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({processID: this.owner.processID,
109 routingID: this.owner.routingID,
110 automationNodeID: this.wrapper.id,
111 actionType: actionType},
112 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;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698