Bug 840409 part.10 Implement widget::IMEHandler::SetOpenState() and widget::IMEHandler::GetOpenState() r=jimm
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 25 Feb 2013 13:00:06 +0900
changeset 122867 46013161c92803ea460b0d10b4f2ebffbcdf1dd4
parent 122866 398295b6d0e4397aaf0b5f4f3437a57a2a763396
child 122868 9b7c0dfbd87ab23348a2632cb4465ee7499afe2e
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.10 Implement widget::IMEHandler::SetOpenState() and widget::IMEHandler::GetOpenState() r=jimm
widget/windows/WinIMEHandler.cpp
widget/windows/WinIMEHandler.h
widget/windows/nsIMM32Handler.h
widget/windows/nsWindow.cpp
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -163,16 +163,44 @@ IMEHandler::GetUpdatePreference()
   if (sIsInTSFMode) {
     return nsTextStore::GetIMEUpdatePreference();
   }
 #endif //NS_ENABLE_TSF
 
   return nsIMEUpdatePreference(false, false);
 }
 
+void
+IMEHandler::SetOpenState(nsWindow* aWindow, bool aOpen)
+{
+#ifdef NS_ENABLE_TSF
+  if (sIsInTSFMode) {
+    nsTextStore::SetIMEOpenState(aOpen);
+    return;
+  }
+#endif //NS_ENABLE_TSF
+
+  nsIMEContext IMEContext(aWindow->GetWindowHandle());
+  IMEContext.SetOpenState(aOpen);
+}
+
+// static
+bool
+IMEHandler::GetOpenState(nsWindow* aWindow)
+{
+#ifdef NS_ENABLE_TSF
+  if (sIsInTSFMode) {
+    return nsTextStore::GetIMEOpenState();
+  }
+#endif //NS_ENABLE_TSF
+
+  nsIMEContext IMEContext(aWindow->GetWindowHandle());
+  return IMEContext.GetOpenState();
+}
+
 #ifdef DEBUG
 // static
 bool
 IMEHandler::CurrentKeyboardLayoutHasIME()
 {
 #ifdef NS_ENABLE_TSF
   if (sIsInTSFMode) {
     return nsTextStore::CurrentKeyboardLayoutHasIME();
--- a/widget/windows/WinIMEHandler.h
+++ b/widget/windows/WinIMEHandler.h
@@ -63,16 +63,22 @@ public:
                                         uint32_t aNewEnd);
 
   /**
    * Returns update preferences.
    */
   static nsIMEUpdatePreference GetUpdatePreference();
 
   /**
+   * Sets and Gets IME open state.
+   */
+  static void SetOpenState(nsWindow* aWindow, bool aOpen);
+  static bool GetOpenState(nsWindow* aWindow);
+
+  /**
    * "Kakutei-Undo" of ATOK or WXG (both of them are Japanese IME) causes
    * strange WM_KEYDOWN/WM_KEYUP/WM_CHAR message pattern.  So, when this
    * returns true, the caller needs to be careful for processing the messages.
    */
   static bool IsDoingKakuteiUndo(HWND aWnd);
 
 #ifdef DEBUG
   /**
--- a/widget/windows/nsIMM32Handler.h
+++ b/widget/windows/nsIMM32Handler.h
@@ -40,16 +40,32 @@ public:
     return mIMC;
   }
 
   bool IsValid() const
   {
     return !!mIMC;
   }
 
+  void SetOpenState(bool aOpen) const
+  {
+    if (!mIMC) {
+      return;
+    }
+    ::ImmSetOpenStatus(mIMC, aOpen);
+  }
+
+  bool GetOpenState() const
+  {
+    if (!mIMC) {
+      return false;
+    }
+    return (::ImmGetOpenStatus(mIMC) != FALSE);
+  }
+
 protected:
   nsIMEContext()
   {
     NS_ERROR("Don't create nsIMEContext without window handle");
   }
 
   nsIMEContext(const nsIMEContext &aSrc) : mWnd(nullptr), mIMC(nullptr)
   {
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -7412,46 +7412,31 @@ nsWindow::SetInputContext(const InputCon
   // Restore the latest associated context when we cannot get actual context.
   if (!mInputContext.mNativeIMEContext) {
     mInputContext.mNativeIMEContext = nativeIMEContext;
   }
 
   if (enable &&
       mInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE) {
     bool open = (mInputContext.mIMEState.mOpen == IMEState::OPEN);
-#ifdef NS_ENABLE_TSF
-    nsTextStore::SetIMEOpenState(open);
-#endif //NS_ENABLE_TSF
-    nsIMEContext IMEContext(mWnd);
-    if (IMEContext.IsValid()) {
-      ::ImmSetOpenStatus(IMEContext.get(), open);
-    }
+    IMEHandler::SetOpenState(this, open);
   }
 }
 
 NS_IMETHODIMP_(InputContext)
 nsWindow::GetInputContext()
 {
   mInputContext.mIMEState.mOpen = IMEState::CLOSED;
   switch (mInputContext.mIMEState.mEnabled) {
     case IMEState::ENABLED:
-    case IMEState::PLUGIN: {
-      nsIMEContext IMEContext(mWnd);
-      if (IMEContext.IsValid()) {
-        mInputContext.mIMEState.mOpen =
-          ::ImmGetOpenStatus(IMEContext.get()) ? IMEState::OPEN :
-                                                 IMEState::CLOSED;
-      }
-#ifdef NS_ENABLE_TSF
-      if (mInputContext.mIMEState.mOpen == IMEState::CLOSED &&
-          nsTextStore::GetIMEOpenState()) {
+    case IMEState::PLUGIN:
+      if (IMEHandler::GetOpenState(this)) {
         mInputContext.mIMEState.mOpen = IMEState::OPEN;
       }
-#endif //NS_ENABLE_TSF
-    }
+      break;
   }
   return mInputContext;
 }
 
 NS_IMETHODIMP nsWindow::CancelIMEComposition()
 {
   return IMEHandler::NotifyIME(this, REQUEST_TO_CANCEL_COMPOSITION);
 }