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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 var ancestorsB = AutomationUtil.getAncestors(nodeB); | 202 var ancestorsB = AutomationUtil.getAncestors(nodeB); |
203 var divergence = AutomationUtil.getDivergence(ancestorsA, ancestorsB); | 203 var divergence = AutomationUtil.getDivergence(ancestorsA, ancestorsB); |
204 | 204 |
205 // Default to Dir.FORWARD. | 205 // Default to Dir.FORWARD. |
206 if (divergence == -1) | 206 if (divergence == -1) |
207 return Dir.FORWARD; | 207 return Dir.FORWARD; |
208 | 208 |
209 var divA = ancestorsA[divergence]; | 209 var divA = ancestorsA[divergence]; |
210 var divB = ancestorsB[divergence]; | 210 var divB = ancestorsB[divergence]; |
211 | 211 |
212 // One of the nodes is an ancestor of the other. Don't distinguish and just | 212 // One of the nodes is an ancestor of the other. Order this relationship in |
213 // consider it Dir.FORWARD. | 213 // the same way dfs would. nodeA <= nodeB if nodeA is a descendant of |
214 if (!divA || !divB || divA.parent === nodeB || divB.parent === nodeA) | 214 // nodeB. nodeA > nodeB if nodeB is a descendant of nodeA. |
| 215 |
| 216 if (!divA) |
| 217 return Dir.FORWARD; |
| 218 if (!divB) |
| 219 return Dir.BACKWARD; |
| 220 if (divA.parent === nodeB) |
| 221 return Dir.BACKWARD; |
| 222 if (divB.parent === nodeA) |
215 return Dir.FORWARD; | 223 return Dir.FORWARD; |
216 | 224 |
217 return divA.indexInParent <= divB.indexInParent ? Dir.FORWARD : Dir.BACKWARD; | 225 return divA.indexInParent <= divB.indexInParent ? Dir.FORWARD : Dir.BACKWARD; |
218 }; | 226 }; |
219 | 227 |
220 /** | 228 /** |
221 * Determines whether the two given nodes come from the same tree source. | 229 * Determines whether the two given nodes come from the same tree source. |
222 * @param {AutomationNode} a | 230 * @param {AutomationNode} a |
223 * @param {AutomationNode} b | 231 * @param {AutomationNode} b |
224 * @return {boolean} | 232 * @return {boolean} |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 while (root && | 312 while (root && |
305 root.parent && | 313 root.parent && |
306 root.parent.root && | 314 root.parent.root && |
307 root.parent.root.role != RoleType.desktop) { | 315 root.parent.root.role != RoleType.desktop) { |
308 root = root.parent.root; | 316 root = root.parent.root; |
309 } | 317 } |
310 return root; | 318 return root; |
311 }; | 319 }; |
312 | 320 |
313 }); // goog.scope | 321 }); // goog.scope |
OLD | NEW |