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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 get deepEquivalent() { | 438 get deepEquivalent() { |
439 var newNode = this.node; | 439 var newNode = this.node; |
440 var newIndex = this.index_; | 440 var newIndex = this.index_; |
441 while (newNode.firstChild) { | 441 while (newNode.firstChild) { |
442 if (newNode.role == RoleType.STATIC_TEXT) { | 442 if (newNode.role == RoleType.STATIC_TEXT) { |
443 // Text offset. | 443 // Text offset. |
444 // Re-interpret the index as an offset into an inlineTextBox. | 444 // Re-interpret the index as an offset into an inlineTextBox. |
445 var target = newNode.firstChild; | 445 var target = newNode.firstChild; |
446 var length = 0; | 446 var length = 0; |
447 while (target && length < newIndex) { | 447 while (target && length < newIndex) { |
448 if (length <= newIndex && newIndex < (length + target.name.length)) | 448 var newLength = length + target.name.length; |
| 449 |
| 450 // Either |newIndex| falls between target's text or |newIndex| is the |
| 451 // total length of all sibling text content. |
| 452 if ((length <= newIndex && newIndex < newLength) || |
| 453 (newIndex == newLength && !target.nextSibling)) |
449 break; | 454 break; |
450 length += target.name.length; | 455 length = newLength; |
451 target = target.nextSibling; | 456 target = target.nextSibling; |
452 } | 457 } |
453 if (target) { | 458 if (target) { |
454 newNode = target; | 459 newNode = target; |
455 newIndex = newIndex - length; | 460 newIndex = newIndex - length; |
456 } | 461 } |
457 break; | 462 break; |
458 } else if ( | 463 } else if ( |
459 newNode.role != RoleType.INLINE_TEXT_BOX && | 464 newNode.role != RoleType.INLINE_TEXT_BOX && |
460 newNode.children[newIndex]) { | 465 newNode.children[newIndex]) { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 /** | 767 /** |
763 * Returns whether this range has valid start and end cursors. | 768 * Returns whether this range has valid start and end cursors. |
764 * @return {boolean} | 769 * @return {boolean} |
765 */ | 770 */ |
766 isValid: function() { | 771 isValid: function() { |
767 return this.start.isValid() && this.end.isValid(); | 772 return this.start.isValid() && this.end.isValid(); |
768 } | 773 } |
769 }; | 774 }; |
770 | 775 |
771 }); // goog.scope | 776 }); // goog.scope |
OLD | NEW |