Bug 891316 part.6 Use widget::MSGResult in nsIMEHandler r=jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 18 Jul 2013 17:12:31 +0900
changeset 152203 ae37b6b3032123d12828018f408f3fecf24f1c58
parent 152202 d9ddda63490012c3a34a9102d52ffd42eea4909a
child 152204 2bf0e61abaae626eb0e948b7273867ef533ca11a
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.6 Use widget::MSGResult in nsIMEHandler r=jimm
widget/windows/WinIMEHandler.cpp
widget/windows/nsIMM32Handler.cpp
widget/windows/nsIMM32Handler.h
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -109,17 +109,17 @@ IMEHandler::ProcessMessage(nsWindow* aWi
       aResult.mConsumed = true;
       return true;
     }
     return false;
   }
 #endif // #ifdef NS_ENABLE_TSF
 
   return nsIMM32Handler::ProcessMessage(aWindow, aMessage, aWParam, aLParam,
-                                        &aResult.mResult, aResult.mConsumed);
+                                        aResult);
 }
 
 // static
 bool
 IMEHandler::IsComposing()
 {
 #ifdef NS_ENABLE_TSF
   if (IsTSFAvailable()) {
--- a/widget/windows/nsIMM32Handler.cpp
+++ b/widget/windows/nsIMM32Handler.cpp
@@ -6,16 +6,17 @@
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif // MOZ_LOGGING
 #include "prlog.h"
 
 #include "nsIMM32Handler.h"
 #include "nsWindow.h"
+#include "nsWindowDefs.h"
 #include "WinUtils.h"
 #include "KeyboardLayout.h"
 #include <algorithm>
 
 using namespace mozilla::widget;
 
 static nsIMM32Handler* gIMM32Handler = nullptr;
 
@@ -234,167 +235,164 @@ nsIMM32Handler::CancelComposition(nsWind
     IMEContext.Disassociate();
   }
 }
 
 /* static */ bool
 nsIMM32Handler::ProcessInputLangChangeMessage(nsWindow* aWindow,
                                               WPARAM wParam,
                                               LPARAM lParam,
-                                              LRESULT *aRetValue,
-                                              bool &aEatMessage)
+                                              MSGResult& aResult)
 {
-  *aRetValue = 0;
-  aEatMessage = false;
+  aResult.mResult = 0;
+  aResult.mConsumed = false;
   // We don't need to create the instance of the handler here.
   if (gIMM32Handler) {
-    aEatMessage = gIMM32Handler->OnInputLangChange(aWindow, wParam, lParam);
+    aResult.mConsumed =
+      gIMM32Handler->OnInputLangChange(aWindow, wParam, lParam);
   }
   InitKeyboardLayout(reinterpret_cast<HKL>(lParam));
   // We can release the instance here, because the instance may be never
   // used. E.g., the new keyboard layout may not use IME, or it may use TSF.
   Terminate();
   // Don't return as "processed", the messages should be processed on nsWindow
   // too.
   return false;
 }
 
 /* static */ bool
 nsIMM32Handler::ProcessMessage(nsWindow* aWindow, UINT msg,
                                WPARAM &wParam, LPARAM &lParam,
-                               LRESULT *aRetValue, bool &aEatMessage)
+                               MSGResult& aResult)
 {
   // XXX We store the composing window in mComposingWindow.  If IME messages are
   // sent to different window, we should commit the old transaction.  And also
   // if the new window handle is not focused, probably, we should not start
   // the composition, however, such case should not be, it's just bad scenario.
 
   // When a plug-in has focus or compsition, we should dispatch the IME events
   // to the plug-in.
   if (aWindow->PluginHasFocus() || IsComposingOnPlugin()) {
-      return ProcessMessageForPlugin(aWindow, msg, wParam, lParam, aRetValue,
-                                   aEatMessage);
+      return ProcessMessageForPlugin(aWindow, msg, wParam, lParam, aResult);
   }
 
-  *aRetValue = 0;
+  aResult.mResult = 0;
   switch (msg) {
     case WM_LBUTTONDOWN:
     case WM_MBUTTONDOWN:
     case WM_RBUTTONDOWN: {
       // We don't need to create the instance of the handler here.
-      if (!gIMM32Handler)
-        return false;
-      if (!gIMM32Handler->OnMouseEvent(aWindow, lParam,
-                            msg == WM_LBUTTONDOWN ? IMEMOUSE_LDOWN :
-                            msg == WM_MBUTTONDOWN ? IMEMOUSE_MDOWN :
-                                                    IMEMOUSE_RDOWN)) {
+      if (!gIMM32Handler) {
         return false;
       }
-      aEatMessage = false;
-      return true;
+      return gIMM32Handler->OnMouseEvent(aWindow, lParam,
+                              msg == WM_LBUTTONDOWN ? IMEMOUSE_LDOWN :
+                              msg == WM_MBUTTONDOWN ? IMEMOUSE_MDOWN :
+                                                      IMEMOUSE_RDOWN, aResult);
     }
     case WM_INPUTLANGCHANGE:
-      return ProcessInputLangChangeMessage(aWindow, wParam, lParam,
-                                           aRetValue, aEatMessage);
+      return ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult);
     case WM_IME_STARTCOMPOSITION:
       EnsureHandlerInstance();
-      aEatMessage = gIMM32Handler->OnIMEStartComposition(aWindow);
+      aResult.mConsumed = gIMM32Handler->OnIMEStartComposition(aWindow);
       return true;
     case WM_IME_COMPOSITION:
       EnsureHandlerInstance();
-      aEatMessage = gIMM32Handler->OnIMEComposition(aWindow, wParam, lParam);
+      aResult.mConsumed =
+        gIMM32Handler->OnIMEComposition(aWindow, wParam, lParam);
       return true;
     case WM_IME_ENDCOMPOSITION:
       EnsureHandlerInstance();
-      aEatMessage = gIMM32Handler->OnIMEEndComposition(aWindow);
+      aResult.mConsumed = gIMM32Handler->OnIMEEndComposition(aWindow);
       return true;
     case WM_IME_CHAR:
-      aEatMessage = OnIMEChar(aWindow, wParam, lParam);
+      aResult.mConsumed = OnIMEChar(aWindow, wParam, lParam);
       return true;
     case WM_IME_NOTIFY:
-      aEatMessage = OnIMENotify(aWindow, wParam, lParam);
+      aResult.mConsumed = OnIMENotify(aWindow, wParam, lParam);
       return true;
     case WM_IME_REQUEST:
       EnsureHandlerInstance();
-      aEatMessage =
-        gIMM32Handler->OnIMERequest(aWindow, wParam, lParam, aRetValue);
+      aResult.mConsumed =
+        gIMM32Handler->OnIMERequest(aWindow, wParam, lParam, &aResult.mResult);
       return true;
     case WM_IME_SELECT:
-      aEatMessage = OnIMESelect(aWindow, wParam, lParam);
+      aResult.mConsumed = OnIMESelect(aWindow, wParam, lParam);
       return true;
     case WM_IME_SETCONTEXT:
-      aEatMessage = OnIMESetContext(aWindow, wParam, lParam, aRetValue);
+      aResult.mConsumed =
+        OnIMESetContext(aWindow, wParam, lParam, &aResult.mResult);
       return true;
     case WM_KEYDOWN:
-      return OnKeyDownEvent(aWindow, wParam, lParam, aEatMessage);
+      return OnKeyDownEvent(aWindow, wParam, lParam, aResult);
     case WM_CHAR:
       if (!gIMM32Handler) {
         return false;
       }
-      aEatMessage = gIMM32Handler->OnChar(aWindow, wParam, lParam);
-      // If we eat this message, we should return "processed", otherwise,
+      aResult.mConsumed = gIMM32Handler->OnChar(aWindow, wParam, lParam);
+      // If we consume this message, we should return "processed", otherwise,
       // the message should be handled on nsWindow, so, we should return
       // "not processed" at that time.
-      return aEatMessage;
+      return aResult.mConsumed;
     default:
       return false;
   };
 }
 
 /* static */ bool
 nsIMM32Handler::ProcessMessageForPlugin(nsWindow* aWindow, UINT msg,
                                         WPARAM &wParam, LPARAM &lParam,
-                                        LRESULT *aRetValue,
-                                        bool &aEatMessage)
+                                        MSGResult& aResult)
 {
-  *aRetValue = 0;
-  aEatMessage = false;
+  aResult.mResult = 0;
+  aResult.mConsumed = false;
   switch (msg) {
     case WM_INPUTLANGCHANGEREQUEST:
     case WM_INPUTLANGCHANGE:
       aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
-      return ProcessInputLangChangeMessage(aWindow, wParam, lParam,
-                                           aRetValue, aEatMessage);
+      return ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult);
     case WM_IME_COMPOSITION:
       EnsureHandlerInstance();
-      aEatMessage =
+      aResult.mConsumed =
         gIMM32Handler->OnIMECompositionOnPlugin(aWindow, wParam, lParam);
       return true;
     case WM_IME_STARTCOMPOSITION:
       EnsureHandlerInstance();
-      aEatMessage =
+      aResult.mConsumed =
         gIMM32Handler->OnIMEStartCompositionOnPlugin(aWindow, wParam, lParam);
       return true;
     case WM_IME_ENDCOMPOSITION:
       EnsureHandlerInstance();
-      aEatMessage =
+      aResult.mConsumed =
         gIMM32Handler->OnIMEEndCompositionOnPlugin(aWindow, wParam, lParam);
       return true;
     case WM_IME_CHAR:
       EnsureHandlerInstance();
-      aEatMessage =
+      aResult.mConsumed =
         gIMM32Handler->OnIMECharOnPlugin(aWindow, wParam, lParam);
       return true;
     case WM_IME_SETCONTEXT:
-      aEatMessage = OnIMESetContextOnPlugin(aWindow, wParam, lParam, aRetValue);
+      aResult.mConsumed =
+        OnIMESetContextOnPlugin(aWindow, wParam, lParam, &aResult.mResult);
       return true;
     case WM_CHAR:
       if (!gIMM32Handler) {
         return false;
       }
-      aEatMessage =
+      aResult.mConsumed =
         gIMM32Handler->OnCharOnPlugin(aWindow, wParam, lParam);
       return false;  // is going to be handled by nsWindow.
     case WM_IME_COMPOSITIONFULL:
     case WM_IME_CONTROL:
     case WM_IME_KEYDOWN:
     case WM_IME_KEYUP:
     case WM_IME_REQUEST:
     case WM_IME_SELECT:
-      aEatMessage = aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
+      aResult.mConsumed =
+        aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
       return true;
   }
   return false;
 }
 
 /****************************************************************************
  * message handlers
  ****************************************************************************/
