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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/automation_util.js

Issue 617323002: Revert of Fix ChromeVox Next compile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Created 6 years, 2 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
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 /** 5 /**
6 * @fileoverview ChromeVox utilities for the automation extension API. 6 * @fileoverview ChromeVox utilities for the automation extension API.
7 */ 7 */
8 8
9 goog.provide('cvox2.AutomationPredicates'); 9 goog.provide('cvox2.AutomationPredicates');
10 goog.provide('cvox2.AutomationUtil'); 10 goog.provide('cvox2.AutomationUtil');
11 goog.provide('cvox2.Dir'); 11 goog.provide('cvox2.Dir');
12 12
13 /** 13 /**
14 * @constructor 14 * @constructor
15 */ 15 */
16 cvox2.AutomationPredicates = function() {}; 16 cvox2.AutomationPredicates = function() {};
17 17
18 /** 18 /**
19 * Constructs a predicate given a role. 19 * Constructs a predicate given a role.
20 * @param {string} role 20 * @param {string} role
21 * @return {function(chrome.automation.AutomationNode) : boolean} 21 * @return {function(AutomationNode) : boolean}
22 */ 22 */
23 cvox2.AutomationPredicates.makeRolePredicate = function(role) { 23 cvox2.AutomationPredicates.makeRolePredicate = function(role) {
24 return function(node) { 24 return function(node) {
25 return node.role == role; 25 return node.role == role;
26 }; 26 };
27 }; 27 };
28 28
29 /** @type {function(chrome.automation.AutomationNode) : boolean} */ 29 /** @type {function(AutomationNode) : boolean} */
30 cvox2.AutomationPredicates.heading = 30 cvox2.AutomationPredicates.heading =
31 cvox2.AutomationPredicates.makeRolePredicate('heading'); 31 cvox2.AutomationPredicates.makeRolePredicate(
32 /** @type {function(chrome.automation.AutomationNode) : boolean} */ 32 chrome.automation.RoleType.heading);
33 /** @type {function(AutomationNode) : boolean} */
33 cvox2.AutomationPredicates.inlineTextBox = 34 cvox2.AutomationPredicates.inlineTextBox =
34 cvox2.AutomationPredicates.makeRolePredicate('inlineTextBox'); 35 cvox2.AutomationPredicates.makeRolePredicate(
35 /** @type {function(chrome.automation.AutomationNode) : boolean} */ 36 chrome.automation.RoleType.inlineTextBox);
37 /** @type {function(AutomationNode) : boolean} */
36 cvox2.AutomationPredicates.link = 38 cvox2.AutomationPredicates.link =
37 cvox2.AutomationPredicates.makeRolePredicate('link'); 39 cvox2.AutomationPredicates.makeRolePredicate(
40 chrome.automation.RoleType.link);
38 41
39 /** 42 /**
40 * Possible directions to perform tree traversals. 43 * Possible directions to perform tree traversals.
41 * @enum {string} 44 * @enum {string}
42 */ 45 */
43 cvox2.Dir = { 46 cvox2.Dir = {
44 // Search from left to right. 47 // Search from left to right.
45 FORWARD: 'forward', 48 FORWARD: 'forward',
46 49
47 // Search from right to left. 50 // Search from right to left.
48 BACKWARD: 'backward' 51 BACKWARD: 'backward'
49 }; 52 };
50 53
51 /** 54 /**
52 * @constructor 55 * @constructor
53 */ 56 */
54 cvox2.AutomationUtil = function() {}; 57 cvox2.AutomationUtil = function() {};
55 58
56 /** 59 /**
57 * Find a node in subtree of |cur| satisfying |pred| using pre-order traversal. 60 * Find a node in subtree of |cur| satisfying |pred| using pre-order traversal.
58 * @param {chrome.automation.AutomationNode} cur Node to begin the search from. 61 * @param {AutomationNode} cur Node to begin the search from.
59 * @param {cvox2.Dir} dir 62 * @param {cvox2.Dir} dir
60 * @param {function(chrome.automation.AutomationNode) : boolean} pred A 63 * @param {function(AutomationNode) : boolean} pred A predicate to apply to a
61 * predicate to apply to a candidate node. 64 * candidate node.
62 * @return {chrome.automation.AutomationNode} 65 * @return {AutomationNode}
63 */ 66 */
64 cvox2.AutomationUtil.findNodePre = function(cur, dir, pred) { 67 cvox2.AutomationUtil.findNodePre = function(cur, dir, pred) {
65 if (pred(cur)) 68 if (pred(cur))
66 return cur; 69 return cur;
67 70
68 var child = dir == cvox2.Dir.BACKWARD ? cur.lastChild() : cur.firstChild(); 71 var child = dir == cvox2.Dir.BACKWARD ? cur.lastChild() : cur.firstChild();
69 while (child) { 72 while (child) {
70 var ret = cvox2.AutomationUtil.findNodePre(child, dir, pred); 73 var ret = cvox2.AutomationUtil.findNodePre(child, dir, pred);
71 if (ret) 74 if (ret)
72 return ret; 75 return ret;
73 child = dir == cvox2.Dir.BACKWARD ? 76 child = dir == cvox2.Dir.BACKWARD ?
74 child.previousSibling() : child.nextSibling(); 77 child.previousSibling() : child.nextSibling();
75 } 78 }
76 }; 79 };
77 80
78 /** 81 /**
79 * Find a node in subtree of |cur| satisfying |pred| using post-order traversal. 82 * Find a node in subtree of |cur| satisfying |pred| using post-order traversal.
80 * @param {chrome.automation.AutomationNode} cur Node to begin the search from. 83 * @param {AutomationNode} cur Node to begin the search from.
81 * @param {cvox2.Dir} dir 84 * @param {cvox2.Dir} dir
82 * @param {function(chrome.automation.AutomationNode) : boolean} pred A 85 * @param {function(AutomationNode) : boolean} pred A predicate to apply to a
83 * predicate to apply to a candidate node. 86 * candidate node.
84 * @return {chrome.automation.AutomationNode} 87 * @return {AutomationNode}
85 */ 88 */
86 cvox2.AutomationUtil.findNodePost = function(cur, dir, pred) { 89 cvox2.AutomationUtil.findNodePost = function(cur, dir, pred) {
87 var child = dir == cvox2.Dir.BACKWARD ? cur.lastChild() : cur.firstChild(); 90 var child = dir == cvox2.Dir.BACKWARD ? cur.lastChild() : cur.firstChild();
88 while (child) { 91 while (child) {
89 var ret = cvox2.AutomationUtil.findNodePost(child, dir, pred); 92 var ret = cvox2.AutomationUtil.findNodePost(child, dir, pred);
90 if (ret) 93 if (ret)
91 return ret; 94 return ret;
92 child = dir == cvox2.Dir.BACKWARD ? 95 child = dir == cvox2.Dir.BACKWARD ?
93 child.previousSibling() : child.nextSibling(); 96 child.previousSibling() : child.nextSibling();
94 } 97 }
95 98
96 if (pred(cur)) 99 if (pred(cur))
97 return cur; 100 return cur;
98 }; 101 };
99 102
100 /** 103 /**
101 * Find the next node in the given direction that is either an immediate 104 * Find the next node in the given direction that is either an immediate
102 * sibling or a sibling of an ancestor. 105 * sibling or a sibling of an ancestor.
103 * @param {chrome.automation.AutomationNode} cur Node to start search from. 106 * @param {AutomationNode} cur Node to start search from.
104 * @param {cvox2.Dir} dir 107 * @param {cvox2.Dir} dir
105 * @return {chrome.automation.AutomationNode} 108 * @return {AutomationNode}
106 */ 109 */
107 cvox2.AutomationUtil.findNextSubtree = function(cur, dir) { 110 cvox2.AutomationUtil.findNextSubtree = function(cur, dir) {
108 while (cur) { 111 while (cur) {
109 var next = dir == cvox2.Dir.BACKWARD ? 112 var next = dir == cvox2.Dir.BACKWARD ?
110 cur.previousSibling() : cur.nextSibling(); 113 cur.previousSibling() : cur.nextSibling();
111 if (next) 114 if (next)
112 return next; 115 return next;
113 116
114 cur = cur.parent(); 117 cur = cur.parent();
115 } 118 }
116 }; 119 };
117 120
118 /** 121 /**
119 * Find the next node in the given direction in depth first order. 122 * Find the next node in the given direction in depth first order.
120 * @param {chrome.automation.AutomationNode} cur Node to begin the search from. 123 * @param {AutomationNode} cur Node to begin the search from.
121 * @param {cvox2.Dir} dir 124 * @param {cvox2.Dir} dir
122 * @param {function(chrome.automation.AutomationNode) : boolean} pred A 125 * @param {function(AutomationNode) : boolean} pred A predicate to apply to a
123 * predicate to apply to a candidate node. 126 * candidate node.
124 * @return {chrome.automation.AutomationNode} 127 * @return {AutomationNode}
125 */ 128 */
126 cvox2.AutomationUtil.findNextNode = function(cur, dir, pred) { 129 cvox2.AutomationUtil.findNextNode = function(cur, dir, pred) {
127 var next = cur; 130 var next = cur;
128 do { 131 do {
129 if (!(next = cvox2.AutomationUtil.findNextSubtree(cur, dir))) 132 if (!(next = cvox2.AutomationUtil.findNextSubtree(cur, dir)))
130 return null; 133 return null;
131 cur = next; 134 cur = next;
132 next = cvox2.AutomationUtil.findNodePre(next, dir, pred); 135 next = cvox2.AutomationUtil.findNodePre(next, dir, pred);
133 } while (!next); 136 } while (!next);
134 return next; 137 return next;
135 }; 138 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698