Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/editing.js

Issue 2971913003: Make character text changes work in Docs (Closed)
Patch Set: Proper diffbase. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 /** @private {AutomationNode|undefined} */ 655 /** @private {AutomationNode|undefined} */
656 this.startContainer_; 656 this.startContainer_;
657 /** @private {AutomationNode|undefined} */ 657 /** @private {AutomationNode|undefined} */
658 this.lineStartContainer_; 658 this.lineStartContainer_;
659 /** @private {number} */ 659 /** @private {number} */
660 this.localLineStartContainerOffset_ = 0; 660 this.localLineStartContainerOffset_ = 0;
661 /** @private {AutomationNode|undefined} */ 661 /** @private {AutomationNode|undefined} */
662 this.lineEndContainer_; 662 this.lineEndContainer_;
663 /** @private {number} */ 663 /** @private {number} */
664 this.localLineEndContainerOffset_ = 0; 664 this.localLineEndContainerOffset_ = 0;
665 /** @type {Cursor} */
666 this.lineStartContainerCursor_;
665 667
666 this.computeLineData_(opt_baseLineOnStart); 668 this.computeLineData_(opt_baseLineOnStart);
667 }; 669 };
668 670
669 editing.EditableLine.prototype = { 671 editing.EditableLine.prototype = {
670 /** @private */ 672 /** @private */
671 computeLineData_: function(opt_baseLineOnStart) { 673 computeLineData_: function(opt_baseLineOnStart) {
672 // 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
673 // 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
674 // 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
760 // Note that both line start and end needs to account for 762 // Note that both line start and end needs to account for
761 // potential offsets into the static texts as follows. 763 // potential offsets into the static texts as follows.
762 var textCountBeforeLineStart = 0, textCountAfterLineEnd = 0; 764 var textCountBeforeLineStart = 0, textCountAfterLineEnd = 0;
763 var finder = this.lineStart_; 765 var finder = this.lineStart_;
764 while (finder.previousSibling) { 766 while (finder.previousSibling) {
765 finder = finder.previousSibling; 767 finder = finder.previousSibling;
766 textCountBeforeLineStart += finder.name.length; 768 textCountBeforeLineStart += finder.name.length;
767 } 769 }
768 this.localLineStartContainerOffset_ = textCountBeforeLineStart; 770 this.localLineStartContainerOffset_ = textCountBeforeLineStart;
769 771
772 if (this.lineStartContainer_) {
773 this.lineStartContainerCursor_ = new Cursor(
774 this.lineStartContainer_, this.localLineStartContainerOffset_);
775 }
776
770 finder = this.lineEnd_; 777 finder = this.lineEnd_;
771 while (finder.nextSibling) { 778 while (finder.nextSibling) {
772 finder = finder.nextSibling; 779 finder = finder.nextSibling;
773 textCountAfterLineEnd += finder.name.length; 780 textCountAfterLineEnd += finder.name.length;
774 } 781 }
775 782
776 if (this.lineEndContainer_.name) { 783 if (this.lineEndContainer_.name) {
777 this.localLineEndContainerOffset_ = 784 this.localLineEndContainerOffset_ =
778 this.lineEndContainer_.name.length - textCountAfterLineEnd; 785 this.lineEndContainer_.name.length - textCountAfterLineEnd;
779 } 786 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 */ 909 */
903 isSameLine: function(otherLine) { 910 isSameLine: function(otherLine) {
904 // 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
905 // 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
906 // staying the same. 913 // staying the same.
907 return (otherLine.lineStartContainer_ == this.lineStartContainer_ && 914 return (otherLine.lineStartContainer_ == this.lineStartContainer_ &&
908 otherLine.localLineStartContainerOffset_ == 915 otherLine.localLineStartContainerOffset_ ==
909 this.localLineStartContainerOffset_) || 916 this.localLineStartContainerOffset_) ||
910 (otherLine.lineEndContainer_ == this.lineEndContainer_ && 917 (otherLine.lineEndContainer_ == this.lineEndContainer_ &&
911 otherLine.localLineEndContainerOffset_ == 918 otherLine.localLineEndContainerOffset_ ==
912 this.localLineEndContainerOffset_); 919 this.localLineEndContainerOffset_) ||
920 (otherLine.lineStartContainerCursor_.recoveryNode ==
921 this.lineStartContainerCursor_.recoveryNode &&
922 otherLine.lineStartContainerCursor_.index ==
923 this.lineStartContainerCursor_.index);
913 }, 924 },
914 925
915 /** 926 /**
916 * 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
917 * same selection. 928 * same selection.
918 * @param {editing.EditableLine} otherLine 929 * @param {editing.EditableLine} otherLine
919 * @return {boolean} 930 * @return {boolean}
920 */ 931 */
921 isSameLineAndSelection: function(otherLine) { 932 isSameLineAndSelection: function(otherLine) {
922 return this.isSameLine(otherLine) && 933 return this.isSameLine(otherLine) &&
923 this.startOffset == otherLine.startOffset && 934 this.startOffset == otherLine.startOffset &&
924 this.endOffset == otherLine.endOffset; 935 this.endOffset == otherLine.endOffset;
925 }, 936 },
926 937
927 /** 938 /**
928 * Returns whether this line comes before |otherLine| in document order. 939 * Returns whether this line comes before |otherLine| in document order.
929 * @return {boolean} 940 * @return {boolean}
930 */ 941 */
931 isBeforeLine: function(otherLine) { 942 isBeforeLine: function(otherLine) {
932 if (this.isSameLine(otherLine) || !this.lineStartContainer_ || 943 if (this.isSameLine(otherLine) || !this.lineStartContainer_ ||
933 !otherLine.lineStartContainer_) 944 !otherLine.lineStartContainer_)
934 return false; 945 return false;
935 return AutomationUtil.getDirection( 946 return AutomationUtil.getDirection(
936 this.lineStartContainer_, otherLine.lineStartContainer_) == 947 this.lineStartContainer_, otherLine.lineStartContainer_) ==
937 Dir.FORWARD; 948 Dir.FORWARD;
938 } 949 }
939 }; 950 };
940 951
941 }); 952 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698