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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/braille/braille_input_handler.js

Issue 1039703002: Make contracted braille input work in more contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@docs2
Patch Set: Created 5 years, 8 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 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 /** 5 /**
6 * @fileoverview Handles braille input keys when the user is typing or editing 6 * @fileoverview Handles braille input keys when the user is typing or editing
7 * text in an input field. This class cooperates with the Braille IME 7 * text in an input field. This class cooperates with the Braille IME
8 * that is built into Chrome OS to do the actual text editing. 8 * that is built into Chrome OS to do the actual text editing.
9 */ 9 */
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 * @private 68 * @private
69 */ 69 */
70 this.pendingCells_ = []; 70 this.pendingCells_ = [];
71 /** 71 /**
72 * @type {cvox.BrailleInputHandler.EntryState_} 72 * @type {cvox.BrailleInputHandler.EntryState_}
73 * @private 73 * @private
74 */ 74 */
75 this.entryState_ = null; 75 this.entryState_ = null;
76 76
77 this.translatorManager_.addChangeListener( 77 this.translatorManager_.addChangeListener(
78 this.clearEntryState_.bind(this)); 78 this.commitAndClearEntryState_.bind(this));
79 }; 79 };
80 80
81 /** 81 /**
82 * The ID of the Braille IME extension built into Chrome OS. 82 * The ID of the Braille IME extension built into Chrome OS.
83 * @const {string} 83 * @const {string}
84 * @private 84 * @private
85 */ 85 */
86 cvox.BrailleInputHandler.IME_EXTENSION_ID_ = 86 cvox.BrailleInputHandler.IME_EXTENSION_ID_ =
87 'jddehjeebkoimngcbdkaahpobgicbffp'; 87 'jddehjeebkoimngcbdkaahpobgicbffp';
88 88
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return this.onBrailleDots_(/** @type {number} */(event.brailleDots)); 144 return this.onBrailleDots_(/** @type {number} */(event.brailleDots));
145 } 145 }
146 // Any other braille command cancels the pending cells. 146 // Any other braille command cancels the pending cells.
147 this.pendingCells_.length = 0; 147 this.pendingCells_.length = 0;
148 if (event.command === cvox.BrailleKeyCommand.STANDARD_KEY) { 148 if (event.command === cvox.BrailleKeyCommand.STANDARD_KEY) {
149 if (event.standardKeyCode === 'Backspace' && 149 if (event.standardKeyCode === 'Backspace' &&
150 !event.altKey && !event.ctrlKey && !event.shiftKey && 150 !event.altKey && !event.ctrlKey && !event.shiftKey &&
151 this.onBackspace_()) { 151 this.onBackspace_()) {
152 return true; 152 return true;
153 } else { 153 } else {
154 this.clearEntryState_(); 154 this.commitAndClearEntryState_();
155 this.sendKeyEventPair_(event); 155 this.sendKeyEventPair_(event);
156 return true; 156 return true;
157 } 157 }
158 } 158 }
159 return false; 159 return false;
160 }, 160 },
161 161
162 /** 162 /**
163 * Returns how the value of the currently displayed content should be 163 * Returns how the value of the currently displayed content should be
164 * expanded given the current input state. 164 * expanded given the current input state.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 this.pendingCells_.push(dots); 202 this.pendingCells_.push(dots);
203 return true; 203 return true;
204 } 204 }
205 if (!this.inputContext_) { 205 if (!this.inputContext_) {
206 return false; 206 return false;
207 } 207 }
208 // Avoid accumulating cells forever when typing without moving the cursor 208 // Avoid accumulating cells forever when typing without moving the cursor
209 // by flushing the input when we see a blank cell. 209 // by flushing the input when we see a blank cell.
210 // Note that this might switch to contracted if appropriate. 210 // Note that this might switch to contracted if appropriate.
211 if (this.entryState_ && this.entryState_.lastCellIsBlank()) { 211 if (this.entryState_ && this.entryState_.lastCellIsBlank()) {
212 this.clearEntryState_(); 212 this.commitAndClearEntryState_();
213 } 213 }
214 if (!this.entryState_) { 214 if (!this.entryState_) {
215 this.entryState_ = this.createEntryState_(); 215 this.entryState_ = this.createEntryState_();
216 if (!this.entryState_) { 216 if (!this.entryState_) {
217 return false; 217 return false;
218 } 218 }
219 } 219 }
220 this.entryState_.appendCell(dots); 220 this.entryState_.appendCell(dots);
221 return true; 221 return true;
222 }, 222 },
(...skipping 20 matching lines...) Expand all
243 * translator available yet). 243 * translator available yet).
244 * @private 244 * @private
245 */ 245 */
246 createEntryState_: function() { 246 createEntryState_: function() {
247 var translator = this.translatorManager_.getDefaultTranslator(); 247 var translator = this.translatorManager_.getDefaultTranslator();
248 if (!translator) { 248 if (!translator) {
249 return null; 249 return null;
250 } 250 }
251 var uncontractedTranslator = 251 var uncontractedTranslator =
252 this.translatorManager_.getUncontractedTranslator(); 252 this.translatorManager_.getUncontractedTranslator();
253 var useComposition = false;
253 if (uncontractedTranslator) { 254 if (uncontractedTranslator) {
254 var textBefore = this.currentTextBefore_; 255 var textBefore = this.currentTextBefore_;
255 var textAfter = this.currentTextAfter_; 256 var textAfter = this.currentTextAfter_;
256 if (this.inAlwaysUncontractedContext_() || 257 if (this.inAlwaysUncontractedContext_() ||
257 (textBefore.length > 0 && /\S$/.test(textBefore)) || 258 (textBefore.length > 0 && /\S$/.test(textBefore)) ||
258 (textAfter.length > 0 && /^\S/.test(textAfter))) { 259 (textAfter.length > 0 && /^\S/.test(textAfter))) {
259 translator = uncontractedTranslator; 260 translator = uncontractedTranslator;
261 } else {
262 useComposition = true;
260 } 263 }
261 } 264 }
262 265
263 return new cvox.BrailleInputHandler.EditsEntryState_(this, translator); 266 useComposition = false;
David Tseng 2015/03/30 17:13:44 This looks wrong.
267 if (useComposition) {
268 return new cvox.BrailleInputHandler.CompositionEntryState_(
269 this, translator);
270 } else {
271 return new cvox.BrailleInputHandler.EditsEntryState_(
272 this, translator);
273 }
264 }, 274 },
265 275
266 /** 276 /**
277 * Commits the current entry state and clears it, if any.
278 * @private
279 */
280 commitAndClearEntryState_: function() {
281 if (this.entryState_) {
282 this.entryState_.commit();
283 this.clearEntryState_();
284 }
285 },
286
287 /**
267 * Clears the current entry state without comitting it. 288 * Clears the current entry state without comitting it.
268 * @private 289 * @private
269 */ 290 */
270 clearEntryState_: function() { 291 clearEntryState_: function() {
271 if (this.entryState_) { 292 if (this.entryState_) {
272 this.entryState_.inputHandler_ = null; 293 this.entryState_.inputHandler_ = null;
273 this.entryState_ = null; 294 this.entryState_ = null;
274 } 295 }
275 }, 296 },
276 297
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // Delete all previous expected changes and ignore this one. 509 // Delete all previous expected changes and ignore this one.
489 this.pendingTextsBefore_.splice(0, i + 1); 510 this.pendingTextsBefore_.splice(0, i + 1);
490 return; 511 return;
491 } 512 }
492 } 513 }
493 // There was an actual text change (or cursor movement) that we hadn't 514 // There was an actual text change (or cursor movement) that we hadn't
494 // caused ourselves, reset any pending input. 515 // caused ourselves, reset any pending input.
495 this.inputHandler_.clearEntryState_(); 516 this.inputHandler_.clearEntryState_();
496 }, 517 },
497 518
519 /**
520 * Makes sure the current text is permanently added to the edit field.
521 * After this call, this object should be abandoned.
522 */
523 commit: function() {
524 },
525
498 /** @return {boolean} */ 526 /** @return {boolean} */
499 lastCellIsBlank: function() { 527 lastCellIsBlank: function() {
500 return this.cells_[this.cells_.length - 1] === 0; 528 return this.cells_[this.cells_.length - 1] === 0;
501 }, 529 },
502 530
503 /** 531 /**
504 * Updates the translated text based on the current cells and sends the 532 * Updates the translated text based on the current cells and sends the
505 * delta to the IME. 533 * delta to the IME.
506 * @private 534 * @private
507 */ 535 */
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 603 }
576 // Send the replace operation to be performed asynchronously by the IME. 604 // Send the replace operation to be performed asynchronously by the IME.
577 this.inputHandler_.postImeMessage_( 605 this.inputHandler_.postImeMessage_(
578 {type: 'replaceText', 606 {type: 'replaceText',
579 contextID: this.inputHandler_.inputContext_.contextID, 607 contextID: this.inputHandler_.inputContext_.contextID,
580 deleteBefore: deleteLength, 608 deleteBefore: deleteLength,
581 newText: toInsert}); 609 newText: toInsert});
582 } 610 }
583 } 611 }
584 }; 612 };
613
614 /**
615 * Entry state that uses the IME composition API to update the edit field.
616 * @param {!cvox.BrailleInputHandler} inputHandler
617 * @param {!cvox.LibLouis.Translator} translator
618 * @constructor
619 * @private
620 * @extends {cvox.BrailleInputHandler.EntryState_}
621 */
622 cvox.BrailleInputHandler.CompositionEntryState_ = function(
623 inputHandler, translator) {
624 cvox.BrailleInputHandler.EntryState_.call(this, inputHandler, translator);
625 };
626
627 cvox.BrailleInputHandler.CompositionEntryState_.prototype = {
628 __proto__: cvox.BrailleInputHandler.EntryState_,
629
630 /** @override */
631 commit: function() {
632 this.inputHandler_.postImeMessage_(
633 {type: 'commitComposition',
634 contextID: this.inputHandler_.inputContext_.contextID});
635 },
636
637 /** @override */
638 sendTextChange_: function(newText) {
639 var currentTextBefore = this.inputHandler_.currentTextBefore_;
640 var oldText = this.text_;
641 this.pendingTextsBefore_.push(currentTextBefore.substring(
642 0, currentTextBefore.length - oldText.length) + newText);
643 this.inputHandler_.postImeMessage_(
644 {type: 'setComposition',
645 contextID: this.inputHandler_.inputContext_.contextID,
646 text: newText});
647 }
648 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698