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 goog.provide('AutomationUtil.Dir'); | 10 goog.provide('AutomationUtil.Dir'); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 else | 150 else |
151 after = candidate; | 151 after = candidate; |
152 return satisfied; | 152 return satisfied; |
153 }); | 153 }); |
154 return opt_options.before ? before : after; | 154 return opt_options.before ? before : after; |
155 }; | 155 }; |
156 | 156 |
157 /** | 157 /** |
158 * Returns an array containing ancestors of node starting at root down to node. | 158 * Returns an array containing ancestors of node starting at root down to node. |
159 * @param {!AutomationNode} node | 159 * @param {!AutomationNode} node |
160 * @return {!Array.<AutomationNode>} | 160 * @return {!Array<AutomationNode>} |
161 */ | 161 */ |
162 AutomationUtil.getAncestors = function(node) { | 162 AutomationUtil.getAncestors = function(node) { |
163 var ret = []; | 163 var ret = []; |
164 var candidate = node; | 164 var candidate = node; |
165 while (candidate) { | 165 while (candidate) { |
166 ret.push(candidate); | 166 ret.push(candidate); |
167 candidate = candidate.parent; | 167 candidate = candidate.parent; |
168 } | 168 } |
169 return ret.reverse(); | 169 return ret.reverse(); |
170 }; | 170 }; |
171 | 171 |
172 /** | 172 /** |
173 * Gets the first index where the two input arrays differ. Returns -1 if they | 173 * Gets the first index where the two input arrays differ. Returns -1 if they |
174 * do not. | 174 * do not. |
175 * @param {!Array.<AutomationNode>} ancestorsA | 175 * @param {!Array<AutomationNode>} ancestorsA |
176 * @param {!Array.<AutomationNode>} ancestorsB | 176 * @param {!Array<AutomationNode>} ancestorsB |
177 * @return {number} | 177 * @return {number} |
178 */ | 178 */ |
179 AutomationUtil.getDivergence = function(ancestorsA, ancestorsB) { | 179 AutomationUtil.getDivergence = function(ancestorsA, ancestorsB) { |
180 for (var i = 0; i < ancestorsA.length; i++) { | 180 for (var i = 0; i < ancestorsA.length; i++) { |
181 if (ancestorsA[i] !== ancestorsB[i]) | 181 if (ancestorsA[i] !== ancestorsB[i]) |
182 return i; | 182 return i; |
183 } | 183 } |
184 if (ancestorsA.length == ancestorsB.length) | 184 if (ancestorsA.length == ancestorsB.length) |
185 return -1; | 185 return -1; |
186 return ancestorsA.length; | 186 return ancestorsA.length; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 // One of the nodes is an ancestor of the other. Don't distinguish and just | 221 // One of the nodes is an ancestor of the other. Don't distinguish and just |
222 // consider it Dir.FORWARD. | 222 // consider it Dir.FORWARD. |
223 if (!divA || !divB || divA.parent === nodeB || divB.parent === nodeA) | 223 if (!divA || !divB || divA.parent === nodeB || divB.parent === nodeA) |
224 return Dir.FORWARD; | 224 return Dir.FORWARD; |
225 | 225 |
226 return divA.indexInParent <= divB.indexInParent ? Dir.FORWARD : Dir.BACKWARD; | 226 return divA.indexInParent <= divB.indexInParent ? Dir.FORWARD : Dir.BACKWARD; |
227 }; | 227 }; |
228 | 228 |
229 }); // goog.scope | 229 }); // goog.scope |
OLD | NEW |