Bug 1130935 part.7 Set composition font when selection is changed since some IMEs need to be set candidate window position even before WM_IME_STARTCOMPOSITION r=emk
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 15 May 2015 10:18:08 +0900
changeset 244013 82939d59771ad5bdfc607e4d9536b7659c1bc038
parent 244012 7097594f13d4ed7bda8479fc97934019c771ad92
child 244014 d01e90b449c943d6da7967ee45a22ab955cf51c5
push id28762
push usercbook@mozilla.com
push dateFri, 15 May 2015 15:40:04 +0000
treeherdermozilla-central@1a8343f8ed83 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1130935
milestone41.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 1130935 part.7 Set composition font when selection is changed since some IMEs need to be set candidate window position even before WM_IME_STARTCOMPOSITION r=emk
widget/windows/WinIMEHandler.cpp
widget/windows/nsIMM32Handler.cpp
widget/windows/nsIMM32Handler.h
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -175,16 +175,17 @@ IMEHandler::NotifyIME(nsWindow* aWindow,
     switch (aIMENotification.mMessage) {
       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);
+          nsIMM32Handler::OnSelectionChange(aWindow, aIMENotification);
         }
         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()) {
@@ -233,16 +234,19 @@ IMEHandler::NotifyIME(nsWindow* aWindow,
       return NS_OK;
     case REQUEST_TO_CANCEL_COMPOSITION:
       nsIMM32Handler::CancelComposition(aWindow);
       return NS_OK;
     case NOTIFY_IME_OF_POSITION_CHANGE:
     case NOTIFY_IME_OF_COMPOSITION_UPDATE:
       nsIMM32Handler::OnUpdateComposition(aWindow);
       return NS_OK;
+    case NOTIFY_IME_OF_SELECTION_CHANGE:
+      nsIMM32Handler::OnSelectionChange(aWindow, aIMENotification);
+      return NS_OK;
     case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
       return nsIMM32Handler::OnMouseButtonEvent(aWindow, aIMENotification);
 #ifdef NS_ENABLE_TSF
     case NOTIFY_IME_OF_BLUR:
       // If a plugin gets focus while TSF has focus, we need to notify TSF of
       // the blur.
       if (nsTextStore::ThinksHavingFocus()) {
         return nsTextStore::OnFocusChange(false, aWindow,
--- a/widget/windows/nsIMM32Handler.cpp
+++ b/widget/windows/nsIMM32Handler.cpp
@@ -263,16 +263,17 @@ nsIMM32Handler::GetKeyboardCodePage()
 }
 
 /* static */
 nsIMEUpdatePreference
 nsIMM32Handler::GetIMEUpdatePreference()
 {
   return nsIMEUpdatePreference(
     nsIMEUpdatePreference::NOTIFY_POSITION_CHANGE |
+    nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE |
     nsIMEUpdatePreference::NOTIFY_MOUSE_BUTTON_EVENT_ON_CHAR);
 }
 
 // used for checking the lParam of WM_IME_COMPOSITION
 #define IS_COMPOSING_LPARAM(lParam) \
   ((lParam) & (GCS_COMPSTR | GCS_COMPATTR | GCS_COMPCLAUSE | GCS_CURSORPOS))
 #define IS_COMMITTING_LPARAM(lParam) ((lParam) & GCS_RESULTSTR)
 // Some IMEs (e.g., the standard IME for Korean) don't have caret position,
@@ -384,16 +385,42 @@ nsIMM32Handler::OnUpdateComposition(nsWi
   if (aWindow->PluginHasFocus()) {
     return;
   }
 
   nsIMEContext IMEContext(aWindow->GetWindowHandle());
   gIMM32Handler->SetIMERelatedWindowsPos(aWindow, IMEContext);
 }
 
+// static
+void
+nsIMM32Handler::OnSelectionChange(nsWindow* aWindow,
+                                  const IMENotification& aIMENotification)
+{
+  if (aIMENotification.mSelectionChangeData.mCausedByComposition) {
+    return;
+  }
+
+  switch (sCodePage) {
+    case 932: // Japanese Shift-JIS
+    case 936: // Simlified Chinese GBK
+    case 949: // Korean
+    case 950: // Traditional Chinese Big5
+      EnsureHandlerInstance();
+      break;
+    default:
+      return;
+  }
+
+  // Like Navi-Bar of ATOK, some IMEs may require proper composition font even
+  // before sending WM_IME_STARTCOMPOSITION.
+  nsIMEContext IMEContext(aWindow->GetWindowHandle());
+  gIMM32Handler->AdjustCompositionFont(IMEContext,
+                   aIMENotification.mSelectionChangeData.GetWritingMode());
+}
 
 /* static */ bool
 nsIMM32Handler::ProcessInputLangChangeMessage(nsWindow* aWindow,
                                               WPARAM wParam,
                                               LPARAM lParam,
                                               MSGResult& aResult)
 {
   aResult.mResult = 0;
--- a/widget/windows/nsIMM32Handler.h
+++ b/widget/windows/nsIMM32Handler.h
@@ -141,16 +141,18 @@ public:
 #endif
 
   // If aForce is TRUE, these methods doesn't check whether we have composition
   // or not.  If you don't set it to TRUE, these method doesn't commit/cancel
   // the composition on uexpected window.
   static void CommitComposition(nsWindow* aWindow, bool aForce = false);
   static void CancelComposition(nsWindow* aWindow, bool aForce = false);
   static void OnUpdateComposition(nsWindow* aWindow);
+  static void OnSelectionChange(nsWindow* aWindow,
+                                const IMENotification& aIMENotification);
 
   static nsIMEUpdatePreference GetIMEUpdatePreference();
 
   // Returns NS_SUCCESS_EVENT_CONSUMED if the mouse button event is consumed by
   // IME.  Otherwise, NS_OK.
   static nsresult OnMouseButtonEvent(nsWindow* aWindow,
                                      const IMENotification& aIMENotification);