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'); |
11 | 11 |
12 goog.require('AutomationTreeWalker'); | 12 goog.require('AutomationTreeWalker'); |
13 goog.require('AutomationUtil'); | 13 goog.require('AutomationUtil'); |
14 goog.require('Output'); | 14 goog.require('Output'); |
15 goog.require('Output.EventType'); | 15 goog.require('Output.EventType'); |
| 16 goog.require('TreePathRecoveryStrategy'); |
16 goog.require('cursors.Cursor'); | 17 goog.require('cursors.Cursor'); |
17 goog.require('cursors.Range'); | 18 goog.require('cursors.Range'); |
18 goog.require('cvox.BrailleBackground'); | 19 goog.require('cvox.BrailleBackground'); |
19 goog.require('cvox.ChromeVoxEditableTextBase'); | 20 goog.require('cvox.ChromeVoxEditableTextBase'); |
20 goog.require('cvox.LibLouis.FormType'); | 21 goog.require('cvox.LibLouis.FormType'); |
21 | 22 |
22 goog.scope(function() { | 23 goog.scope(function() { |
23 var AutomationEvent = chrome.automation.AutomationEvent; | 24 var AutomationEvent = chrome.automation.AutomationEvent; |
24 var AutomationNode = chrome.automation.AutomationNode; | 25 var AutomationNode = chrome.automation.AutomationNode; |
25 var Cursor = cursors.Cursor; | 26 var Cursor = cursors.Cursor; |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 /** @private {AutomationNode|undefined} */ | 655 /** @private {AutomationNode|undefined} */ |
655 this.startContainer_; | 656 this.startContainer_; |
656 /** @private {AutomationNode|undefined} */ | 657 /** @private {AutomationNode|undefined} */ |
657 this.lineStartContainer_; | 658 this.lineStartContainer_; |
658 /** @private {number} */ | 659 /** @private {number} */ |
659 this.localLineStartContainerOffset_ = 0; | 660 this.localLineStartContainerOffset_ = 0; |
660 /** @private {AutomationNode|undefined} */ | 661 /** @private {AutomationNode|undefined} */ |
661 this.lineEndContainer_; | 662 this.lineEndContainer_; |
662 /** @private {number} */ | 663 /** @private {number} */ |
663 this.localLineEndContainerOffset_ = 0; | 664 this.localLineEndContainerOffset_ = 0; |
| 665 /** @type {RecoveryStrategy} */ |
| 666 this.lineStartContainerRecovery_; |
664 | 667 |
665 this.computeLineData_(opt_baseLineOnStart); | 668 this.computeLineData_(opt_baseLineOnStart); |
666 }; | 669 }; |
667 | 670 |
668 editing.EditableLine.prototype = { | 671 editing.EditableLine.prototype = { |
669 /** @private */ | 672 /** @private */ |
670 computeLineData_: function(opt_baseLineOnStart) { | 673 computeLineData_: function(opt_baseLineOnStart) { |
671 // Note that we calculate the line based only upon anchor or focus even if | 674 // Note that we calculate the line based only upon anchor or focus even if |
672 // they do not fall on the same line. It is up to the caller to specify | 675 // they do not fall on the same line. It is up to the caller to specify |
673 // which end to base this line upon since it requires reasoning about two | 676 // which end to base this line upon since it requires reasoning about two |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 // Note that both line start and end needs to account for | 762 // Note that both line start and end needs to account for |
760 // potential offsets into the static texts as follows. | 763 // potential offsets into the static texts as follows. |
761 var textCountBeforeLineStart = 0, textCountAfterLineEnd = 0; | 764 var textCountBeforeLineStart = 0, textCountAfterLineEnd = 0; |
762 var finder = this.lineStart_; | 765 var finder = this.lineStart_; |
763 while (finder.previousSibling) { | 766 while (finder.previousSibling) { |
764 finder = finder.previousSibling; | 767 finder = finder.previousSibling; |
765 textCountBeforeLineStart += finder.name.length; | 768 textCountBeforeLineStart += finder.name.length; |
766 } | 769 } |
767 this.localLineStartContainerOffset_ = textCountBeforeLineStart; | 770 this.localLineStartContainerOffset_ = textCountBeforeLineStart; |
768 | 771 |
| 772 if (this.lineStartContainer_) { |
| 773 this.lineStartContainerRecovery_ = |
| 774 new TreePathRecoveryStrategy(this.lineStartContainer_); |
| 775 } |
| 776 |
769 finder = this.lineEnd_; | 777 finder = this.lineEnd_; |
770 while (finder.nextSibling) { | 778 while (finder.nextSibling) { |
771 finder = finder.nextSibling; | 779 finder = finder.nextSibling; |
772 textCountAfterLineEnd += finder.name.length; | 780 textCountAfterLineEnd += finder.name.length; |
773 } | 781 } |
774 | 782 |
775 if (this.lineEndContainer_.name) { | 783 if (this.lineEndContainer_.name) { |
776 this.localLineEndContainerOffset_ = | 784 this.localLineEndContainerOffset_ = |
777 this.lineEndContainer_.name.length - textCountAfterLineEnd; | 785 this.lineEndContainer_.name.length - textCountAfterLineEnd; |
778 } | 786 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 */ | 909 */ |
902 isSameLine: function(otherLine) { | 910 isSameLine: function(otherLine) { |
903 // Equality is intentionally loose here as any of the state nodes can be | 911 // Equality is intentionally loose here as any of the state nodes can be |
904 // invalidated at any time. We rely upon the start/anchor of the line | 912 // invalidated at any time. We rely upon the start/anchor of the line |
905 // staying the same. | 913 // staying the same. |
906 return (otherLine.lineStartContainer_ == this.lineStartContainer_ && | 914 return (otherLine.lineStartContainer_ == this.lineStartContainer_ && |
907 otherLine.localLineStartContainerOffset_ == | 915 otherLine.localLineStartContainerOffset_ == |
908 this.localLineStartContainerOffset_) || | 916 this.localLineStartContainerOffset_) || |
909 (otherLine.lineEndContainer_ == this.lineEndContainer_ && | 917 (otherLine.lineEndContainer_ == this.lineEndContainer_ && |
910 otherLine.localLineEndContainerOffset_ == | 918 otherLine.localLineEndContainerOffset_ == |
911 this.localLineEndContainerOffset_); | 919 this.localLineEndContainerOffset_) || |
| 920 (otherLine.lineStartContainerRecovery_.node == |
| 921 this.lineStartContainerRecovery_.node && |
| 922 otherLine.localLineStartContainerOffset_ == |
| 923 this.localLineStartContainerOffset_); |
912 }, | 924 }, |
913 | 925 |
914 /** | 926 /** |
915 * Returns true if |otherLine| surrounds the same line as |this| and has the | 927 * Returns true if |otherLine| surrounds the same line as |this| and has the |
916 * same selection. | 928 * same selection. |
917 * @param {editing.EditableLine} otherLine | 929 * @param {editing.EditableLine} otherLine |
918 * @return {boolean} | 930 * @return {boolean} |
919 */ | 931 */ |
920 isSameLineAndSelection: function(otherLine) { | 932 isSameLineAndSelection: function(otherLine) { |
921 return this.isSameLine(otherLine) && | 933 return this.isSameLine(otherLine) && |
922 this.startOffset == otherLine.startOffset && | 934 this.startOffset == otherLine.startOffset && |
923 this.endOffset == otherLine.endOffset; | 935 this.endOffset == otherLine.endOffset; |
924 }, | 936 }, |
925 | 937 |
926 /** | 938 /** |
927 * Returns whether this line comes before |otherLine| in document order. | 939 * Returns whether this line comes before |otherLine| in document order. |
928 * @return {boolean} | 940 * @return {boolean} |
929 */ | 941 */ |
930 isBeforeLine: function(otherLine) { | 942 isBeforeLine: function(otherLine) { |
931 if (this.isSameLine(otherLine) || !this.lineStartContainer_ || | 943 if (this.isSameLine(otherLine) || !this.lineStartContainer_ || |
932 !otherLine.lineStartContainer_) | 944 !otherLine.lineStartContainer_) |
933 return false; | 945 return false; |
934 return AutomationUtil.getDirection( | 946 return AutomationUtil.getDirection( |
935 this.lineStartContainer_, otherLine.lineStartContainer_) == | 947 this.lineStartContainer_, otherLine.lineStartContainer_) == |
936 Dir.FORWARD; | 948 Dir.FORWARD; |
937 } | 949 } |
938 }; | 950 }; |
939 | 951 |
940 }); | 952 }); |
OLD | NEW |