Bug 891316 part.7 Refactor nsIMM32Handler::OnIME*() r=jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 18 Jul 2013 17:12:31 +0900
changeset 152204 2bf0e61abaae626eb0e948b7273867ef533ca11a
parent 152203 ae37b6b3032123d12828018f408f3fecf24f1c58
child 152205 2bac560565ec4f76e0530212505373f0d686a617
push id382
push userakeybl@mozilla.com
push dateMon, 21 Oct 2013 21:47:13 +0000
treeherdermozilla-release@5f1868ee45cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs891316
milestone25.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 891316 part.7 Refactor nsIMM32Handler::OnIME*() r=jimm
widget/windows/nsIMM32Handler.cpp
widget/windows/nsIMM32Handler.h
--- a/widget/windows/nsIMM32Handler.cpp
+++ b/widget/windows/nsIMM32Handler.cpp
@@ -287,45 +287,34 @@ nsIMM32Handler::ProcessMessage(nsWindow*
                               msg == WM_LBUTTONDOWN ? IMEMOUSE_LDOWN :
                               msg == WM_MBUTTONDOWN ? IMEMOUSE_MDOWN :
                                                       IMEMOUSE_RDOWN, aResult);
     }
     case WM_INPUTLANGCHANGE:
       return ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult);
     case WM_IME_STARTCOMPOSITION:
       EnsureHandlerInstance();
-      aResult.mConsumed = gIMM32Handler->OnIMEStartComposition(aWindow);
-      return true;
+      return gIMM32Handler->OnIMEStartComposition(aWindow, aResult);
     case WM_IME_COMPOSITION:
       EnsureHandlerInstance();
-      aResult.mConsumed =
-        gIMM32Handler->OnIMEComposition(aWindow, wParam, lParam);
-      return true;
+      return gIMM32Handler->OnIMEComposition(aWindow, wParam, lParam, aResult);
     case WM_IME_ENDCOMPOSITION:
       EnsureHandlerInstance();
-      aResult.mConsumed = gIMM32Handler->OnIMEEndComposition(aWindow);
-      return true;
+      return gIMM32Handler->OnIMEEndComposition(aWindow, aResult);
     case WM_IME_CHAR:
-      aResult.mConsumed = OnIMEChar(aWindow, wParam, lParam);
-      return true;
+      return OnIMEChar(aWindow, wParam, lParam, aResult);
     case WM_IME_NOTIFY:
-      aResult.mConsumed = OnIMENotify(aWindow, wParam, lParam);
-      return true;
+      return OnIMENotify(aWindow, wParam, lParam, aResult);
     case WM_IME_REQUEST:
       EnsureHandlerInstance();
-      aResult.mConsumed =
-        gIMM32Handler->OnIMERequest(aWindow, wParam, lParam, &aResult.mResult);
-      return true;
+      return gIMM32Handler->OnIMERequest(aWindow, wParam, lParam, aResult);
     case WM_IME_SELECT:
-      aResult.mConsumed = OnIMESelect(aWindow, wParam, lParam);
-      return true;
+      return OnIMESelect(aWindow, wParam, lParam, aResult);
     case WM_IME_SETCONTEXT:
-      aResult.mConsumed =
-        OnIMESetContext(aWindow, wParam, lParam, &aResult.mResult);
-      return true;
+      return OnIMESetContext(aWindow, wParam, lParam, aResult);
     case WM_KEYDOWN:
       return OnKeyDownEvent(aWindow, wParam, lParam, aResult);
     case WM_CHAR:
       if (!gIMM32Handler) {
         return false;
       }
       aResult.mConsumed = gIMM32Handler->OnChar(aWindow, wParam, lParam);
       // If we consume this message, we should return "processed", otherwise,