@@ -1932,18 +1930,21 @@ nsIMM32Handler::ResolveIMECaretPos(nsIWi
   if (aReferenceWidget)
     aOutRect.MoveBy(aReferenceWidget->WidgetToScreenOffset());
 
   if (aNewOriginWidget)
     aOutRect.MoveBy(-aNewOriginWidget->WidgetToScreenOffset());
 }
 
 bool
-nsIMM32Handler::OnMouseEvent(nsWindow* aWindow, LPARAM lParam, int aAction)
+nsIMM32Handler::OnMouseEvent(nsWindow* aWindow, LPARAM lParam, int aAction,
+                             MSGResult& aResult)
 {
+  aResult.mConsumed = false; // always call next wndprc
+
   if (!sWM_MSIME_MOUSE || !mIsComposing ||
       !ShouldDrawCompositionStringOurselves()) {
     return false;
   }
 
   nsIntPoint cursor(LOWORD(lParam), HIWORD(lParam));
   nsQueryContentEvent charAtPt(true, NS_QUERY_CHARACTER_AT_POINT, aWindow);
   aWindow->InitEvent(charAtPt, &cursor);
@@ -1991,22 +1992,22 @@ nsIMM32Handler::OnMouseEvent(nsWindow* a
   nsIMEContext IMEContext(aWindow->GetWindowHandle());
   return ::SendMessageW(imeWnd, sWM_MSIME_MOUSE,
                         MAKELONG(MAKEWORD(aAction, positioning), offset),
                         (LPARAM) IMEContext.get()) == 1;
 }
 
 /* static */ bool
 nsIMM32Handler::OnKeyDownEvent(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
-                               bool &aEatMessage)
+                               MSGResult& aResult)
 {
   PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
     ("IMM32: OnKeyDownEvent, hWnd=%08x, wParam=%08x, lParam=%08x\n",
      aWindow->GetWindowHandle(), wParam, lParam));
