Index: chrome/browser/resources/chromeos/chromevox/braille/braille_input_handler.js |
diff --git a/chrome/browser/resources/chromeos/chromevox/braille/braille_input_handler.js b/chrome/browser/resources/chromeos/chromevox/braille/braille_input_handler.js |
index b4c3868245d9c0e1c0270ba2ab15139f410e8ffa..b39763540a06ce52be8f105e2f249742269174c2 100644 |
--- a/chrome/browser/resources/chromeos/chromevox/braille/braille_input_handler.js |
+++ b/chrome/browser/resources/chromeos/chromevox/braille/braille_input_handler.js |
@@ -75,7 +75,7 @@ cvox.BrailleInputHandler = function(translatorManager) { |
this.entryState_ = null; |
this.translatorManager_.addChangeListener( |
- this.clearEntryState_.bind(this)); |
+ this.commitAndClearEntryState_.bind(this)); |
}; |
/** |
@@ -151,7 +151,7 @@ cvox.BrailleInputHandler.prototype = { |
this.onBackspace_()) { |
return true; |
} else { |
- this.clearEntryState_(); |
+ this.commitAndClearEntryState_(); |
this.sendKeyEventPair_(event); |
return true; |
} |
@@ -209,7 +209,7 @@ cvox.BrailleInputHandler.prototype = { |
// by flushing the input when we see a blank cell. |
// Note that this might switch to contracted if appropriate. |
if (this.entryState_ && this.entryState_.lastCellIsBlank()) { |
- this.clearEntryState_(); |
+ this.commitAndClearEntryState_(); |
} |
if (!this.entryState_) { |
this.entryState_ = this.createEntryState_(); |
@@ -250,6 +250,7 @@ cvox.BrailleInputHandler.prototype = { |
} |
var uncontractedTranslator = |
this.translatorManager_.getUncontractedTranslator(); |
+ var useComposition = false; |
if (uncontractedTranslator) { |
var textBefore = this.currentTextBefore_; |
var textAfter = this.currentTextAfter_; |
@@ -257,10 +258,30 @@ cvox.BrailleInputHandler.prototype = { |
(textBefore.length > 0 && /\S$/.test(textBefore)) || |
(textAfter.length > 0 && /^\S/.test(textAfter))) { |
translator = uncontractedTranslator; |
+ } else { |
+ useComposition = true; |
} |
} |
- return new cvox.BrailleInputHandler.EditsEntryState_(this, translator); |
+ useComposition = false; |
David Tseng
2015/03/30 17:13:44
This looks wrong.
|
+ if (useComposition) { |
+ return new cvox.BrailleInputHandler.CompositionEntryState_( |
+ this, translator); |
+ } else { |
+ return new cvox.BrailleInputHandler.EditsEntryState_( |
+ this, translator); |
+ } |
+ }, |
+ |
+ /** |
+ * Commits the current entry state and clears it, if any. |
+ * @private |
+ */ |
+ commitAndClearEntryState_: function() { |
+ if (this.entryState_) { |
+ this.entryState_.commit(); |
+ this.clearEntryState_(); |
+ } |
}, |
/** |
@@ -495,6 +516,13 @@ cvox.BrailleInputHandler.EntryState_.prototype = { |
this.inputHandler_.clearEntryState_(); |
}, |
+ /** |
+ * Makes sure the current text is permanently added to the edit field. |
+ * After this call, this object should be abandoned. |
+ */ |
+ commit: function() { |
+ }, |
+ |
/** @return {boolean} */ |
lastCellIsBlank: function() { |
return this.cells_[this.cells_.length - 1] === 0; |
@@ -582,3 +610,39 @@ cvox.BrailleInputHandler.EditsEntryState_.prototype = { |
} |
} |
}; |
+ |
+/** |
+ * Entry state that uses the IME composition API to update the edit field. |
+ * @param {!cvox.BrailleInputHandler} inputHandler |
+ * @param {!cvox.LibLouis.Translator} translator |
+ * @constructor |
+ * @private |
+ * @extends {cvox.BrailleInputHandler.EntryState_} |
+ */ |
+cvox.BrailleInputHandler.CompositionEntryState_ = function( |
+ inputHandler, translator) { |
+ cvox.BrailleInputHandler.EntryState_.call(this, inputHandler, translator); |
+}; |
+ |
+cvox.BrailleInputHandler.CompositionEntryState_.prototype = { |
+ __proto__: cvox.BrailleInputHandler.EntryState_, |
+ |
+ /** @override */ |
+ commit: function() { |
+ this.inputHandler_.postImeMessage_( |
+ {type: 'commitComposition', |
+ contextID: this.inputHandler_.inputContext_.contextID}); |
+ }, |
+ |
+ /** @override */ |
+ sendTextChange_: function(newText) { |
+ var currentTextBefore = this.inputHandler_.currentTextBefore_; |
+ var oldText = this.text_; |
+ this.pendingTextsBefore_.push(currentTextBefore.substring( |
+ 0, currentTextBefore.length - oldText.length) + newText); |
+ this.inputHandler_.postImeMessage_( |
+ {type: 'setComposition', |
+ contextID: this.inputHandler_.inputContext_.contextID, |
+ text: newText}); |
+ } |
+}; |