@@ -346,38 +335,31 @@ nsIMM32Handler::ProcessMessageForPlugin(
   aResult.mConsumed = false;
   switch (msg) {
     case WM_INPUTLANGCHANGEREQUEST:
     case WM_INPUTLANGCHANGE:
       aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
       return ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult);
     case WM_IME_COMPOSITION:
       EnsureHandlerInstance();
-      aResult.mConsumed =
-        gIMM32Handler->OnIMECompositionOnPlugin(aWindow, wParam, lParam);
-      return true;
+      return gIMM32Handler->OnIMECompositionOnPlugin(aWindow, wParam, lParam,
+                                                     aResult);
     case WM_IME_STARTCOMPOSITION:
       EnsureHandlerInstance();
-      aResult.mConsumed =
-        gIMM32Handler->OnIMEStartCompositionOnPlugin(aWindow, wParam, lParam);
-      return true;
+      return gIMM32Handler->OnIMEStartCompositionOnPlugin(aWindow, wParam,
+                                                          lParam, aResult);
     case WM_IME_ENDCOMPOSITION:
       EnsureHandlerInstance();
-      aResult.mConsumed =
-        gIMM32Handler->OnIMEEndCompositionOnPlugin(aWindow, wParam, lParam);
-      return true;
+      return gIMM32Handler->OnIMEEndCompositionOnPlugin(aWindow, wParam, lParam,
+                                                        aResult);
     case WM_IME_CHAR:
       EnsureHandlerInstance();
-      aResult.mConsumed =
-        gIMM32Handler->OnIMECharOnPlugin(aWindow, wParam, lParam);
-      return true;
+      return gIMM32Handler->OnIMECharOnPlugin(aWindow, wParam, lParam, aResult);
     case WM_IME_SETCONTEXT:
-      aResult.mConsumed =
-        OnIMESetContextOnPlugin(aWindow, wParam, lParam, &aResult.mResult);
-      return true;
+      return OnIMESetContextOnPlugin(aWindow, wParam, lParam, aResult);
     case WM_CHAR:
       if (!gIMM32Handler) {
         return false;
       }
       aResult.mConsumed =
         gIMM32Handler->OnCharOnPlugin(aWindow, wParam, lParam);
       return false;  // is going to be handled by nsWindow.
     case WM_IME_COMPOSITIONFULL:
@@ -412,78 +394,84 @@ nsIMM32Handler::OnInputLangChange(nsWind
   if (mIsComposing) {
     HandleEndComposition(aWindow);
   }
 
   return false;
 }
 
 bool
-nsIMM32Handler::OnIMEStartComposition(nsWindow* aWindow)
+nsIMM32Handler::OnIMEStartComposition(nsWindow* aWindow,
+                                      MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMEStartComposition, hWnd=%08x, mIsComposing=%s\n",
      aWindow->GetWindowHandle(), mIsComposing ? "TRUE" : "FALSE"));
+  aResult.mConsumed = ShouldDrawCompositionStringOurselves();
   if (mIsComposing) {
     NS_WARNING("Composition has been already started");
-    return ShouldDrawCompositionStringOurselves();
+    return true;
   }
 
   nsIMEContext IMEContext(aWindow->GetWindowHandle());
   HandleStartComposition(aWindow, IMEContext);
-  return ShouldDrawCompositionStringOurselves();
+  return true;
 }
 
 bool
 nsIMM32Handler::OnIMEComposition(nsWindow* aWindow,
                                  WPARAM wParam,
-                                 LPARAM lParam)
+                                 LPARAM lParam,
+                                 MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMEComposition, hWnd=%08x, lParam=%08x, mIsComposing=%s\n",
      aWindow->GetWindowHandle(), lParam, mIsComposing ? "TRUE" : "FALSE"));
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMEComposition, GCS_RESULTSTR=%s, GCS_COMPSTR=%s, GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, GCS_CURSORPOS=%s\n",
      lParam & GCS_RESULTSTR  ? "YES" : "no",
      lParam & GCS_COMPSTR    ? "YES" : "no",
      lParam & GCS_COMPATTR   ? "YES" : "no",
      lParam & GCS_COMPCLAUSE ? "YES" : "no",
      lParam & GCS_CURSORPOS  ? "YES" : "no"));
 
   NS_PRECONDITION(!aWindow->PluginHasFocus(),
     "OnIMEComposition should not be called when a plug-in has focus");
 
   nsIMEContext IMEContext(aWindow->GetWindowHandle());
-  return HandleComposition(aWindow, IMEContext, lParam);
+  aResult.mConsumed = HandleComposition(aWindow, IMEContext, lParam);
+  return true;
 }
 
 bool
-nsIMM32Handler::OnIMEEndComposition(nsWindow* aWindow)
+nsIMM32Handler::OnIMEEndComposition(nsWindow* aWindow,
+                                    MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMEEndComposition, hWnd=%08x, mIsComposing=%s\n",
      aWindow->GetWindowHandle(), mIsComposing ? "TRUE" : "FALSE"));
 
