Bug 1081993 - WinIMEHandler should notify nsIMM32Handler of some notifications even in TSF mode when IMM IME is active. r=emk, a=lsblakk
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 16 Oct 2014 10:02:29 +0900
changeset 233442 9936bcca134f807e9295c6b1db0d0497e3525fec
parent 233441 de32c9a4888da1b596d7b59d380d53294f2954d6
child 233443 1f25ba89a1cee67330163d57a5296bc97ee23b61
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk, lsblakk
bugs1081993
milestone35.0a2
Bug 1081993 - WinIMEHandler should notify nsIMM32Handler of some notifications even in TSF mode when IMM IME is active. r=emk, a=lsblakk
widget/windows/WinIMEHandler.cpp
widget/windows/WinIMEHandler.h
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -124,70 +124,104 @@ IMEHandler::ProcessMessage(nsWindow* aWi
     }
   }
 #endif // #ifdef NS_ENABLE_TSF
 
   return nsIMM32Handler::ProcessMessage(aWindow, aMessage, aWParam, aLParam,
                                         aResult);
 }
 
+#ifdef NS_ENABLE_TSF
+// static
+bool
+IMEHandler::IsIMMActive()
+{
+  return nsTextStore::IsIMM_IME();
+}
+#endif // #ifdef NS_ENABLE_TSF
+
 // static
 bool
 IMEHandler::IsComposing()
 {
 #ifdef NS_ENABLE_TSF
   if (IsTSFAvailable()) {
-    return nsTextStore::IsComposing();
+    return nsTextStore::IsComposing() || nsIMM32Handler::IsComposing();
   }
 #endif // #ifdef NS_ENABLE_TSF
 
   return nsIMM32Handler::IsComposing();
 }
 
 // static
 bool
 IMEHandler::IsComposingOn(nsWindow* aWindow)
 {
 #ifdef NS_ENABLE_TSF
   if (IsTSFAvailable()) {
-    return nsTextStore::IsComposingOn(aWindow);
+    return nsTextStore::IsComposingOn(aWindow) ||
+           nsIMM32Handler::IsComposingOn(aWindow);
   }
 #endif // #ifdef NS_ENABLE_TSF
 
   return nsIMM32Handler::IsComposingOn(aWindow);
 }
 
 // static
 nsresult
 IMEHandler::NotifyIME(nsWindow* aWindow,
                       const IMENotification& aIMENotification)
 {
 #ifdef NS_ENABLE_TSF
   if (IsTSFAvailable()) {
     switch (aIMENotification.mMessage) {
-      case NOTIFY_IME_OF_SELECTION_CHANGE:
-        return nsTextStore::OnSelectionChange();
+      case NOTIFY_IME_OF_SELECTION_CHANGE: {
+        nsresult rv = nsTextStore::OnSelectionChange();
+        // If IMM IME is active, we need to notify nsIMM32Handler of updating
+        // composition change.  It will adjust candidate window position or
+        // composition window position.
+        if (IsIMMActive()) {
+          nsIMM32Handler::OnUpdateComposition(aWindow);
+        }
+        return rv;
+      }
+      case NOTIFY_IME_OF_COMPOSITION_UPDATE:
+        // If IMM IME is active, we need to notify nsIMM32Handler of updating
+        // composition change.  It will adjust candidate window position or
+        // composition window position.
+        if (IsIMMActive()) {
+          nsIMM32Handler::OnUpdateComposition(aWindow);
+        }
+        return NS_OK;
       case NOTIFY_IME_OF_TEXT_CHANGE:
         return nsTextStore::OnTextChange(aIMENotification);
       case NOTIFY_IME_OF_FOCUS:
         return nsTextStore::OnFocusChange(true, aWindow,
                                           aWindow->GetInputContext());
       case NOTIFY_IME_OF_BLUR:
         return nsTextStore::OnFocusChange(false, aWindow,
                                           aWindow->GetInputContext());
       case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
+        // If IMM IME is active, we should send a mouse button event via IMM.
+        if (IsIMMActive()) {
+          return nsIMM32Handler::OnMouseButtonEvent(aWindow, aIMENotification);
+        }
         return nsTextStore::OnMouseButtonEvent(aIMENotification);
       case REQUEST_TO_COMMIT_COMPOSITION:
         if (nsTextStore::IsComposingOn(aWindow)) {
           nsTextStore::CommitComposition(false);
+        } else if (IsIMMActive()) {
+          nsIMM32Handler::CommitComposition(aWindow);
         }
         return NS_OK;
       case REQUEST_TO_CANCEL_COMPOSITION:
         if (nsTextStore::IsComposingOn(aWindow)) {
           nsTextStore::CommitComposition(true);
+        } else if (IsIMMActive()) {
+          nsIMM32Handler::CancelComposition(aWindow);
         }
         return NS_OK;
       case NOTIFY_IME_OF_POSITION_CHANGE:
         return nsTextStore::OnLayoutChange();
       default:
         return NS_ERROR_NOT_IMPLEMENTED;
     }
   }
@@ -234,17 +268,17 @@ IMEHandler::GetUpdatePreference()
   return nsIMM32Handler::GetIMEUpdatePreference();
 }
 
 // static
 bool
 IMEHandler::GetOpenState(nsWindow* aWindow)
 {
 #ifdef NS_ENABLE_TSF
-  if (IsTSFAvailable()) {
+  if (IsTSFAvailable() && !IsIMMActive()) {
     return nsTextStore::GetIMEOpenState();
   }
 #endif //NS_ENABLE_TSF
 
   nsIMEContext IMEContext(aWindow->GetWindowHandle());
   return IMEContext.GetOpenState();
 }
 
--- a/widget/windows/WinIMEHandler.h
+++ b/widget/windows/WinIMEHandler.h
@@ -117,15 +117,16 @@ private:
                                     const nsAString& aHTMLInputType);
   static bool sIsInTSFMode;
   // If sIMMEnabled is false, any IME messages are not handled in TSF mode.
   // Additionally, IME context is always disassociated from focused window.
   static bool sIsIMMEnabled;
   static bool sPluginHasFocus;
 
   static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); }
+  static bool IsIMMActive();
 #endif // #ifdef NS_ENABLE_TSF
 };
 
 } // namespace widget
 } // namespace mozilla
 
 #endif // #ifndef WinIMEHandler_h_