OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 A tree walker over the automation tree. | 6 * @fileoverview A tree walker over the automation tree. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('AutomationTreeWalker'); | 9 goog.provide('AutomationTreeWalker'); |
10 goog.provide('AutomationTreeWalkerPhase'); | 10 goog.provide('AutomationTreeWalkerPhase'); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 this.phase_ = AutomationTreeWalkerPhase.INITIAL; | 81 this.phase_ = AutomationTreeWalkerPhase.INITIAL; |
82 /** @const {constants.Dir} @private */ | 82 /** @const {constants.Dir} @private */ |
83 this.dir_ = dir; | 83 this.dir_ = dir; |
84 /** @const {!chrome.automation.AutomationNode} @private */ | 84 /** @const {!chrome.automation.AutomationNode} @private */ |
85 this.initialNode_ = node; | 85 this.initialNode_ = node; |
86 /** | 86 /** |
87 * Deepest common ancestor of initialNode and node. Valid only when moving | 87 * Deepest common ancestor of initialNode and node. Valid only when moving |
88 * backward. | 88 * backward. |
89 * @type {chrome.automation.AutomationNode} @private | 89 * @type {chrome.automation.AutomationNode} @private |
90 */ | 90 */ |
91 this.backwardAncestor_ = node.parent; | 91 this.backwardAncestor_ = node.parent || null; |
92 var restrictions = opt_restrictions || {}; | 92 var restrictions = opt_restrictions || {}; |
93 | 93 |
94 this.visitPred_ = function(node) { | 94 this.visitPred_ = function(node) { |
95 if (this.skipInitialAncestry_ && | 95 if (this.skipInitialAncestry_ && |
96 this.phase_ == AutomationTreeWalkerPhase.ANCESTOR) | 96 this.phase_ == AutomationTreeWalkerPhase.ANCESTOR) |
97 return false; | 97 return false; |
98 | 98 |
99 if (this.skipInitialSubtree_ && | 99 if (this.skipInitialSubtree_ && |
100 this.phase != AutomationTreeWalkerPhase.ANCESTOR && | 100 this.phase != AutomationTreeWalkerPhase.ANCESTOR && |
101 this.phase != AutomationTreeWalkerPhase.OTHER) | 101 this.phase != AutomationTreeWalkerPhase.OTHER) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 node = node.previousSibling; | 214 node = node.previousSibling; |
215 | 215 |
216 while (!this.leafPred_(node) && node.lastChild) | 216 while (!this.leafPred_(node) && node.lastChild) |
217 node = node.lastChild; | 217 node = node.lastChild; |
218 | 218 |
219 this.node_ = node; | 219 this.node_ = node; |
220 return; | 220 return; |
221 } | 221 } |
222 if (node.parent && this.backwardAncestor_ == node.parent) { | 222 if (node.parent && this.backwardAncestor_ == node.parent) { |
223 this.phase_ = AutomationTreeWalkerPhase.ANCESTOR; | 223 this.phase_ = AutomationTreeWalkerPhase.ANCESTOR; |
224 this.backwardAncestor_ = node.parent.parent; | 224 this.backwardAncestor_ = node.parent.parent || null; |
225 } | 225 } |
226 this.node_ = node.parent; | 226 this.node_ = node.parent || null; |
227 } | 227 } |
228 }; | 228 }; |
OLD | NEW |