+  aResult.mConsumed = ShouldDrawCompositionStringOurselves();
   if (!mIsComposing) {
-    return ShouldDrawCompositionStringOurselves();
+    return true;
   }
 
   // Korean IME posts WM_IME_ENDCOMPOSITION first when we hit space during
   // composition. Then, we should ignore the message and commit the composition
   // string at following WM_IME_COMPOSITION.
   MSG compositionMsg;
   if (WinUtils::PeekMessage(&compositionMsg, aWindow->GetWindowHandle(),
                             WM_IME_STARTCOMPOSITION, WM_IME_COMPOSITION,
                             PM_NOREMOVE) &&
       compositionMsg.message == WM_IME_COMPOSITION &&
       IS_COMMITTING_LPARAM(compositionMsg.lParam)) {
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
       ("IMM32: OnIMEEndComposition, WM_IME_ENDCOMPOSITION is followed by "
        "WM_IME_COMPOSITION, ignoring the message..."));
-    return ShouldDrawCompositionStringOurselves();
+    return true;
   }
 
   // Otherwise, e.g., ChangJie doesn't post WM_IME_COMPOSITION before
   // WM_IME_ENDCOMPOSITION when composition string becomes empty.
   // Then, we should dispatch a compositionupdate event, a text event and
   // a compositionend event.
   // XXX Shouldn't we dispatch the text event with actual or latest composition
   //     string?
@@ -494,52 +482,57 @@ nsIMM32Handler::OnIMEEndComposition(nsWi
 
   mCompositionString.Truncate();
 
   nsIMEContext IMEContext(aWindow->GetWindowHandle());
   DispatchTextEvent(aWindow, IMEContext, false);
 
   HandleEndComposition(aWindow);
 
-  return ShouldDrawCompositionStringOurselves();
+  return true;
 }
 
 /* static */ bool
 nsIMM32Handler::OnIMEChar(nsWindow* aWindow,
                           WPARAM wParam,
-                          LPARAM lParam)
+                          LPARAM lParam,
+                          MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMEChar, hWnd=%08x, char=%08x\n",
      aWindow->GetWindowHandle(), wParam));
 
   // We don't need to fire any text events from here. This method will be
   // called when the composition string of the current IME is not drawn by us
   // and some characters are committed. In that case, the committed string was
   // processed in nsWindow::OnIMEComposition already.
 
-  // We need to return TRUE here so that Windows don't send two WM_CHAR msgs
+  // We need to consume the message so that Windows don't send two WM_CHAR msgs
+  aResult.mConsumed = true;
   return true;
 }
 
 /* static */ bool
-nsIMM32Handler::OnIMECompositionFull(nsWindow* aWindow)
+nsIMM32Handler::OnIMECompositionFull(nsWindow* aWindow,
+                                     MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMECompositionFull, hWnd=%08x\n",
      aWindow->GetWindowHandle()));
 
   // not implement yet
-  return false;
+  aResult.mConsumed = false;
+  return true;
 }
 
 /* static */ bool
 nsIMM32Handler::OnIMENotify(nsWindow* aWindow,
                             WPARAM wParam,
-                            LPARAM lParam)
+                            LPARAM lParam,
+                            MSGResult& aResult)
 {
 #ifdef PR_LOGGING
   switch (wParam) {
     case IMN_CHANGECANDIDATE:
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
         ("IMM32: OnIMENotify, hWnd=%08x, IMN_CHANGECANDIDATE, lParam=%08x\n",
          aWindow->GetWindowHandle(), lParam));
       break;
@@ -607,83 +600,93 @@ nsIMM32Handler::OnIMENotify(nsWindow* aW
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
         ("IMM32: OnIMENotify, hWnd=%08x, IMN_PRIVATE\n",
          aWindow->GetWindowHandle()));
       break;
   }
 #endif // PR_LOGGING
 
   // not implement yet
-  return false;
+  aResult.mConsumed = false;
+  return true;
 }
 
 bool
 nsIMM32Handler::OnIMERequest(nsWindow* aWindow,
                              WPARAM wParam,
                              LPARAM lParam,
-                             LRESULT *oResult)
+                             MSGResult& aResult)
 {
   switch (wParam) {
     case IMR_RECONVERTSTRING:
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
         ("IMM32: OnIMERequest, hWnd=%08x, IMR_RECONVERTSTRING\n",
          aWindow->GetWindowHandle()));
-      return HandleReconvert(aWindow, lParam, oResult);
+      aResult.mConsumed = HandleReconvert(aWindow, lParam, &aResult.mResult);
+      return true;
     case IMR_QUERYCHARPOSITION:
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
         ("IMM32: OnIMERequest, hWnd=%08x, IMR_QUERYCHARPOSITION\n",
          aWindow->GetWindowHandle()));
