Bug 911951 part.3 Reimplement CompositionManager.setComposition() and CompositionManager.endComposition() r=yxl
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 13 Sep 2013 00:19:00 +0900
changeset 159763 cbaab4e2562d69958b1fd22d168c9d211194fc1d
parent 159762 bf88b54e5db42eea362ef5a217103228aab83910
child 159764 11cc413aad1c3b7ac09e170fb49690b878273b89
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyxl
bugs911951
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 911951 part.3 Reimplement CompositionManager.setComposition() and CompositionManager.endComposition() r=yxl
b2g/chrome/content/forms.js
--- a/b2g/chrome/content/forms.js
+++ b/b2g/chrome/content/forms.js
@@ -1064,92 +1064,100 @@ function replaceSurroundingText(element,
     editor.insertText(text);
   }
 }
 
 let CompositionManager =  {
   _isStarted: false,
   _text: '',
   _clauseAttrMap: {
-    'raw-input': domWindowUtils.COMPOSITION_ATTR_RAWINPUT,
-    'selected-raw-text': domWindowUtils.COMPOSITION_ATTR_SELECTEDRAWTEXT,
-    'converted-text': domWindowUtils.COMPOSITION_ATTR_CONVERTEDTEXT,
-    'selected-converted-text': domWindowUtils.COMPOSITION_ATTR_SELECTEDCONVERTEDTEXT
+    'raw-input':
+      Ci.nsICompositionStringSynthesizer.ATTR_RAWINPUT,
+    'selected-raw-text':
+      Ci.nsICompositionStringSynthesizer.ATTR_SELECTEDRAWTEXT,
+    'converted-text':
+      Ci.nsICompositionStringSynthesizer.ATTR_CONVERTEDTEXT,
+    'selected-converted-text':
+      Ci.nsICompositionStringSynthesizer.ATTR_SELECTEDCONVERTEDTEXT
   },
 
   setComposition: function cm_setComposition(element, text, cursor, clauses) {
     // Check parameters.
     if (!element) {
       return;
     }
     let len = text.length;
-    if (cursor < 0) {
-      cursor = 0;
-    } else if (cursor > len) {
+    if (cursor > len) {
       cursor = len;
     }
-    let clauseLens = [len, 0, 0];
-    let clauseAttrs = [domWindowUtils.COMPOSITION_ATTR_RAWINPUT,
-                       domWindowUtils.COMPOSITION_ATTR_RAWINPUT,
-                       domWindowUtils.COMPOSITION_ATTR_RAWINPUT];
+    let clauseLens = [];
+    let clauseAttrs = [];
     if (clauses) {
       let remainingLength = len;
-      // Currently we don't support 4 or more clauses composition string.
-      let clauseNum = Math.min(3, clauses.length);
-      for (let i = 0; i < clauseNum; i++) {
+      for (let i = 0; i < clauses.length; i++) {
         if (clauses[i]) {
           let clauseLength = clauses[i].length || 0;
           // Make sure the total clauses length is not bigger than that of the
           // composition string.
           if (clauseLength > remainingLength) {
             clauseLength = remainingLength;
           }
           remainingLength -= clauseLength;
-          clauseLens[i] = clauseLength;
-          clauseAttrs[i] = this._clauseAttrMap[clauses[i].selectionType] ||
-                           domWindowUtils.COMPOSITION_ATTR_RAWINPUT;
+          clauseLens.push(clauseLength);
+          clauseAttrs.push(this._clauseAttrMap[clauses[i].selectionType] ||
+                           Ci.nsICompositionStringSynthesizer.ATTR_RAWINPUT);
         }
       }
       // 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[2] += remainingLength;
+        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', '', '');
       this._text = '';
     }
 
     // Update the composing text.
     if (this._text !== text) {
       this._text = text;
       domWindowUtils.sendCompositionEvent('compositionupdate', text, '');
     }
-    domWindowUtils.sendTextEvent(text,
-                                 clauseLens[0], clauseAttrs[0],
-                                 clauseLens[1], clauseAttrs[1],
-                                 clauseLens[2], clauseAttrs[2],
-                                 cursor, 0);
+    let compositionString = domWindowUtils.createCompositionStringSynthesizer();
+    compositionString.setString(text);
+    for (var i = 0; i < clauseLens.length; i++) {
+      compositionString.appendClause(clauseLens[i], clauseAttrs[i]);
+    }
+    if (cursor >= 0) {
+      compositionString.setCaret(cursor, 0);
+    }
+    compositionString.dispatchEvent();
   },
 
   endComposition: function cm_endComposition(text) {
     if (!this._isStarted) {
       return;
     }
     // Update the composing text.
     if (this._text !== text) {
       domWindowUtils.sendCompositionEvent('compositionupdate', text, '');
     }
+    let compositionString = domWindowUtils.createCompositionStringSynthesizer();
+    compositionString.setString(text);
     // Set the cursor position to |text.length| so that the text will be
     // committed before the cursor position.
-    domWindowUtils.sendTextEvent(text, 0, 0, 0, 0, 0, 0, text.length, 0);
+    compositionString.setCaret(text.length, 0);
+    compositionString.dispatchEvent();
     domWindowUtils.sendCompositionEvent('compositionend', text, '');
     this._text = '';
     this._isStarted = false;
   },
 
   // Composition ends due to external actions.
   onCompositionEnd: function cm_onCompositionEnd() {
     if (!this._isStarted) {