Bug 840409 part.13 Implement widget::IMEHandler::IsIMEEnabled() which checks whether the state indicates IME available or not r=jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 25 Feb 2013 13:00:07 +0900
changeset 122870 94813538595cedad90c2fdc9b7669e4b9ba9bc5b
parent 122869 4b6be794fbb02c5cb8808f9425a442ccdc8d7d9a
child 122871 5fe283c4cd7f76bc147468d10cf4ce2462558384
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs840409
milestone22.0a1
Bug 840409 part.13 Implement widget::IMEHandler::IsIMEEnabled() which checks whether the state indicates IME available or not r=jimm
widget/windows/WinIMEHandler.cpp
widget/windows/WinIMEHandler.h
widget/windows/nsWindow.cpp
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -46,16 +46,31 @@ IMEHandler::Terminate()
   }
 #endif // #ifdef NS_ENABLE_TSF
 
   nsIMM32Handler::Terminate();
 }
 
 // static
 bool
+IMEHandler::IsIMEEnabled(const InputContext& aInputContext)
+{
+  return IsIMEEnabled(aInputContext.mIMEState.mEnabled);
+}
+
+// static
+bool
+IMEHandler::IsIMEEnabled(IMEState::Enabled aIMEState)
+{
+  return (aIMEState == mozilla::widget::IMEState::ENABLED ||
+          aIMEState == mozilla::widget::IMEState::PLUGIN);
+}
+
+// static
+bool
 IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage,
                            WPARAM& aWParam, LPARAM& aLParam,
                            LRESULT* aRetValue, bool& aEatMessage)
 {
 #ifdef NS_ENABLE_TSF
   if (sIsInTSFMode) {
     if (aMessage == WM_USER_TSF_TEXTCHANGE) {
       nsTextStore::OnTextChangeMsg();
@@ -194,18 +209,17 @@ IMEHandler::OnDestroyWindow(nsWindow* aW
 
 // static
 void
 IMEHandler::SetInputContext(nsWindow* aWindow, InputContext& aInputContext)
 {
   // FYI: If there is no composition, this call will do nothing.
   NotifyIME(aWindow, REQUEST_TO_COMMIT_COMPOSITION);
 
-  bool enable = (aInputContext.mIMEState.mEnabled == IMEState::ENABLED ||
-                 aInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
+  bool enable = IsIMEEnabled(aInputContext);
   bool adjustOpenState = (enable &&
     aInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE);
   bool open = (adjustOpenState &&
     aInputContext.mIMEState.mOpen == IMEState::OPEN);
 
   aInputContext.mNativeIMEContext = nullptr;
 
 #ifdef NS_ENABLE_TSF
--- a/widget/windows/WinIMEHandler.h
+++ b/widget/windows/WinIMEHandler.h
@@ -3,39 +3,43 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef WinIMEHandler_h_
 #define WinIMEHandler_h_
 
 #include "nscore.h"
 #include "nsEvent.h"
+#include "nsIWidget.h"
 #include <windows.h>
 
 class nsWindow;
-struct nsIMEUpdatePreference;
 
 namespace mozilla {
 namespace widget {
 
-struct InputContext;
-
 /**
  * IMEHandler class is a mediator class.  On Windows, there are two IME API
  * sets: One is IMM which is legacy API set. The other is TSF which is modern
  * API set. By using this class, non-IME handler classes don't need to worry
  * that we're in which mode.
  */
 class IMEHandler MOZ_FINAL
 {
 public:
   static void Initialize();
   static void Terminate();
 
   /**
+   * Returns true if the context or IME state is enabled.  Otherwise, false.
+   */
+  static bool IsIMEEnabled(const InputContext& aInputContext);
+  static bool IsIMEEnabled(IMEState::Enabled aIMEState);
+
+  /**
    * When the message is not needed to handle anymore by the caller, this
    * returns true.  Otherwise, false.
    * Additionally, if aEatMessage is true, the caller shouldn't call next
    * wndproc anymore.
    */
   static bool ProcessMessage(nsWindow* aWindow, UINT aMessage,
                              WPARAM& aWParam, LPARAM& aLParam,
                              LRESULT* aRetValue, bool& aEatMessage);
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -163,17 +163,16 @@
 #include "nsWindowDefs.h"
 
 #include "nsCrashOnException.h"
 #include "nsIXULRuntime.h"
 
 #include "nsIContent.h"
 
 #include "mozilla/HangMonitor.h"
-#include "nsIMM32Handler.h"
 #include "WinIMEHandler.h"
 
 using namespace mozilla::widget;
 using namespace mozilla::layers;
 using namespace mozilla;
 
 /**************************************************************
  **************************************************************
@@ -6475,17 +6474,17 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
 
 #ifdef DEBUG
   //PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("In OnKeyDown virt: %d\n", DOMKeyCode));
 #endif
 
   static bool sRedirectedKeyDownEventPreventedDefault = false;
   bool noDefault;
   if (aFakeCharMessage || !IsRedirectedKeyDownMessage(aMsg)) {
-    nsIMEContext IMEContext(mWnd);
+    bool isIMEEnabled = IMEHandler::IsIMEEnabled(mInputContext);
     nsKeyEvent keydownEvent(true, NS_KEY_DOWN, this);
     keydownEvent.keyCode = DOMKeyCode;
     InitKeyEvent(keydownEvent, nativeKey, aModKeyState);
     noDefault = DispatchKeyEvent(keydownEvent, &aMsg);
     if (aEventDispatched) {
       *aEventDispatched = true;
     }
 
@@ -6493,19 +6492,18 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
     // focus is moved from a non-editable editor to an editor by keydown
     // event handler), WM_CHAR and WM_SYSCHAR shouldn't cause first character
     // inputting if IME is opened.  But then, we should redirect the native
     // keydown message to IME.
     // However, note that if focus has been already moved to another
     // application, we shouldn't redirect the message to it because the keydown
     // message is processed by us, so, nobody shouldn't process it.
     HWND focusedWnd = ::GetFocus();
-    nsIMEContext newIMEContext(mWnd);
     if (!noDefault && !aFakeCharMessage && focusedWnd && !PluginHasFocus() &&
-        !IMEContext.get() && newIMEContext.get()) {
+        !isIMEEnabled && IMEHandler::IsIMEEnabled(mInputContext)) {
       RemoveNextCharMessage(focusedWnd);
 
       INPUT keyinput;
       keyinput.type = INPUT_KEYBOARD;
       keyinput.ki.wVk = aMsg.wParam;
       keyinput.ki.wScan = WinUtils::GetScanCode(aMsg.lParam);
       keyinput.ki.dwFlags = KEYEVENTF_SCANCODE;
       if (WinUtils::IsExtendedScanCode(aMsg.lParam)) {
@@ -7385,23 +7383,20 @@ nsWindow::SetInputContext(const InputCon
   IMEHandler::SetInputContext(this, newInputContext);
   mInputContext = newInputContext;
 }
 
 NS_IMETHODIMP_(InputContext)
 nsWindow::GetInputContext()
 {
   mInputContext.mIMEState.mOpen = IMEState::CLOSED;
-  switch (mInputContext.mIMEState.mEnabled) {
-    case IMEState::ENABLED:
-    case IMEState::PLUGIN:
-      if (IMEHandler::GetOpenState(this)) {
-        mInputContext.mIMEState.mOpen = IMEState::OPEN;
-      }
-      break;
+  if (IMEHandler::IsIMEEnabled(mInputContext) && IMEHandler::GetOpenState(this)) {
+    mInputContext.mIMEState.mOpen = IMEState::OPEN;
+  } else {
+    mInputContext.mIMEState.mOpen = IMEState::CLOSED;
   }
   return mInputContext;
 }
 
 NS_IMETHODIMP nsWindow::CancelIMEComposition()
 {
   return IMEHandler::NotifyIME(this, REQUEST_TO_CANCEL_COMPOSITION);
 }