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

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

Issue 2943193002: Run clang-format on .js files in c/b/r/chromeos/chromevox (Closed)
Patch Set: Created 3 years, 6 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('AutomationUtil'); 9 goog.provide('AutomationUtil');
10 10
(...skipping 24 matching lines...) Expand all
35 return null; 35 return null;
36 36
37 if (pred(cur) && !AutomationPredicate.shouldIgnoreNode(cur)) 37 if (pred(cur) && !AutomationPredicate.shouldIgnoreNode(cur))
38 return cur; 38 return cur;
39 39
40 var child = dir == Dir.BACKWARD ? cur.lastChild : cur.firstChild; 40 var child = dir == Dir.BACKWARD ? cur.lastChild : cur.firstChild;
41 while (child) { 41 while (child) {
42 var ret = AutomationUtil.findNodePre(child, dir, pred); 42 var ret = AutomationUtil.findNodePre(child, dir, pred);
43 if (ret) 43 if (ret)
44 return ret; 44 return ret;
45 child = dir == Dir.BACKWARD ? 45 child = dir == Dir.BACKWARD ? child.previousSibling : child.nextSibling;
46 child.previousSibling : child.nextSibling;
47 } 46 }
48 return null; 47 return null;
49 }; 48 };
50 49
51 /** 50 /**
52 * Find a node in subtree of |cur| satisfying |pred| using post-order traversal. 51 * Find a node in subtree of |cur| satisfying |pred| using post-order traversal.
53 * @param {AutomationNode} cur Node to begin the search from. 52 * @param {AutomationNode} cur Node to begin the search from.
54 * @param {Dir} dir 53 * @param {Dir} dir
55 * @param {AutomationPredicate.Unary} pred A predicate to apply 54 * @param {AutomationPredicate.Unary} pred A predicate to apply
56 * to a candidate node. 55 * to a candidate node.
57 * @return {AutomationNode} 56 * @return {AutomationNode}
58 */ 57 */
59 AutomationUtil.findNodePost = function(cur, dir, pred) { 58 AutomationUtil.findNodePost = function(cur, dir, pred) {
60 if (!cur) 59 if (!cur)
61 return null; 60 return null;
62 61
63 var child = dir == Dir.BACKWARD ? cur.lastChild : cur.firstChild; 62 var child = dir == Dir.BACKWARD ? cur.lastChild : cur.firstChild;
64 while (child) { 63 while (child) {
65 var ret = AutomationUtil.findNodePost(child, dir, pred); 64 var ret = AutomationUtil.findNodePost(child, dir, pred);
66 if (ret) 65 if (ret)
67 return ret; 66 return ret;
68 child = dir == Dir.BACKWARD ? 67 child = dir == Dir.BACKWARD ? child.previousSibling : child.nextSibling;
69 child.previousSibling : child.nextSibling;
70 } 68 }
71 69
72 if (pred(cur) && !AutomationPredicate.shouldIgnoreNode(cur)) 70 if (pred(cur) && !AutomationPredicate.shouldIgnoreNode(cur))
73 return cur; 71 return cur;
74 72
75 return null; 73 return null;
76 }; 74 };
77 75
78 /** 76 /**
79 * Find the next node in the given direction in depth first order. 77 * Find the next node in the given direction in depth first order.
(...skipping 14 matching lines...) Expand all
94 * By default: 92 * By default:
95 * the root predicate ges set to |AutomationPredicate.root|. 93 * the root predicate ges set to |AutomationPredicate.root|.
96 * |skipInitialSubtree| is false if |cur| is a container or matches 94 * |skipInitialSubtree| is false if |cur| is a container or matches
97 * |pred|. This alleviates the caller from syncing forwards. 95 * |pred|. This alleviates the caller from syncing forwards.
98 * Leaves are nodes matched by |prred| which are not also containers. 96 * Leaves are nodes matched by |prred| which are not also containers.
99 * This takes care of syncing backwards. 97 * This takes care of syncing backwards.
100 * @return {AutomationNode} 98 * @return {AutomationNode}
101 */ 99 */
102 AutomationUtil.findNextNode = function(cur, dir, pred, opt_restrictions) { 100 AutomationUtil.findNextNode = function(cur, dir, pred, opt_restrictions) {
103 var restrictions = {}; 101 var restrictions = {};
104 opt_restrictions = opt_restrictions || {leaf: undefined, 102 opt_restrictions = opt_restrictions || {
105 root: undefined, 103 leaf: undefined,
106 visit: undefined, 104 root: undefined,
107 skipInitialSubtree: !AutomationPredicate.container(cur) && pred(cur)}; 105 visit: undefined,
106 skipInitialSubtree: !AutomationPredicate.container(cur) && pred(cur)
107 };
108 108
109 restrictions.root = opt_restrictions.root || AutomationPredicate.root; 109 restrictions.root = opt_restrictions.root || AutomationPredicate.root;
110 restrictions.leaf = opt_restrictions.leaf || function(node) { 110 restrictions.leaf = opt_restrictions.leaf || function(node) {
111 // Treat nodes matched by |pred| as leaves except for containers. 111 // Treat nodes matched by |pred| as leaves except for containers.
112 return !AutomationPredicate.container(node) && pred(node); 112 return !AutomationPredicate.container(node) && pred(node);
113 }; 113 };
114 114
115 restrictions.skipInitialSubtree = opt_restrictions.skipInitialSubtree; 115 restrictions.skipInitialSubtree = opt_restrictions.skipInitialSubtree;
116 restrictions.skipInitialAncestry = opt_restrictions.skipInitialAncestry; 116 restrictions.skipInitialAncestry = opt_restrictions.skipInitialAncestry;
117 117
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 /** 281 /**
282 * Gets a top level root. 282 * Gets a top level root.
283 * @param {!AutomationNode} node 283 * @param {!AutomationNode} node
284 * @return {AutomationNode} 284 * @return {AutomationNode}
285 */ 285 */
286 AutomationUtil.getTopLevelRoot = function(node) { 286 AutomationUtil.getTopLevelRoot = function(node) {
287 var root = node.root; 287 var root = node.root;
288 if (!root || root.role == RoleType.DESKTOP) 288 if (!root || root.role == RoleType.DESKTOP)
289 return null; 289 return null;
290 290
291 while (root && 291 while (root && root.parent && root.parent.root &&
292 root.parent && 292 root.parent.root.role != RoleType.DESKTOP) {
293 root.parent.root &&
294 root.parent.root.role != RoleType.DESKTOP) {
295 root = root.parent.root; 293 root = root.parent.root;
296 } 294 }
297 return root; 295 return root;
298 }; 296 };
299 297
300 /** 298 /**
301 * @param {!AutomationNode} prevNode 299 * @param {!AutomationNode} prevNode
302 * @param {!AutomationNode} node 300 * @param {!AutomationNode} node
303 * @return {AutomationNode} 301 * @return {AutomationNode}
304 */ 302 */
(...skipping 16 matching lines...) Expand all
321 AutomationUtil.getText = function(node) { 319 AutomationUtil.getText = function(node) {
322 if (!node) 320 if (!node)
323 return ''; 321 return '';
324 322
325 if (node.role === RoleType.TEXT_FIELD) 323 if (node.role === RoleType.TEXT_FIELD)
326 return node.value || ''; 324 return node.value || '';
327 return node.name || ''; 325 return node.name || '';
328 }; 326 };
329 327
330 }); // goog.scope 328 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698