-  aEatMessage = false;
+  aResult.mConsumed = false;
   switch (wParam) {
     case VK_TAB:
     case VK_PRIOR:
     case VK_NEXT:
     case VK_END:
     case VK_HOME:
     case VK_LEFT:
     case VK_UP:
--- a/widget/windows/nsIMM32Handler.h
+++ b/widget/windows/nsIMM32Handler.h
@@ -11,16 +11,24 @@
 #include "nsString.h"
 #include "nsGUIEvent.h"
 #include "nsTArray.h"
 
 class nsIWidget;
 class nsWindow;
 struct nsIntRect;
 
+namespace mozilla {
+namespace widget {
+
+struct MSGResult;
+
+} // namespace widget
+} // namespace mozilla
+
 class nsIMEContext
 {
 public:
   nsIMEContext(HWND aWnd) : mWnd(aWnd)
   {
     mIMC = ::ImmGetContext(mWnd);
   }
 
@@ -96,28 +104,25 @@ protected:
   }
 
   HWND mWnd;
   HIMC mIMC;
 };
 
 class nsIMM32Handler
 {
+  typedef mozilla::widget::MSGResult MSGResult;
 public:
   static void Initialize();
   static void Terminate();
-  // The result of Process* method mean "The message was processed, don't
-  // process the message in the caller (nsWindow)" when it's TRUE.  At that
-  // time, aEatMessage means that the message should be passed to next WndProc
-  // when it's FALSE, otherwise, the message should be eaten by us.  When the
-  // result is FALSE, aEatMessage doesn't have any meaning.  Then, the caller
-  // should continue to process the message.
+
+  // If Process*() returns true, the caller shouldn't do anything anymore.
   static bool ProcessMessage(nsWindow* aWindow, UINT msg,
-                               WPARAM &wParam, LPARAM &lParam,
-                               LRESULT *aRetValue, bool &aEatMessage);
+                             WPARAM& wParam, LPARAM& lParam,
+                             MSGResult& aResult);
   static bool IsComposing()
   {
     return IsComposingOnOurEditor() || IsComposingOnPlugin();
   }
   static bool IsComposingOn(nsWindow* aWindow)
   {
     return IsComposing() && IsComposingWindow(aWindow);
   }