-      return HandleQueryCharPosition(aWindow, lParam, oResult);
+      aResult.mConsumed =
+        HandleQueryCharPosition(aWindow, lParam, &aResult.mResult);
+      return true;
     case IMR_DOCUMENTFEED:
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
         ("IMM32: OnIMERequest, hWnd=%08x, IMR_DOCUMENTFEED\n",
          aWindow->GetWindowHandle()));
-      return HandleDocumentFeed(aWindow, lParam, oResult);
+      aResult.mConsumed = HandleDocumentFeed(aWindow, lParam, &aResult.mResult);
+      return true;
     default:
       PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
         ("IMM32: OnIMERequest, hWnd=%08x, wParam=%08x\n",
          aWindow->GetWindowHandle(), wParam));
-      return false;
+      aResult.mConsumed = false;
+      return true;
   }
 }
 
 /* static */ bool
 nsIMM32Handler::OnIMESelect(nsWindow* aWindow,
                             WPARAM wParam,
-                            LPARAM lParam)
+                            LPARAM lParam,
+                            MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMESelect, hWnd=%08x, wParam=%08x, lParam=%08x\n",
      aWindow->GetWindowHandle(), wParam, lParam));
 
   // not implement yet
-  return false;
+  aResult.mConsumed = false;
+  return true;
 }
 
 /* static */ bool
 nsIMM32Handler::OnIMESetContext(nsWindow* aWindow,
                                 WPARAM wParam,
                                 LPARAM lParam,
-                                LRESULT *aResult)
+                                MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMESetContext, hWnd=%08x, %s, lParam=%08x\n",
      aWindow->GetWindowHandle(), wParam ? "Active" : "Deactive", lParam));
 
+  aResult.mConsumed = false;
+
   // NOTE: If the aWindow is top level window of the composing window because
   // when a window on deactive window gets focus, WM_IME_SETCONTEXT (wParam is
   // TRUE) is sent to the top level window first.  After that,
   // WM_IME_SETCONTEXT (wParam is FALSE) is sent to the top level window.
   // Finally, WM_IME_SETCONTEXT (wParam is TRUE) is sent to the focused window.
   // The top level window never becomes composing window, so, we can ignore
   // the WM_IME_SETCONTEXT on the top level window.
   if (IsTopLevelWindowOfComposition(aWindow)) {
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
       ("IMM32: OnIMESetContext, hWnd=%08x is top level window\n"));
-    return false;
+    return true;
   }
 
   // When IME context is activating on another window,
   // we should commit the old composition on the old window.
   bool cancelComposition = false;
   if (wParam && gIMM32Handler) {
     cancelComposition =
       gIMM32Handler->CommitCompositionOnPreviousWindow(aWindow);
@@ -694,25 +697,26 @@ nsIMM32Handler::OnIMESetContext(nsWindow
     PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
       ("IMM32: OnIMESetContext, ISC_SHOWUICOMPOSITIONWINDOW is removed\n"));
     lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
   }
 
   // We should sent WM_IME_SETCONTEXT to the DefWndProc here because the
   // ancestor windows shouldn't receive this message.  If they receive the
   // message, we cannot know whether which window is the target of the message.
-  *aResult = ::DefWindowProc(aWindow->GetWindowHandle(),
-                             WM_IME_SETCONTEXT, wParam, lParam);
+  aResult.mResult = ::DefWindowProc(aWindow->GetWindowHandle(),
+                                    WM_IME_SETCONTEXT, wParam, lParam);
 
   // Cancel composition on the new window if we committed our composition on
   // another window.
   if (cancelComposition) {
     CancelComposition(aWindow, true);
   }
 
+  aResult.mConsumed = true;
   return true;
 }
 
 bool
 nsIMM32Handler::OnChar(nsWindow* aWindow,
                        WPARAM wParam,
                        LPARAM lParam)
 {
@@ -742,33 +746,35 @@ nsIMM32Handler::OnChar(nsWindow* aWindow
 
 /****************************************************************************
  * message handlers for plug-in
  ****************************************************************************/
 
 bool
 nsIMM32Handler::OnIMEStartCompositionOnPlugin(nsWindow* aWindow,
                                               WPARAM wParam,
-                                              LPARAM lParam)
+                                              LPARAM lParam,
+                                              MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMEStartCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s\n",
      aWindow->GetWindowHandle(), mIsComposingOnPlugin ? "TRUE" : "FALSE"));
   mIsComposingOnPlugin = true;
   mComposingWindow = aWindow;
