| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 return; | 306 return; |
| 307 } | 307 } |
| 308 | 308 |
| 309 if (cur.text == '') { | 309 if (cur.text == '') { |
| 310 // This line has no text content. Describe the DOM selection. | 310 // This line has no text content. Describe the DOM selection. |
| 311 new Output() | 311 new Output() |
| 312 .withRichSpeechAndBraille( | 312 .withRichSpeechAndBraille( |
| 313 new Range(cur.start_, cur.end_), | 313 new Range(cur.start_, cur.end_), |
| 314 new Range(prev.start_, prev.end_), Output.EventType.NAVIGATE) | 314 new Range(prev.start_, prev.end_), Output.EventType.NAVIGATE) |
| 315 .go(); | 315 .go(); |
| 316 } else if (!cur.hasCollapsedSelection()) { |
| 317 // This is a selection. |
| 318 cvox.ChromeVox.tts.speak(cur.selectedText, cvox.QueueMode.CATEGORY_FLUSH); |
| 319 cvox.ChromeVox.tts.speak(Msgs.getMsg('selected'), cvox.QueueMode.QUEUE); |
| 320 this.brailleCurrentRichLine_(); |
| 316 } else { | 321 } else { |
| 317 // Describe the current line. This accounts for previous/current | 322 // Describe the current line. This accounts for previous/current |
| 318 // selections and picking the line edge boundary that changed (as computed | 323 // selections and picking the line edge boundary that changed (as computed |
| 319 // above). This is also the code path for describing paste. | 324 // above). This is also the code path for describing paste. |
| 320 cvox.ChromeVox.tts.speak(cur.text, cvox.QueueMode.CATEGORY_FLUSH); | 325 cvox.ChromeVox.tts.speak(cur.text, cvox.QueueMode.CATEGORY_FLUSH); |
| 321 this.brailleCurrentRichLine_(); | 326 this.brailleCurrentRichLine_(); |
| 322 } | 327 } |
| 323 | 328 |
| 324 // The state in EditableTextBase needs to get updated with the new line | 329 // The state in EditableTextBase needs to get updated with the new line |
| 325 // contents, so that subsequent intra-line changes get the right state | 330 // contents, so that subsequent intra-line changes get the right state |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 }, | 722 }, |
| 718 | 723 |
| 719 /** | 724 /** |
| 720 * The text content of this line. | 725 * The text content of this line. |
| 721 * @return {string} The text of this line. | 726 * @return {string} The text of this line. |
| 722 */ | 727 */ |
| 723 get text() { | 728 get text() { |
| 724 return this.value_.toString(); | 729 return this.value_.toString(); |
| 725 }, | 730 }, |
| 726 | 731 |
| 732 /** @return {string} */ |
| 733 get selectedText() { |
| 734 return this.value_.toString().substring(this.startOffset, this.endOffset); |
| 735 }, |
| 736 |
| 737 /** @return {boolean} */ |
| 738 hasCollapsedSelection: function() { |
| 739 return this.start_.equals(this.end_); |
| 740 }, |
| 741 |
| 727 /** | 742 /** |
| 728 * Returns true if |otherLine| surrounds the same line as |this|. Note that | 743 * Returns true if |otherLine| surrounds the same line as |this|. Note that |
| 729 * the contents of the line might be different. | 744 * the contents of the line might be different. |
| 730 * @param {editing.EditableLine} otherLine | 745 * @param {editing.EditableLine} otherLine |
| 731 * @return {boolean} | 746 * @return {boolean} |
| 732 */ | 747 */ |
| 733 isSameLine: function(otherLine) { | 748 isSameLine: function(otherLine) { |
| 734 // Equality is intentionally loose here as any of the state nodes can be | 749 // Equality is intentionally loose here as any of the state nodes can be |
| 735 // invalidated at any time. We rely upon the start/anchor of the line | 750 // invalidated at any time. We rely upon the start/anchor of the line |
| 736 // staying the same. | 751 // staying the same. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 749 * @return {boolean} | 764 * @return {boolean} |
| 750 */ | 765 */ |
| 751 isSameLineAndSelection: function(otherLine) { | 766 isSameLineAndSelection: function(otherLine) { |
| 752 return this.isSameLine(otherLine) && | 767 return this.isSameLine(otherLine) && |
| 753 this.startOffset == otherLine.startOffset && | 768 this.startOffset == otherLine.startOffset && |
| 754 this.endOffset == otherLine.endOffset; | 769 this.endOffset == otherLine.endOffset; |
| 755 } | 770 } |
| 756 }; | 771 }; |
| 757 | 772 |
| 758 }); | 773 }); |
| OLD | NEW |