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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/braille_ime/braille_ime.js
diff --git a/chrome/browser/resources/chromeos/braille_ime/braille_ime.js b/chrome/browser/resources/chromeos/braille_ime/braille_ime.js
index deed955617be1eea14cdad4f1a0ca00c47745f34..b4babcdf2ec546473dcbea6d456fbff75c0cd5e3 100644
--- a/chrome/browser/resources/chromeos/braille_ime/braille_ime.js
+++ b/chrome/browser/resources/chromeos/braille_ime/braille_ime.js
@@ -130,6 +130,15 @@ BrailleIme.prototype = {
*/
port_: null,
+ // state of the current composition, if any. This is kep here so that
+ // the composition can be committed on key presses.
+
+ /** @type {number} */
David Tseng 2015/03/30 17:13:44 nit: @private; also, perhaps combine these two mem
+ compositionContextID_: 0,
+
+ /** @type {string} */
+ compositionText_: '',
+
/**
* Registers event listeners in the chrome IME API.
*/
@@ -217,7 +226,7 @@ BrailleIme.prototype = {
onKeyEvent_: function(engineID, event) {
var result = this.processKey_(event);
if (result !== undefined) {
- chrome.input.ime.keyEventHandled(event.requestId, result);
+ this.keyEventHandled_(event.requestId, event.type, result);
}
},
@@ -356,7 +365,17 @@ BrailleIme.prototype = {
case 'keyEventHandled':
message =
/** @type {{requestId: string, result: boolean}} */ (message);
- chrome.input.ime.keyEventHandled(message.requestId, message.result);
+ this.keyEventHandled_(message.requestId, 'keydown', message.result);
+ break;
+ case 'setComposition':
+ message =
+ /** @type {{contextID: number, text: string}} */ (message);
+ this.setComposition_(message.contextID, message.text);
+ break;
+ case 'commitComposition':
+ message =
+ /** @type {{contextID: number}} */ (message);
+ this.commitComposition_(message.contextID);
break;
default:
console.error('Unknown message from ChromeVox: ' +
@@ -430,6 +449,50 @@ BrailleIme.prototype = {
},
/**
+ * Responds to an asynchronous key event, indicating whether it was handled
+ * or not. If it wasn't handled, any outstanding composition text is
+ * committed before sending the response to the IME API.
+ * @param {string} requestId Key even request id.
David Tseng 2015/03/30 17:13:44 nit: Key event
+ * @param {string} type Type of key event being responded to.
+ * @param {boolean} response Wether the IME handled theevent.
David Tseng 2015/03/30 17:13:44 nit: whether ... the event
+ */
+ keyEventHandled_: function(requestId, type, response) {
+ if (!response && type === 'keydown' && this.compositionText_) {
+ this.commitComposition_();
+ this.sendToChromeVox_({type: 'reset'});
+ }
+ chrome.input.ime.keyEventHandled(requestId, response);
+ },
+
+ /**
+ * Calls the correspnding IME API function and stores the current
David Tseng 2015/03/30 17:13:44 nit: corresponding
+ * composition.
+ * @param {number} contextID
+ * @param {string} text
+ */
+ setComposition_: function(contextID, text) {
+ chrome.input.ime.setComposition({contextID: contextID,
+ text: text,
+ cursor: text.length});
+ this.compositionContextID_ = contextID;
+ this.compositionText_ = text;
+ },
+
+ /**
+ * Commits the last set composition if it mathces the given context id.
David Tseng 2015/03/30 17:13:44 nit: matches
+ * @param {number=} opt_contextID
+ */
+ commitComposition_: function(opt_contextID) {
+ if (opt_contextID === undefined ||
David Tseng 2015/03/30 17:13:44 Why is this optional?
+ opt_contextID === this.compositionContextID_) {
+ chrome.input.ime.commitText({contextID: this.compositionContextID_,
+ text: this.compositionText_});
+ }
+ this.compositionText_ = '';
+ this.compositionContextID_ = 0;
+ },
+
+ /**
* Updates the menu items for this IME.
*/
updateMenuItems_: function() {

Powered by Google App Engine
This is Rietveld 408576698