-  bool handled =
+  aResult.mConsumed =
     aWindow->DispatchPluginEvent(WM_IME_STARTCOMPOSITION, wParam, lParam,
                                  false);
-  return handled;
+  return true;
 }
 
 bool
 nsIMM32Handler::OnIMECompositionOnPlugin(nsWindow* aWindow,
                                          WPARAM wParam,
-                                         LPARAM lParam)
+                                         LPARAM lParam,
+                                         MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMECompositionOnPlugin, hWnd=%08x, lParam=%08x, mIsComposingOnPlugin=%s\n",
      aWindow->GetWindowHandle(), lParam,
      mIsComposingOnPlugin ? "TRUE" : "FALSE"));
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMECompositionOnPlugin, GCS_RESULTSTR=%s, GCS_COMPSTR=%s, GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, GCS_CURSORPOS=%s\n",
      lParam & GCS_RESULTSTR  ? "YES" : "no",
@@ -781,63 +787,65 @@ nsIMM32Handler::OnIMECompositionOnPlugin
     mIsComposingOnPlugin = false;
     mComposingWindow = nullptr;
   }
   // Continue composition if there is still a string being composed.
   if (IS_COMPOSING_LPARAM(lParam)) {
     mIsComposingOnPlugin = true;
     mComposingWindow = aWindow;
   }
-  bool handled =
+  aResult.mConsumed =
     aWindow->DispatchPluginEvent(WM_IME_COMPOSITION, wParam, lParam, true);
-  return handled;
+  return true;
 }
 
 bool
 nsIMM32Handler::OnIMEEndCompositionOnPlugin(nsWindow* aWindow,
                                             WPARAM wParam,
-                                            LPARAM lParam)
+                                            LPARAM lParam,
+                                            MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMEEndCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s\n",
      aWindow->GetWindowHandle(), mIsComposingOnPlugin ? "TRUE" : "FALSE"));
 
   mIsComposingOnPlugin = false;
   mComposingWindow = nullptr;
-  bool handled =
+  aResult.mConsumed =
     aWindow->DispatchPluginEvent(WM_IME_ENDCOMPOSITION, wParam, lParam,
                                  false);
-  return handled;
+  return true;
 }
 
 bool
 nsIMM32Handler::OnIMECharOnPlugin(nsWindow* aWindow,
                                   WPARAM wParam,
-                                  LPARAM lParam)
+                                  LPARAM lParam,
+                                  MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMECharOnPlugin, hWnd=%08x, char=%08x, scancode=%08x\n",
      aWindow->GetWindowHandle(), wParam, lParam));
 
-  bool handled =
+  aResult.mConsumed =
     aWindow->DispatchPluginEvent(WM_IME_CHAR, wParam, lParam, true);
 
-  if (!handled) {
+  if (!aResult.mConsumed) {
     // Record the WM_CHAR messages which are going to be coming.
     EnsureHandlerInstance();
     EnqueueIMECharRecords(wParam, lParam);
   }
-  return handled;
+  return true;
 }
 
 /* static */ bool
 nsIMM32Handler::OnIMESetContextOnPlugin(nsWindow* aWindow,
                                         WPARAM wParam,
                                         LPARAM lParam,
-                                        LRESULT *aResult)
+                                        MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnIMESetContextOnPlugin, hWnd=%08x, %s, lParam=%08x\n",
      aWindow->GetWindowHandle(), wParam ? "Active" : "Deactive", lParam));
 
   // If the IME context becomes active on a plug-in, we should commit
   // our composition.  And also we should cancel the composition on new
   // window.  Note that if IsTopLevelWindowOfComposition(aWindow) returns