@@ -152,31 +157,30 @@ protected:
    * In this method, the top level window means in all windows, not only in all
    * OUR windows.  I.e., if the aWindow is embedded, this always returns FALSE.
    */
   static bool IsTopLevelWindowOfComposition(nsWindow* aWindow);
 
   static bool ProcessInputLangChangeMessage(nsWindow* aWindow,
                                               WPARAM wParam,
                                               LPARAM lParam,
-                                              LRESULT *aRetValue,
-                                              bool &aEatMessage);
+                                              MSGResult& aResult);
   static bool ProcessMessageForPlugin(nsWindow* aWindow, UINT msg,
                                         WPARAM &wParam, LPARAM &lParam,
-                                        LRESULT *aRetValue,
-                                        bool &aEatMessage);
+                                        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)".
-  bool OnMouseEvent(nsWindow* aWindow, LPARAM lParam, int aAction);
+  bool OnMouseEvent(nsWindow* aWindow, LPARAM lParam, int aAction,
+                    MSGResult& aResult);
   static bool OnKeyDownEvent(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
-                               bool &aEatMessage);
+                             MSGResult& aResult);
 
   // The result of On* methods mean "eat this message" when it's TRUE.
   bool OnIMEStartComposition(nsWindow* aWindow);
   bool OnIMEStartCompositionOnPlugin(nsWindow* aWindow,
                                        WPARAM wParam, LPARAM lParam);
   bool OnIMEComposition(nsWindow* aWindow, WPARAM wParam, LPARAM lParam);
   bool OnIMECompositionOnPlugin(nsWindow* aWindow,
                                   WPARAM wParam, LPARAM lParam);