| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 AutomationUtil.isInSameTree = function(a, b) { | 234 AutomationUtil.isInSameTree = function(a, b) { |
| 235 if (!a || !b) | 235 if (!a || !b) |
| 236 return true; | 236 return true; |
| 237 | 237 |
| 238 // Given two non-desktop roots, consider them in the "same" tree. | 238 // Given two non-desktop roots, consider them in the "same" tree. |
| 239 return a.root === b.root || | 239 return a.root === b.root || |
| 240 (a.root.role == b.root.role && a.root.role == RoleType.rootWebArea); | 240 (a.root.role == b.root.role && a.root.role == RoleType.rootWebArea); |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 /** | 243 /** |
| 244 * Determines whether the two given nodes come from the same webpage. | |
| 245 * @param {AutomationNode} a | |
| 246 * @param {AutomationNode} b | |
| 247 * @return {boolean} | |
| 248 */ | |
| 249 AutomationUtil.isInSameWebpage = function(a, b) { | |
| 250 if (!a || !b) | |
| 251 return false; | |
| 252 | |
| 253 a = a.root; | |
| 254 while (a && a.parent && AutomationUtil.isInSameTree(a.parent, a)) | |
| 255 a = a.parent.root; | |
| 256 | |
| 257 b = b.root; | |
| 258 while (b && b.parent && AutomationUtil.isInSameTree(b.parent, b)) | |
| 259 b = b.parent.root; | |
| 260 | |
| 261 return a == b; | |
| 262 }; | |
| 263 | |
| 264 /** | |
| 265 * Determines whether or not a node is or is the descendant of another node. | 244 * Determines whether or not a node is or is the descendant of another node. |
| 266 * @param {!AutomationNode} node | 245 * @param {!AutomationNode} node |
| 267 * @param {!AutomationNode} ancestor | 246 * @param {!AutomationNode} ancestor |
| 268 * @return {boolean} | 247 * @return {boolean} |
| 269 */ | 248 */ |
| 270 AutomationUtil.isDescendantOf = function(node, ancestor) { | 249 AutomationUtil.isDescendantOf = function(node, ancestor) { |
| 271 var testNode = node; | 250 var testNode = node; |
| 272 while (testNode && testNode !== ancestor) | 251 while (testNode && testNode !== ancestor) |
| 273 testNode = testNode.parent; | 252 testNode = testNode.parent; |
| 274 return testNode === ancestor; | 253 return testNode === ancestor; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 while (root && | 291 while (root && |
| 313 root.parent && | 292 root.parent && |
| 314 root.parent.root && | 293 root.parent.root && |
| 315 root.parent.root.role != RoleType.desktop) { | 294 root.parent.root.role != RoleType.desktop) { |
| 316 root = root.parent.root; | 295 root = root.parent.root; |
| 317 } | 296 } |
| 318 return root; | 297 return root; |
| 319 }; | 298 }; |
| 320 | 299 |
| 321 }); // goog.scope | 300 }); // goog.scope |
| OLD | NEW |