Bug 917322 part.13 B2G should use nsITextInputProcessor in forms.js r=smaug+xyuan
--- a/dom/inputmethod/forms.js
+++ b/dom/inputmethod/forms.js
@@ -1202,25 +1202,36 @@ function replaceSurroundingText(element,
// Insert the text to be replaced with.
editor.insertText(text);
}
return true;
}
let CompositionManager = {
_isStarted: false,
+ _textInputProcessor: null,
_clauseAttrMap: {
'raw-input':
- Ci.nsICompositionStringSynthesizer.ATTR_RAWINPUT,
+ Ci.nsITextInputProcessor.ATTR_RAW_CLAUSE,
'selected-raw-text':
- Ci.nsICompositionStringSynthesizer.ATTR_SELECTEDRAWTEXT,
+ Ci.nsITextInputProcessor.ATTR_SELECTED_RAW_CLAUSE,
'converted-text':
- Ci.nsICompositionStringSynthesizer.ATTR_CONVERTEDTEXT,
+ Ci.nsITextInputProcessor.ATTR_CONVERTED_CLAUSE,
'selected-converted-text':
- Ci.nsICompositionStringSynthesizer.ATTR_SELECTEDCONVERTEDTEXT
+ Ci.nsITextInputProcessor.ATTR_SELECTED_CLAUSE
+ },
+
+ _prepareTextInputProcessor: function cm_prepareTextInputProcessor(aWindow)
+ {
+ if (!this._textInputProcessor) {
+ this._textInputProcessor =
+ Cc["@mozilla.org/text-input-processor;1"].
+ createInstance(Ci.nsITextInputProcessor);
+ }
+ return this._textInputProcessor.init(aWindow);
},
setComposition: function cm_setComposition(element, text, cursor, clauses) {
// Check parameters.
if (!element) {
return;
}
let len = text.length;
@@ -1237,52 +1248,53 @@ let CompositionManager = {
// Make sure the total clauses length is not bigger than that of the
// composition string.
if (clauseLength > remainingLength) {
clauseLength = remainingLength;
}
remainingLength -= clauseLength;
clauseLens.push(clauseLength);
clauseAttrs.push(this._clauseAttrMap[clauses[i].selectionType] ||
- Ci.nsICompositionStringSynthesizer.ATTR_RAWINPUT);
+ Ci.nsITextInputProcessor.ATTR_RAW_CLAUSE);
}
}
// If the total clauses length is less than that of the composition
// string, extend the last clause to the end of the composition string.
if (remainingLength > 0) {
clauseLens[clauseLens.length - 1] += remainingLength;
}
} else {
clauseLens.push(len);
- clauseAttrs.push(Ci.nsICompositionStringSynthesizer.ATTR_RAWINPUT);
- }
-
- // Start composition if need to.
- if (!this._isStarted) {
- this._isStarted = true;
- domWindowUtils.sendCompositionEvent('compositionstart', '', '');
+ clauseAttrs.push(Ci.nsITextInputProcessor.ATTR_RAW_CLAUSE);
}
+ let win = element.ownerDocument.defaultView;
+ if (!this._prepareTextInputProcessor(win)) {
+ return;
+ }
// Update the composing text.
- let compositionString = domWindowUtils.createCompositionStringSynthesizer();
- compositionString.setString(text);
+ this._textInputProcessor.setPendingCompositionString(text);
for (var i = 0; i < clauseLens.length; i++) {
- compositionString.appendClause(clauseLens[i], clauseAttrs[i]);
+ if (!clauseLens[i]) {
+ continue;
+ }
+ this._textInputProcessor.appendClauseToPendingComposition(clauseLens[i],
+ clauseAttrs[i]);
}
if (cursor >= 0) {
- compositionString.setCaret(cursor, 0);
+ this._textInputProcessor.setCaretInPendingComposition(cursor);
}
- compositionString.dispatchEvent();
+ this._isStarted = this._textInputProcessor.flushPendingComposition();
},
endComposition: function cm_endComposition(text) {
if (!this._isStarted) {
return;
}
- domWindowUtils.sendCompositionEvent('compositioncommit', text, '');
+ this._textInputProcessor.commitComposition(text ? text : "");
this._isStarted = false;
},
// Composition ends due to external actions.
onCompositionEnd: function cm_onCompositionEnd() {
if (!this._isStarted) {
return;
}