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 Classes related to cursors that point to and select parts of | 6 * @fileoverview Classes related to cursors that point to and select parts of |
7 * the automation tree. | 7 * the automation tree. |
8 */ | 8 */ |
9 | 9 |
10 goog.provide('cursors.Cursor'); | 10 goog.provide('cursors.Cursor'); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 135 |
136 /** | 136 /** |
137 * Returns the node. If the node is invalid since the last time it | 137 * Returns the node. If the node is invalid since the last time it |
138 * was accessed, moves the cursor to the nearest valid ancestor first. | 138 * was accessed, moves the cursor to the nearest valid ancestor first. |
139 * @return {AutomationNode} | 139 * @return {AutomationNode} |
140 */ | 140 */ |
141 get node() { | 141 get node() { |
142 for (var i = 0; i < this.ancestry_.length; i++) { | 142 for (var i = 0; i < this.ancestry_.length; i++) { |
143 var firstValidNode = this.ancestry_[i]; | 143 var firstValidNode = this.ancestry_[i]; |
144 if (firstValidNode != null && firstValidNode.role !== undefined && | 144 if (firstValidNode != null && firstValidNode.role !== undefined && |
145 firstValidNode.root !== undefined) { | 145 firstValidNode.root != undefined) { |
hidehiko
2017/03/21 03:43:23
nit: looks unnecessary change? (Or any reasons to
David Tseng
2017/03/21 16:41:16
It actually is. There are some cases, particularly
hidehiko
2017/03/21 22:00:43
firstValidNode.root can be null, I think it's nice
| |
146 return firstValidNode; | 146 return firstValidNode; |
147 } | 147 } |
148 // If we have to walk up to an ancestor, reset the index to NODE_INDEX. | 148 // If we have to walk up to an ancestor, reset the index to NODE_INDEX. |
149 this.index_ = cursors.NODE_INDEX; | 149 this.index_ = cursors.NODE_INDEX; |
150 } | 150 } |
151 return null; | 151 return null; |
152 }, | 152 }, |
153 | 153 |
154 /** | 154 /** |
155 * @return {number} | 155 * @return {number} |
(...skipping 13 matching lines...) Expand all Loading... | |
169 if (!adjustedNode) | 169 if (!adjustedNode) |
170 return null; | 170 return null; |
171 | 171 |
172 // Make no adjustments if we're within editable content. | 172 // Make no adjustments if we're within editable content. |
173 if (adjustedNode.state.editable) | 173 if (adjustedNode.state.editable) |
174 return adjustedNode; | 174 return adjustedNode; |
175 | 175 |
176 // Selections over line break nodes are broken. | 176 // Selections over line break nodes are broken. |
177 var parent = adjustedNode.parent; | 177 var parent = adjustedNode.parent; |
178 var grandparent = parent && parent.parent; | 178 var grandparent = parent && parent.parent; |
179 if (parent.role == RoleType.LINE_BREAK) { | 179 if (parent && parent.role == RoleType.LINE_BREAK) { |
180 adjustedNode = grandparent; | 180 adjustedNode = grandparent; |
181 } else if (grandparent.role == RoleType.LINE_BREAK) { | 181 } else if (grandparent && grandparent.role == RoleType.LINE_BREAK) { |
182 adjustedNode = grandparent.parent; | 182 adjustedNode = grandparent.parent; |
183 } else if (this.index_ == cursors.NODE_INDEX || | 183 } else if (this.index_ == cursors.NODE_INDEX || |
184 adjustedNode.role == RoleType.INLINE_TEXT_BOX || | 184 adjustedNode.role == RoleType.INLINE_TEXT_BOX || |
185 adjustedNode.nameFrom != chrome.automation.NameFromType.CONTENTS) { | 185 adjustedNode.nameFrom != chrome.automation.NameFromType.CONTENTS) { |
186 // A node offset or unselectable character offset. | 186 // A node offset or unselectable character offset. |
187 adjustedNode = parent; | 187 adjustedNode = parent; |
188 } else { | 188 } else { |
189 // A character offset into content. | 189 // A character offset into content. |
190 adjustedNode = | 190 adjustedNode = |
191 adjustedNode.find({role: RoleType.STATIC_TEXT}) || adjustedNode; | 191 adjustedNode.find({role: RoleType.STATIC_TEXT}) || adjustedNode; |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 /** | 687 /** |
688 * Returns whether this range has valid start and end cursors. | 688 * Returns whether this range has valid start and end cursors. |
689 * @return {boolean} | 689 * @return {boolean} |
690 */ | 690 */ |
691 isValid: function() { | 691 isValid: function() { |
692 return this.start.isValid() && this.end.isValid(); | 692 return this.start.isValid() && this.end.isValid(); |
693 } | 693 } |
694 }; | 694 }; |
695 | 695 |
696 }); // goog.scope | 696 }); // goog.scope |
OLD | NEW |