Bug 543789 part.5 Implement DOM3 composition event on Mac r=smichaud+smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 22 Sep 2011 18:17:40 +0900
changeset 78625 8d48a0f50b4c2c92de5320e97f48b69e7ebfba11
parent 78624 71ffc9bbcb31e08cdbd72338251f8ead42655b37
child 78626 54fbf5eda91483e9770ed039b7378a82335d9a4a
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmichaud
bugs543789
milestone9.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 543789 part.5 Implement DOM3 composition event on Mac r=smichaud+smaug
widget/src/cocoa/TextInputHandler.h
widget/src/cocoa/TextInputHandler.mm
--- a/widget/src/cocoa/TextInputHandler.h
+++ b/widget/src/cocoa/TextInputHandler.h
@@ -941,16 +941,19 @@ protected:
    *
    * @param aAttrString           A string which is committed.
    */
   void InsertTextAsCommittingComposition(NSAttributedString* aAttrString);
 
 private:
   // If mIsIMEComposing is true, the composition string is stored here.
   NSString* mIMECompositionString;
+  // mLastDispatchedCompositionString stores the lastest dispatched composition
+  // string by compositionupdate event.
+  nsString mLastDispatchedCompositionString;
 
   NSRange mMarkedRange;
 
   PRPackedBool mIsIMEComposing;
   PRPackedBool mIsIMEEnabled;
   PRPackedBool mIsASCIICapableOnly;
   PRPackedBool mIgnoreIMECommit;
   // This flag is enabled by OnFocusChangeInGecko, and will be cleared by
--- a/widget/src/cocoa/TextInputHandler.mm
+++ b/widget/src/cocoa/TextInputHandler.mm
@@ -1936,16 +1936,34 @@ IMEInputHandler::DispatchTextEvent(const
   textEvent.theText = aText;
   nsAutoTArray<nsTextRange, 4> textRanges;
   if (!aDoCommit) {
     SetTextRangeList(textRanges, aAttrString, aSelectedRange);
   }
   textEvent.rangeArray = textRanges.Elements();
   textEvent.rangeCount = textRanges.Length();
 
+  if (textEvent.theText != mLastDispatchedCompositionString) {
+    nsCompositionEvent compositionUpdate(PR_TRUE, NS_COMPOSITION_UPDATE,
+                                         mWidget);
+    compositionUpdate.time = textEvent.time;
+    compositionUpdate.data = textEvent.theText;
+    mLastDispatchedCompositionString = textEvent.theText;
+    DispatchEvent(compositionUpdate);
+    if (mIsInFocusProcessing || Destroyed()) {
+      PR_LOG(gLog, PR_LOG_ALWAYS,
+        ("%p IMEInputHandler::DispatchTextEvent, compositionupdate causes "
+         "aborting the composition, mIsInFocusProcessing=%s, Destryoed()=%s",
+         this, TrueOrFalse(mIsInFocusProcessing), TrueOrFalse(Destroyed())));
+      if (Destroyed()) {
+        return PR_TRUE;
+      }
+    }
+  }
+
   return DispatchEvent(textEvent);
 }
 
 void
 IMEInputHandler::InitCompositionEvent(nsCompositionEvent& aCompositionEvent)
 {
   aCompositionEvent.time = PR_IntervalNow();
 }
@@ -2005,16 +2023,17 @@ IMEInputHandler::InsertTextAsCommittingC
        "destroyed by text event", this));
     return;
   }
 
   OnUpdateIMEComposition([aAttrString string]);
 
   nsCompositionEvent compEnd(PR_TRUE, NS_COMPOSITION_END, mWidget);
   InitCompositionEvent(compEnd);
+  compEnd.data = mLastDispatchedCompositionString;
   DispatchEvent(compEnd);
   if (Destroyed()) {
     PR_LOG(gLog, PR_LOG_ALWAYS,
       ("%p IMEInputHandler::InsertTextAsCommittingComposition, "
        "destroyed by compositionend event", this));
     return;
   }
 
@@ -2082,16 +2101,17 @@ IMEInputHandler::SetMarkedText(NSAttribu
         ("%p IMEInputHandler::SetMarkedText, "
          "destroyed by text event", this));
       return;
     }
 
     if (doCommit) {
       nsCompositionEvent compEnd(PR_TRUE, NS_COMPOSITION_END, mWidget);
       InitCompositionEvent(compEnd);
+      compEnd.data = mLastDispatchedCompositionString;
       DispatchEvent(compEnd);
       if (Destroyed()) {
         PR_LOG(gLog, PR_LOG_ALWAYS,
           ("%p IMEInputHandler::SetMarkedText, "
            "destroyed by compositionend event", this));
         return;
       }
       OnEndIMEComposition();
@@ -2431,16 +2451,18 @@ IMEInputHandler::OnStartIMEComposition()
     ("%p IMEInputHandler::OnStartIMEComposition, mView=%p, mWidget=%p"
      "currentInputManager=%p, mIsIMEComposing=%s",
      this, mView, mWidget, [NSInputManager currentInputManager],
      TrueOrFalse(mIsIMEComposing)));
 
   NS_ASSERTION(!mIsIMEComposing, "There is a composition already");
   mIsIMEComposing = PR_TRUE;
 
+  mLastDispatchedCompositionString.Truncate();
+
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 void
 IMEInputHandler::OnUpdateIMEComposition(NSString* aIMECompositionString)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
@@ -2474,16 +2496,18 @@ IMEInputHandler::OnEndIMEComposition()
 
   mIsIMEComposing = PR_FALSE;
 
   if (mIMECompositionString) {
     [mIMECompositionString release];
     mIMECompositionString = nsnull;
   }
 
+  mLastDispatchedCompositionString.Truncate();
+
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 void
 IMEInputHandler::SendCommittedText(NSString *aString)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;