@@ -851,22 +859,23 @@ nsIMM32Handler::OnIMESetContextOnPlugin(
 
   // Dispatch message to the plug-in.
   // XXX When a windowless plug-in gets focus, we should send
   //     WM_IME_SETCONTEXT
   aWindow->DispatchPluginEvent(WM_IME_SETCONTEXT, wParam, lParam, false);
 
   // We should send WM_IME_SETCONTEXT to the DefWndProc here.  It shouldn't
   // be received on ancestor windows, see OnIMESetContext() for the detail.
-  *aResult = ::DefWindowProc(aWindow->GetWindowHandle(),
-                             WM_IME_SETCONTEXT, wParam, lParam);
+  aResult.mResult = ::DefWindowProc(aWindow->GetWindowHandle(),
+                                    WM_IME_SETCONTEXT, wParam, lParam);
 
   // Don't synchronously dispatch the pending events when we receive
   // WM_IME_SETCONTEXT because we get it during plugin destruction.
   // (bug 491848)
+  aResult.mConsumed = true;
   return true;
 }
 
 bool
 nsIMM32Handler::OnCharOnPlugin(nsWindow* aWindow,
                                WPARAM wParam,
                                LPARAM lParam)
 {
--- a/widget/windows/nsIMM32Handler.h
+++ b/widget/windows/nsIMM32Handler.h
@@ -165,52 +165,56 @@ protected:
                                               MSGResult& aResult);
   static bool ProcessMessageForPlugin(nsWindow* aWindow, UINT msg,
                                         WPARAM &wParam, LPARAM &lParam,
                                         MSGResult& aResult);
 
   nsIMM32Handler();
   ~nsIMM32Handler();
 
-  // The result of following On*Event methods means "The message was processed,
-  // don't process the message in the caller (nsWindow)".
+  // On*() methods return true if the caller of message handler shouldn't do
+  // anything anymore.  Otherwise, false.
   bool OnMouseEvent(nsWindow* aWindow, LPARAM lParam, int aAction,
                     MSGResult& aResult);
   static bool OnKeyDownEvent(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
                              MSGResult& aResult);
 
-  // The result of On* methods mean "eat this message" when it's TRUE.
-  bool OnIMEStartComposition(nsWindow* aWindow);
+  bool OnIMEStartComposition(nsWindow* aWindow, MSGResult& aResult);
   bool OnIMEStartCompositionOnPlugin(nsWindow* aWindow,
-                                       WPARAM wParam, LPARAM lParam);
-  bool OnIMEComposition(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
-  bool OnIMECompositionOnPlugin(nsWindow* aWindow,
-                                  WPARAM wParam, LPARAM lParam);
-  bool OnIMEEndComposition(nsWindow* aWindow);
-  bool OnIMEEndCompositionOnPlugin(nsWindow* aWindow,
-                                     WPARAM wParam, LPARAM lParam);
+                                     WPARAM wParam, LPARAM lParam,
+                                     MSGResult& aResult);
+  bool OnIMEComposition(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
+                        MSGResult& aResult);
+  bool OnIMECompositionOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
+                                MSGResult& aResult);
+  bool OnIMEEndComposition(nsWindow* aWindow, MSGResult& aResult);
+  bool OnIMEEndCompositionOnPlugin(nsWindow* aWindow, WPARAM wParam,
+                                   LPARAM lParam, MSGResult& aResult);
   bool OnIMERequest(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
-                      LRESULT *aResult);
-  bool OnIMECharOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
+                    MSGResult& aResult);
+  bool OnIMECharOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
+                         MSGResult& aResult);
   bool OnChar(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
   bool OnCharOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
   bool OnInputLangChange(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
 
   // These message handlers don't use instance members, we should not create
   // the instance by the messages.  So, they should be static.
-  static bool OnIMEChar(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
-  static bool OnIMESetContext(nsWindow* aWindow,
-                                WPARAM wParam, LPARAM lParam,
-                                LRESULT *aResult);
+  static bool OnIMEChar(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
+                        MSGResult& aResult);
+  static bool OnIMESetContext(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
+                              MSGResult& aResult);
   static bool OnIMESetContextOnPlugin(nsWindow* aWindow,
-                                        WPARAM wParam, LPARAM lParam,
-                                        LRESULT *aResult);
-  static bool OnIMECompositionFull(nsWindow* aWindow);
-  static bool OnIMENotify(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
-  static bool OnIMESelect(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
+                                      WPARAM wParam, LPARAM lParam,
+                                      MSGResult& aResult);
+  static bool OnIMECompositionFull(nsWindow* aWindow, MSGResult& aResult);
+  static bool OnIMENotify(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
+                          MSGResult& aResult);
+  static bool OnIMESelect(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
+                          MSGResult& aResult);
 
   // The result of Handle* method mean "Processed" when it's TRUE.
   void HandleStartComposition(nsWindow* aWindow,
                               const nsIMEContext &aIMEContext);
   bool HandleComposition(nsWindow* aWindow, const nsIMEContext &aIMEContext,
                            LPARAM lParam);
   void HandleEndComposition(nsWindow* aWindow);
   bool HandleReconvert(nsWindow* aWindow, LPARAM lParam, LRESULT *oResult);