| 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 Processes events related to editing text and emits the | 6 * @fileoverview Processes events related to editing text and emits the |
| 7 * appropriate spoken and braille feedback. | 7 * appropriate spoken and braille feedback. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 goog.provide('editing.TextEditHandler'); | 10 goog.provide('editing.TextEditHandler'); |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 549 |
| 550 /** @private {!Cursor} */ | 550 /** @private {!Cursor} */ |
| 551 this.end_ = new Cursor(endNode, endIndex); | 551 this.end_ = new Cursor(endNode, endIndex); |
| 552 this.end_ = this.end_.deepEquivalent || this.end_; | 552 this.end_ = this.end_.deepEquivalent || this.end_; |
| 553 /** @private {number} */ | 553 /** @private {number} */ |
| 554 this.localContainerStartOffset_ = startIndex; | 554 this.localContainerStartOffset_ = startIndex; |
| 555 | 555 |
| 556 // Computed members. | 556 // Computed members. |
| 557 /** @private {Spannable} */ | 557 /** @private {Spannable} */ |
| 558 this.value_; | 558 this.value_; |
| 559 /** @private {AutomationNode|undefined} */ | 559 /** @private {AutomationNode} */ |
| 560 this.lineStart_; | 560 this.lineStart_; |
| 561 /** @private {AutomationNode|undefined} */ | 561 /** @private {AutomationNode} */ |
| 562 this.lineEnd_; | 562 this.lineEnd_; |
| 563 /** @private {AutomationNode|undefined} */ | 563 /** @private {AutomationNode|undefined} */ |
| 564 this.startContainer_; | 564 this.startContainer_; |
| 565 /** @private {AutomationNode|undefined} */ | 565 /** @private {AutomationNode|undefined} */ |
| 566 this.lineStartContainer_; | 566 this.lineStartContainer_; |
| 567 /** @private {number} */ | 567 /** @private {number} */ |
| 568 this.localLineStartContainerOffset_ = 0; | 568 this.localLineStartContainerOffset_ = 0; |
| 569 /** @private {AutomationNode|undefined} */ | 569 /** @private {AutomationNode|undefined} */ |
| 570 this.lineEndContainer_; | 570 this.lineEndContainer_; |
| 571 /** @private {number} */ | 571 /** @private {number} */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 595 // Initialize defaults. | 595 // Initialize defaults. |
| 596 this.lineStart_ = lineBase.node; | 596 this.lineStart_ = lineBase.node; |
| 597 this.lineEnd_ = this.lineStart_; | 597 this.lineEnd_ = this.lineStart_; |
| 598 this.startContainer_ = this.lineStart_.parent; | 598 this.startContainer_ = this.lineStart_.parent; |
| 599 this.lineStartContainer_ = this.lineStart_.parent; | 599 this.lineStartContainer_ = this.lineStart_.parent; |
| 600 this.lineEndContainer_ = this.lineStart_.parent; | 600 this.lineEndContainer_ = this.lineStart_.parent; |
| 601 | 601 |
| 602 // Annotate each chunk with its associated inline text box node. | 602 // Annotate each chunk with its associated inline text box node. |
| 603 this.value_.setSpan(this.lineStart_, 0, nameLen); | 603 this.value_.setSpan(this.lineStart_, 0, nameLen); |
| 604 | 604 |
| 605 // Also, track the nodes necessary for selection (either their parents, in | 605 // If the current selection is not on an inline text box (e.g. an image), |
| 606 // the case of inline text boxes, or the node itself). | 606 // return early here so that the line contents are just the node. This is |
| 607 // pending the ability to show non-text leaf inline objects. |
| 608 if (this.lineStart_.role != RoleType.INLINE_TEXT_BOX) |
| 609 return; |
| 610 |
| 611 // Also, track their static text parents. |
| 607 var parents = [this.startContainer_]; | 612 var parents = [this.startContainer_]; |
| 608 | 613 |
| 609 // Compute the start of line. | 614 // Compute the start of line. |
| 610 var lineStart = this.lineStart_; | 615 var lineStart = this.lineStart_; |
| 611 | 616 while (lineStart.previousOnLine && lineStart.previousOnLine.role) { |
| 612 // Hack: note underlying bugs require these hacks. | 617 lineStart = lineStart.previousOnLine; |
| 613 while ((lineStart.previousOnLine && lineStart.previousOnLine.role) || | 618 if (lineStart.role != RoleType.INLINE_TEXT_BOX) |
| 614 (lineStart.previousSibling && lineStart.previousSibling.lastChild && | 619 continue; |
| 615 lineStart.previousSibling.lastChild.nextOnLine == lineStart)) { | |
| 616 if (lineStart.previousOnLine) | |
| 617 lineStart = lineStart.previousOnLine; | |
| 618 else | |
| 619 lineStart = lineStart.previousSibling.lastChild; | |
| 620 | 620 |
| 621 this.lineStart_ = lineStart; | 621 this.lineStart_ = lineStart; |
| 622 | 622 if (parents[0] != lineStart.parent) |
| 623 if (lineStart.role != RoleType.INLINE_TEXT_BOX) | |
| 624 parents.unshift(lineStart); | |
| 625 else if (parents[0] != lineStart.parent) | |
| 626 parents.unshift(lineStart.parent); | 623 parents.unshift(lineStart.parent); |
| 627 | 624 |
| 628 var prepend = new Spannable(lineStart.name, lineStart); | 625 var prepend = new Spannable(lineStart.name, lineStart); |
| 629 prepend.append(this.value_); | 626 prepend.append(this.value_); |
| 630 this.value_ = prepend; | 627 this.value_ = prepend; |
| 631 } | 628 } |
| 632 this.lineStartContainer_ = this.lineStart_.parent; | 629 this.lineStartContainer_ = this.lineStart_.parent; |
| 633 | 630 |
| 634 var lineEnd = this.lineEnd_; | 631 var lineEnd = this.lineEnd_; |
| 635 | 632 while (lineEnd.nextOnLine && lineEnd.nextOnLine.role) { |
| 636 // Hack: note underlying bugs require these hacks. | 633 lineEnd = lineEnd.nextOnLine; |
| 637 while ((lineEnd.nextOnLine && lineEnd.nextOnLine.role) || | 634 if (lineEnd.role != RoleType.INLINE_TEXT_BOX) |
| 638 (lineEnd.nextSibling && | 635 continue; |
| 639 lineEnd.nextSibling.previousOnLine == lineEnd)) { | |
| 640 if (lineEnd.nextOnLine) | |
| 641 lineEnd = lineEnd.nextOnLine; | |
| 642 else | |
| 643 lineEnd = lineEnd.nextSibling.firstChild; | |
| 644 | 636 |
| 645 this.lineEnd_ = lineEnd; | 637 this.lineEnd_ = lineEnd; |
| 646 | 638 if (parents[parents.length - 1] != lineEnd.parent) |
| 647 if (lineEnd.role != RoleType.INLINE_TEXT_BOX) | |
| 648 parents.push(this.lineEnd_); | |
| 649 else if (parents[parents.length - 1] != lineEnd.parent) | |
| 650 parents.push(this.lineEnd_.parent); | 639 parents.push(this.lineEnd_.parent); |
| 651 | 640 |
| 652 var annotation = lineEnd; | 641 var annotation = lineEnd; |
| 653 if (lineEnd == this.end_.node) | 642 if (lineEnd == this.end_.node) |
| 654 annotation = this.end_; | 643 annotation = this.end_; |
| 655 | 644 |
| 656 this.value_.append(new Spannable(lineEnd.name, annotation)); | 645 this.value_.append(new Spannable(lineEnd.name, annotation)); |
| 657 } | 646 } |
| 658 this.lineEndContainer_ = this.lineEnd_.parent; | 647 this.lineEndContainer_ = this.lineEnd_.parent; |
| 659 | 648 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 * @return {boolean} | 810 * @return {boolean} |
| 822 */ | 811 */ |
| 823 isSameLineAndSelection: function(otherLine) { | 812 isSameLineAndSelection: function(otherLine) { |
| 824 return this.isSameLine(otherLine) && | 813 return this.isSameLine(otherLine) && |
| 825 this.startOffset == otherLine.startOffset && | 814 this.startOffset == otherLine.startOffset && |
| 826 this.endOffset == otherLine.endOffset; | 815 this.endOffset == otherLine.endOffset; |
| 827 } | 816 } |
| 828 }; | 817 }; |
| 829 | 818 |
| 830 }); | 819 }); |
| OLD | NEW |