| 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 /** | 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return true; | 108 return true; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 var walker = new AutomationTreeWalker(cur, dir, restrictions); | 111 var walker = new AutomationTreeWalker(cur, dir, restrictions); |
| 112 return walker.next().node; | 112 return walker.next().node; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * Given nodes a_1, ..., a_n starting at |cur| in pre order traversal, apply | 116 * Given nodes a_1, ..., a_n starting at |cur| in pre order traversal, apply |
| 117 * |pred| to a_i and a_(i - 1) until |pred| is satisfied. Returns a_(i - 1) or | 117 * |pred| to a_i and a_(i - 1) until |pred| is satisfied. Returns a_(i - 1) or |
| 118 * a_i (depending on opt_options.before) or null if no match was found. | 118 * a_i (depending on opt_before) or null if no match was found. |
| 119 * @param {!AutomationNode} cur | 119 * @param {!AutomationNode} cur |
| 120 * @param {Dir} dir | 120 * @param {Dir} dir |
| 121 * @param {AutomationPredicate.Binary} pred | 121 * @param {AutomationPredicate.Binary} pred |
| 122 * @param {{filter: (AutomationPredicate.Unary|undefined), | 122 * @param {boolean=} opt_before True to return a_(i - 1); a_i otherwise. |
| 123 * before: boolean?}=} opt_options | 123 * Defaults to false. |
| 124 * filter - Filters which candidate nodes to consider. Defaults to leaf | |
| 125 * only. | |
| 126 * before - True to return a_(i - 1); a_i otherwise. Defaults to false. | |
| 127 * @return {AutomationNode} | 124 * @return {AutomationNode} |
| 128 */ | 125 */ |
| 129 AutomationUtil.findNodeUntil = function(cur, dir, pred, opt_options) { | 126 AutomationUtil.findNodeUntil = function(cur, dir, pred, opt_before) { |
| 130 opt_options = | 127 var before = cur; |
| 131 opt_options || {filter: AutomationPredicate.leaf, before: false}; | 128 var after = before; |
| 132 if (!opt_options.filter) | 129 do { |
| 133 opt_options.filter = AutomationPredicate.leaf; | 130 before = after; |
| 134 | 131 after = AutomationUtil.findNextNode(before, dir, AutomationPredicate.leaf); |
| 135 var before = null; | 132 } while (after && !pred(before, after)); |
| 136 var after = null; | 133 return opt_before ? before : after; |
| 137 var prev = cur; | |
| 138 AutomationUtil.findNextNode(cur, | |
| 139 dir, | |
| 140 function(candidate) { | |
| 141 if (!opt_options.filter(candidate)) | |
| 142 return false; | |
| 143 | |
| 144 var satisfied = pred(prev, candidate); | |
| 145 | |
| 146 prev = candidate; | |
| 147 if (!satisfied) | |
| 148 before = candidate; | |
| 149 else | |
| 150 after = candidate; | |
| 151 return satisfied; | |
| 152 }, | |
| 153 {leaf: AutomationPredicate.leaf, skipInitialSubtree: true}); | |
| 154 | |
| 155 return opt_options.before ? before : after; | |
| 156 }; | 134 }; |
| 157 | 135 |
| 158 /** | 136 /** |
| 159 * Returns an array containing ancestors of node starting at root down to node. | 137 * Returns an array containing ancestors of node starting at root down to node. |
| 160 * @param {!AutomationNode} node | 138 * @param {!AutomationNode} node |
| 161 * @return {!Array<AutomationNode>} | 139 * @return {!Array<AutomationNode>} |
| 162 */ | 140 */ |
| 163 AutomationUtil.getAncestors = function(node) { | 141 AutomationUtil.getAncestors = function(node) { |
| 164 var ret = []; | 142 var ret = []; |
| 165 var candidate = node; | 143 var candidate = node; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 a = a.parent.root; | 259 a = a.parent.root; |
| 282 | 260 |
| 283 b = b.root; | 261 b = b.root; |
| 284 while (b && b.parent && AutomationUtil.isInSameTree(b.parent, b)) | 262 while (b && b.parent && AutomationUtil.isInSameTree(b.parent, b)) |
| 285 b = b.parent.root; | 263 b = b.parent.root; |
| 286 | 264 |
| 287 return a == b; | 265 return a == b; |
| 288 }; | 266 }; |
| 289 | 267 |
| 290 }); // goog.scope | 268 }); // goog.scope |
| OLD | NEW |