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