Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 goog.provide('cvox.ChromeVoxEditableContentEditable'); | 5 goog.provide('cvox.ChromeVoxEditableContentEditable'); |
| 6 goog.provide('cvox.ChromeVoxEditableHTMLInput'); | 6 goog.provide('cvox.ChromeVoxEditableHTMLInput'); |
| 7 goog.provide('cvox.ChromeVoxEditableTextArea'); | 7 goog.provide('cvox.ChromeVoxEditableTextArea'); |
| 8 goog.provide('cvox.ChromeVoxEditableTextBase'); | 8 goog.provide('cvox.ChromeVoxEditableTextBase'); |
| 9 goog.provide('cvox.TextChangeEvent'); | 9 goog.provide('cvox.TextChangeEvent'); |
| 10 goog.provide('cvox.TextHandlerInterface'); | 10 goog.provide('cvox.TextHandlerInterface'); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 this.describeSelectionChanged(evt); | 368 this.describeSelectionChanged(evt); |
| 369 } else { | 369 } else { |
| 370 this.describeTextChanged(evt); | 370 this.describeTextChanged(evt); |
| 371 } | 371 } |
| 372 this.lastChangeDescribed = true; | 372 this.lastChangeDescribed = true; |
| 373 | 373 |
| 374 this.value = evt.value; | 374 this.value = evt.value; |
| 375 this.start = evt.start; | 375 this.start = evt.start; |
| 376 this.end = evt.end; | 376 this.end = evt.end; |
| 377 | 377 |
| 378 if (this.brailleHandler_) { | 378 this.brailleCurrentLine_(); |
| 379 var line = this.getLine(this.getLineIndex(evt.start)); | |
| 380 var lineStart = this.getLineStart(this.getLineIndex(evt.start)); | |
| 381 var start = evt.start - lineStart; | |
| 382 var end = Math.min(evt.end - lineStart, line.length); | |
| 383 this.brailleHandler_.changed(line, start, end, this.multiline, this.node, | |
| 384 lineStart); | |
| 385 } | |
| 386 }; | 379 }; |
| 387 | 380 |
| 388 | 381 |
| 389 /** | 382 /** |
| 383 * Shows the current line on the braille display. | |
| 384 * @private | |
| 385 */ | |
| 386 cvox.ChromeVoxEditableTextBase.prototype.brailleCurrentLine_ = function() { | |
| 387 if (this.brailleHandler_) { | |
| 388 var lineIndex = this.getLineIndex(this.start); | |
| 389 var line = this.getLine(lineIndex); | |
| 390 // Collapsable whitespace inside the contenteditable is represented | |
| 391 // as non-breaking spaces. This confuses braille input (which relies on | |
| 392 // the text being added to be the same as the text in the input field). | |
| 393 // Since the non-breaking spaces are just an artifact of how | |
| 394 // contenteditable is implemented, normalize to normal spaces instead. | |
| 395 if (this instanceof cvox.ChromeVoxEditableContentEditable) { | |
|
David Tseng
2014/12/04 22:53:26
Does this belong in the subclass (i.e. replace val
| |
| 396 line = line.replace(/\u00A0/g, ' '); | |
| 397 } | |
| 398 var lineStart = this.getLineStart(lineIndex); | |
| 399 var start = this.start - lineStart; | |
| 400 var end = Math.min(this.end - lineStart, line.length); | |
| 401 console.log('Changed: ' + line + ' ' + start + ' ' + end + ' ' + lineStart); | |
|
David Tseng
2014/12/04 22:53:26
Remove.
| |
| 402 this.brailleHandler_.changed(line, start, end, this.multiline, this.node, | |
| 403 lineStart); | |
| 404 } | |
| 405 }; | |
| 406 | |
| 407 /** | |
| 390 * Describe a change in the selection or cursor position when the text | 408 * Describe a change in the selection or cursor position when the text |
| 391 * stays the same. | 409 * stays the same. |
| 392 * @param {cvox.TextChangeEvent} evt The text change event. | 410 * @param {cvox.TextChangeEvent} evt The text change event. |
| 393 */ | 411 */ |
| 394 cvox.ChromeVoxEditableTextBase.prototype.describeSelectionChanged = | 412 cvox.ChromeVoxEditableTextBase.prototype.describeSelectionChanged = |
| 395 function(evt) { | 413 function(evt) { |
| 396 // TODO(deboer): Factor this into two function: | 414 // TODO(deboer): Factor this into two function: |
| 397 // - one to determine the selection event | 415 // - one to determine the selection event |
| 398 // - one to speak | 416 // - one to speak |
| 399 | 417 |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1241 * @override | 1259 * @override |
| 1242 */ | 1260 */ |
| 1243 cvox.ChromeVoxEditableContentEditable.prototype.changed = | 1261 cvox.ChromeVoxEditableContentEditable.prototype.changed = |
| 1244 function(evt) { | 1262 function(evt) { |
| 1245 if (!evt.triggeredByUser) { | 1263 if (!evt.triggeredByUser) { |
| 1246 return; | 1264 return; |
| 1247 } | 1265 } |
| 1248 // Take over here if we can't describe a change; assume it's a blank line. | 1266 // Take over here if we can't describe a change; assume it's a blank line. |
| 1249 if (!this.shouldDescribeChange(evt)) { | 1267 if (!this.shouldDescribeChange(evt)) { |
| 1250 this.speak(cvox.ChromeVox.msgs.getMsg('text_box_blank'), true); | 1268 this.speak(cvox.ChromeVox.msgs.getMsg('text_box_blank'), true); |
| 1269 if (this.brailleHandler_) { | |
| 1270 this.brailleHandler_.changed('' /*line*/, 0 /*start*/, 0 /*end*/, | |
| 1271 true /*multiline*/, null /*element*/, | |
| 1272 evt.start /*lineStart*/); | |
| 1273 } | |
| 1251 } else { | 1274 } else { |
| 1252 goog.base(this, 'changed', evt); | 1275 goog.base(this, 'changed', evt); |
| 1253 } | 1276 } |
| 1254 }; | 1277 }; |
| 1255 | 1278 |
| 1256 | 1279 |
| 1257 /** @override */ | 1280 /** @override */ |
| 1258 cvox.ChromeVoxEditableContentEditable.prototype.moveCursorToNextCharacter = | 1281 cvox.ChromeVoxEditableContentEditable.prototype.moveCursorToNextCharacter = |
| 1259 function() { | 1282 function() { |
| 1260 window.getSelection().modify('move', 'forward', 'character'); | 1283 window.getSelection().modify('move', 'forward', 'character'); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 // but there is still content after the new line (like the example | 1345 // but there is still content after the new line (like the example |
| 1323 // above after "Title"). In these cases, we "pretend" we're the | 1346 // above after "Title"). In these cases, we "pretend" we're the |
| 1324 // last character so we speak "blank". | 1347 // last character so we speak "blank". |
| 1325 return false; | 1348 return false; |
| 1326 } | 1349 } |
| 1327 | 1350 |
| 1328 // Otherwise, we should never speak "blank" no matter what (even if | 1351 // Otherwise, we should never speak "blank" no matter what (even if |
| 1329 // we're at the end of a content editable). | 1352 // we're at the end of a content editable). |
| 1330 return true; | 1353 return true; |
| 1331 }; | 1354 }; |
| OLD | NEW |