 Chromium Code Reviews
 Chromium Code Reviews Issue 2931893002:
  More precise use of multiline state  (Closed)
    
  
    Issue 2931893002:
  More precise use of multiline state  (Closed) 
  | 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 throw Error('Node must have editable state set to true.'); | 113 throw Error('Node must have editable state set to true.'); | 
| 114 var start = node.textSelStart; | 114 var start = node.textSelStart; | 
| 115 var end = node.textSelEnd; | 115 var end = node.textSelEnd; | 
| 116 cvox.ChromeVoxEditableTextBase.call( | 116 cvox.ChromeVoxEditableTextBase.call( | 
| 117 this, node.value || '', Math.min(start, end), Math.max(start, end), | 117 this, node.value || '', Math.min(start, end), Math.max(start, end), | 
| 118 node.state[StateType.PROTECTED] /**password*/, cvox.ChromeVox.tts); | 118 node.state[StateType.PROTECTED] /**password*/, cvox.ChromeVox.tts); | 
| 119 /** @override */ | 119 /** @override */ | 
| 120 this.multiline = node.state[StateType.MULTILINE] || false; | 120 this.multiline = node.state[StateType.MULTILINE] || false; | 
| 121 /** @type {!AutomationNode} @private */ | 121 /** @type {!AutomationNode} @private */ | 
| 122 this.node_ = node; | 122 this.node_ = node; | 
| 123 /** @type {Array<number>} @private */ | |
| 124 this.lineBreaks_ = []; | |
| 125 } | 123 } | 
| 126 | 124 | 
| 127 AutomationEditableText.prototype = { | 125 AutomationEditableText.prototype = { | 
| 128 __proto__: cvox.ChromeVoxEditableTextBase.prototype, | 126 __proto__: cvox.ChromeVoxEditableTextBase.prototype, | 
| 129 | 127 | 
| 130 /** | 128 /** | 
| 131 * Called when the text field has been updated. | 129 * Called when the text field has been updated. | 
| 132 */ | 130 */ | 
| 133 onUpdate: function() { | 131 onUpdate: function() { | 
| 134 var newValue = this.node_.value || ''; | 132 var newValue = this.node_.value || ''; | 
| 135 | 133 | 
| 136 if (this.value != newValue) | |
| 137 this.lineBreaks_ = []; | |
| 138 | |
| 139 var textChangeEvent = new cvox.TextChangeEvent( | 134 var textChangeEvent = new cvox.TextChangeEvent( | 
| 140 newValue, this.node_.textSelStart || 0, this.node_.textSelEnd || 0, | 135 newValue, this.node_.textSelStart || 0, this.node_.textSelEnd || 0, | 
| 141 true /* triggered by user */); | 136 true /* triggered by user */); | 
| 142 this.changed(textChangeEvent); | 137 this.changed(textChangeEvent); | 
| 143 this.outputBraille_(); | 138 this.outputBraille_(); | 
| 144 }, | 139 }, | 
| 145 | 140 | 
| 146 /** @override */ | 141 /** @override */ | 
| 147 getLineIndex: function(charIndex) { | 142 getLineIndex: function(charIndex) { | 
| 148 if (!this.multiline) | 143 if (!this.multiline) | 
| 149 return 0; | 144 return 0; | 
| 150 var breaks = this.node_.lineBreaks || []; | 145 var breaks = this.node_.lineBreaks || []; | 
| 151 var index = 0; | 146 var index = 0; | 
| 152 while (index < breaks.length && breaks[index] <= charIndex) | 147 while (index < breaks.length && breaks[index] <= charIndex) | 
| 153 ++index; | 148 ++index; | 
| 154 return index; | 149 return index; | 
| 155 }, | 150 }, | 
| 156 | 151 | 
| 157 /** @override */ | 152 /** @override */ | 
| 158 getLineStart: function(lineIndex) { | 153 getLineStart: function(lineIndex) { | 
| 159 if (!this.multiline || lineIndex == 0) | 154 if (!this.multiline || lineIndex == 0) | 
| 160 return 0; | 155 return 0; | 
| 161 var breaks = this.getLineBreaks_(); | 156 var breaks = this.getLineBreaks_(); | 
| 157 if (breaks.length < 1) | |
| 
David Tseng
2017/07/01 01:17:40
Thanks for the cleanup, but this entire class is p
 | |
| 158 return 0; | |
| 162 return breaks[lineIndex - 1] || this.node_.value.length; | 159 return breaks[lineIndex - 1] || this.node_.value.length; | 
| 163 }, | 160 }, | 
| 164 | 161 | 
| 165 /** @override */ | 162 /** @override */ | 
| 166 getLineEnd: function(lineIndex) { | 163 getLineEnd: function(lineIndex) { | 
| 167 var breaks = this.getLineBreaks_(); | 164 var breaks = this.getLineBreaks_(); | 
| 168 var value = this.node_.value; | 165 var value = this.node_.value; | 
| 169 if (lineIndex >= breaks.length) | 166 if (lineIndex >= breaks.length) | 
| 170 return value.length; | 167 return value.length; | 
| 171 return breaks[lineIndex] - 1; | 168 return breaks[lineIndex] - 1; | 
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 * @return {boolean} | 807 * @return {boolean} | 
| 811 */ | 808 */ | 
| 812 isSameLineAndSelection: function(otherLine) { | 809 isSameLineAndSelection: function(otherLine) { | 
| 813 return this.isSameLine(otherLine) && | 810 return this.isSameLine(otherLine) && | 
| 814 this.startOffset == otherLine.startOffset && | 811 this.startOffset == otherLine.startOffset && | 
| 815 this.endOffset == otherLine.endOffset; | 812 this.endOffset == otherLine.endOffset; | 
| 816 } | 813 } | 
| 817 }; | 814 }; | 
| 818 | 815 | 
| 819 }); | 816 }); | 
| OLD | NEW |