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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 /** | 134 /** |
135 * A node appropriate for making selections. | 135 * A node appropriate for making selections. |
136 * @return {AutomationNode} | 136 * @return {AutomationNode} |
137 * @private | 137 * @private |
138 */ | 138 */ |
139 get selectionNode_() { | 139 get selectionNode_() { |
140 if (!this.node) | 140 if (!this.node) |
141 return null; | 141 return null; |
142 | 142 |
143 if (this.node.role == RoleType.inlineTextBox || | 143 if (this.node.role == RoleType.inlineTextBox) |
144 this.index_ == cursors.NODE_INDEX) | |
145 return this.node.parent; | 144 return this.node.parent; |
146 | 145 |
147 return this.node; | 146 return this.node; |
148 }, | 147 }, |
149 | 148 |
150 /** | 149 /** |
151 * An index appropriate for making selections. If this cursor has a | 150 * An index appropriate for making selections. If this cursor has a |
152 * cursors.NODE_INDEX index, the selection index is a node offset e.g. the | 151 * cursors.NODE_INDEX index, the selection index is a node offset e.g. the |
153 * index in parent. If not, the index is a character offset. | 152 * index in parent. If not, the index is a character offset. |
154 * @return {number} | 153 * @return {number} |
155 * @private | 154 * @private |
156 */ | 155 */ |
157 get selectionIndex_() { | 156 get selectionIndex_() { |
158 var adjustedIndex = this.index_; | 157 var adjustedIndex = this.index_; |
159 if (this.node.role == RoleType.inlineTextBox) { | 158 if (this.node.role == RoleType.inlineTextBox) { |
160 if (adjustedIndex == cursors.NODE_INDEX) | 159 if (adjustedIndex == cursors.NODE_INDEX) |
161 adjustedIndex = 0; | 160 adjustedIndex = 0; |
162 | 161 |
163 var sibling = this.node.previousSibling; | 162 var sibling = this.node.previousSibling; |
164 while (sibling) { | 163 while (sibling) { |
165 adjustedIndex += sibling.name.length; | 164 adjustedIndex += sibling.name.length; |
166 sibling = sibling.previousSibling; | 165 sibling = sibling.previousSibling; |
167 } | 166 } |
168 } else if (this.index_ == cursors.NODE_INDEX) { | 167 } else if (this.index_ == cursors.NODE_INDEX) { |
169 adjustedIndex = this.node.indexInParent + 1; | 168 // Indicies of this kind are buggy. Set it to 0 (different than the DOM |
| 169 // index in parent convention). |
| 170 adjustedIndex = 0; |
170 } | 171 } |
171 return adjustedIndex; | 172 return adjustedIndex; |
172 }, | 173 }, |
173 | 174 |
174 /** | 175 /** |
175 * Gets the accessible text of the node associated with this cursor. | 176 * Gets the accessible text of the node associated with this cursor. |
176 * | 177 * |
177 * @param {!AutomationNode=} opt_node Use this node rather than this cursor's | 178 * @param {!AutomationNode=} opt_node Use this node rather than this cursor's |
178 * node. | 179 * node. |
179 * @return {string} | 180 * @return {string} |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 /** | 605 /** |
605 * Returns whether this range has valid start and end cursors. | 606 * Returns whether this range has valid start and end cursors. |
606 * @return {boolean} | 607 * @return {boolean} |
607 */ | 608 */ |
608 isValid: function() { | 609 isValid: function() { |
609 return this.start.isValid() && this.end.isValid(); | 610 return this.start.isValid() && this.end.isValid(); |
610 } | 611 } |
611 }; | 612 }; |
612 | 613 |
613 }); // goog.scope | 614 }); // goog.scope |
OLD | NEW |