| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 return -1; | 184 if (ancestorsA.length == ancestorsB.length) |
| 185 return -1; |
| 186 return ancestorsA.length; |
| 185 }; | 187 }; |
| 186 | 188 |
| 187 /** | 189 /** |
| 188 * Returns ancestors of |node| that are not also ancestors of |prevNode|. | 190 * Returns ancestors of |node| that are not also ancestors of |prevNode|. |
| 189 * @param {!AutomationNode} prevNode | 191 * @param {!AutomationNode} prevNode |
| 190 * @param {!AutomationNode} node | 192 * @param {!AutomationNode} node |
| 191 * @return {!Array<AutomationNode>} | 193 * @return {!Array<AutomationNode>} |
| 192 */ | 194 */ |
| 193 AutomationUtil.getUniqueAncestors = function(prevNode, node) { | 195 AutomationUtil.getUniqueAncestors = function(prevNode, node) { |
| 194 var prevAncestors = AutomationUtil.getAncestors(prevNode); | 196 var prevAncestors = AutomationUtil.getAncestors(prevNode); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 218 | 220 |
| 219 // 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 |
| 220 // consider it Dir.FORWARD. | 222 // consider it Dir.FORWARD. |
| 221 if (!divA || !divB || divA.parent === nodeB || divB.parent === nodeA) | 223 if (!divA || !divB || divA.parent === nodeB || divB.parent === nodeA) |
| 222 return Dir.FORWARD; | 224 return Dir.FORWARD; |
| 223 | 225 |
| 224 return divA.indexInParent <= divB.indexInParent ? Dir.FORWARD : Dir.BACKWARD; | 226 return divA.indexInParent <= divB.indexInParent ? Dir.FORWARD : Dir.BACKWARD; |
| 225 }; | 227 }; |
| 226 | 228 |
| 227 }); // goog.scope | 229 }); // goog.scope |
| OLD | NEW |