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

Side by Side Diff: chrome/browser/resources/chromeos/braille_ime/braille_ime.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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @fileoverview Braille hardware keyboard input method. 8 * @fileoverview Braille hardware keyboard input method.
9 * 9 *
10 * This method is automatically enabled when a braille display is connected 10 * This method is automatically enabled when a braille display is connected
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 */ 123 */
124 engineID_: '', 124 engineID_: '',
125 125
126 /** 126 /**
127 * The port used to communicate with ChromeVox. 127 * The port used to communicate with ChromeVox.
128 * @type {Port} port_ 128 * @type {Port} port_
129 * @private 129 * @private
130 */ 130 */
131 port_: null, 131 port_: null,
132 132
133 // state of the current composition, if any. This is kep here so that
134 // the composition can be committed on key presses.
135
136 /** @type {number} */
David Tseng 2015/03/30 17:13:44 nit: @private; also, perhaps combine these two mem
137 compositionContextID_: 0,
138
139 /** @type {string} */
140 compositionText_: '',
141
133 /** 142 /**
134 * Registers event listeners in the chrome IME API. 143 * Registers event listeners in the chrome IME API.
135 */ 144 */
136 init: function() { 145 init: function() {
137 chrome.input.ime.onActivate.addListener(this.onActivate_.bind(this)); 146 chrome.input.ime.onActivate.addListener(this.onActivate_.bind(this));
138 chrome.input.ime.onDeactivated.addListener(this.onDeactivated_.bind(this)); 147 chrome.input.ime.onDeactivated.addListener(this.onDeactivated_.bind(this));
139 chrome.input.ime.onFocus.addListener(this.onFocus_.bind(this)); 148 chrome.input.ime.onFocus.addListener(this.onFocus_.bind(this));
140 chrome.input.ime.onBlur.addListener(this.onBlur_.bind(this)); 149 chrome.input.ime.onBlur.addListener(this.onBlur_.bind(this));
141 chrome.input.ime.onInputContextUpdate.addListener( 150 chrome.input.ime.onInputContextUpdate.addListener(
142 this.onInputContextUpdate_.bind(this)); 151 this.onInputContextUpdate_.bind(this));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 219
211 /** 220 /**
212 * Called by the system when this IME is active and a key event is generated. 221 * Called by the system when this IME is active and a key event is generated.
213 * @param {string} engineID Engine ID, should be 'braille'. 222 * @param {string} engineID Engine ID, should be 'braille'.
214 * @param {!ChromeKeyboardEvent} event The keyboard event. 223 * @param {!ChromeKeyboardEvent} event The keyboard event.
215 * @private 224 * @private
216 */ 225 */
217 onKeyEvent_: function(engineID, event) { 226 onKeyEvent_: function(engineID, event) {
218 var result = this.processKey_(event); 227 var result = this.processKey_(event);
219 if (result !== undefined) { 228 if (result !== undefined) {
220 chrome.input.ime.keyEventHandled(event.requestId, result); 229 this.keyEventHandled_(event.requestId, event.type, result);
221 } 230 }
222 }, 231 },
223 232
224 /** 233 /**
225 * Called when chrome ends the current text input session. 234 * Called when chrome ends the current text input session.
226 * @param {string} engineID Engine ID, should be 'braille'. 235 * @param {string} engineID Engine ID, should be 'braille'.
227 * @private 236 * @private
228 */ 237 */
229 onReset_: function(engineID) { 238 onReset_: function(engineID) {
230 this.log_('onReset', engineID); 239 this.log_('onReset', engineID);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 * @type {{contextID: number, deleteBefore: number, 358 * @type {{contextID: number, deleteBefore: number,
350 * newText: string}} 359 * newText: string}}
351 */ 360 */
352 (message); 361 (message);
353 this.replaceText_(message.contextID, message.deleteBefore, 362 this.replaceText_(message.contextID, message.deleteBefore,
354 message.newText); 363 message.newText);
355 break; 364 break;
356 case 'keyEventHandled': 365 case 'keyEventHandled':
357 message = 366 message =
358 /** @type {{requestId: string, result: boolean}} */ (message); 367 /** @type {{requestId: string, result: boolean}} */ (message);
359 chrome.input.ime.keyEventHandled(message.requestId, message.result); 368 this.keyEventHandled_(message.requestId, 'keydown', message.result);
369 break;
370 case 'setComposition':
371 message =
372 /** @type {{contextID: number, text: string}} */ (message);
373 this.setComposition_(message.contextID, message.text);
374 break;
375 case 'commitComposition':
376 message =
377 /** @type {{contextID: number}} */ (message);
378 this.commitComposition_(message.contextID);
360 break; 379 break;
361 default: 380 default:
362 console.error('Unknown message from ChromeVox: ' + 381 console.error('Unknown message from ChromeVox: ' +
363 JSON.stringify(message)); 382 JSON.stringify(message));
364 break; 383 break;
365 } 384 }
366 }, 385 },
367 386
368 /** 387 /**
369 * Handles a disconnect event from the ChromeVox side. 388 * Handles a disconnect event from the ChromeVox side.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // deleteSurroundingText works correctly. 442 // deleteSurroundingText works correctly.
424 chrome.input.ime.deleteSurroundingText( 443 chrome.input.ime.deleteSurroundingText(
425 {engineID: this.engineID_, contextID: contextID, 444 {engineID: this.engineID_, contextID: contextID,
426 offset: 0, length: 0}, deleteText); 445 offset: 0, length: 0}, deleteText);
427 } else { 446 } else {
428 addText(); 447 addText();
429 } 448 }
430 }, 449 },
431 450
432 /** 451 /**
452 * Responds to an asynchronous key event, indicating whether it was handled
453 * or not. If it wasn't handled, any outstanding composition text is
454 * committed before sending the response to the IME API.
455 * @param {string} requestId Key even request id.
David Tseng 2015/03/30 17:13:44 nit: Key event
456 * @param {string} type Type of key event being responded to.
457 * @param {boolean} response Wether the IME handled theevent.
David Tseng 2015/03/30 17:13:44 nit: whether ... the event
458 */
459 keyEventHandled_: function(requestId, type, response) {
460 if (!response && type === 'keydown' && this.compositionText_) {
461 this.commitComposition_();
462 this.sendToChromeVox_({type: 'reset'});
463 }
464 chrome.input.ime.keyEventHandled(requestId, response);
465 },
466
467 /**
468 * Calls the correspnding IME API function and stores the current
David Tseng 2015/03/30 17:13:44 nit: corresponding
469 * composition.
470 * @param {number} contextID
471 * @param {string} text
472 */
473 setComposition_: function(contextID, text) {
474 chrome.input.ime.setComposition({contextID: contextID,
475 text: text,
476 cursor: text.length});
477 this.compositionContextID_ = contextID;
478 this.compositionText_ = text;
479 },
480
481 /**
482 * Commits the last set composition if it mathces the given context id.
David Tseng 2015/03/30 17:13:44 nit: matches
483 * @param {number=} opt_contextID
484 */
485 commitComposition_: function(opt_contextID) {
486 if (opt_contextID === undefined ||
David Tseng 2015/03/30 17:13:44 Why is this optional?
487 opt_contextID === this.compositionContextID_) {
488 chrome.input.ime.commitText({contextID: this.compositionContextID_,
489 text: this.compositionText_});
490 }
491 this.compositionText_ = '';
492 this.compositionContextID_ = 0;
493 },
494
495 /**
433 * Updates the menu items for this IME. 496 * Updates the menu items for this IME.
434 */ 497 */
435 updateMenuItems_: function() { 498 updateMenuItems_: function() {
436 // TODO(plundblad): Localize when translations available. 499 // TODO(plundblad): Localize when translations available.
437 chrome.input.ime.setMenuItems( 500 chrome.input.ime.setMenuItems(
438 {engineID: this.engineID_, 501 {engineID: this.engineID_,
439 items: [ 502 items: [
440 { 503 {
441 id: this.USE_STANDARD_KEYBOARD_ID, 504 id: this.USE_STANDARD_KEYBOARD_ID,
442 label: 'Use standard keyboard for braille', 505 label: 'Use standard keyboard for braille',
443 style: 'check', 506 style: 'check',
444 visible: true, 507 visible: true,
445 checked: this.useStandardKeyboard_, 508 checked: this.useStandardKeyboard_,
446 enabled: true 509 enabled: true
447 } 510 }
448 ] 511 ]
449 }); 512 });
450 } 513 }
451 }; 514 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698