Bug 1310454 part 2 - TSFTextStore::SetInputContext() should do nothing when it's called for initializing native IME context when a widget is created r=m_kato a=lizzard
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 19 May 2017 15:52:59 +0900
changeset 394091 8f24ea832cb2cd792d4a2333fba643c476d0e850
parent 394090 b4855604982cb7fc4709c3ec53c2dce56420a874
child 394092 bafab90a35154efefa0f002456ff7bc6060f190e
push id7361
push usercbook@mozilla.com
push dateFri, 26 May 2017 12:34:30 +0000
treeherdermozilla-beta@83e94c015805 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato, lizzard
bugs1310454
milestone54.0
Bug 1310454 part 2 - TSFTextStore::SetInputContext() should do nothing when it's called for initializing native IME context when a widget is created r=m_kato a=lizzard On Windows, when nsWindow is created, IMEHandler::InitInputContext() is called. Then, it calls TSFTextStore::SetInputContext(). However, at least for now, TSFTextStore needs to do nothing until the widget gets focus. MozReview-Commit-ID: HBafHEUSCtd
widget/IMEData.h
widget/windows/TSFTextStore.cpp
widget/windows/WinIMEHandler.cpp
--- a/widget/IMEData.h
+++ b/widget/IMEData.h
@@ -352,17 +352,21 @@ struct InputContextAction final
     GOT_FOCUS,
     // Focused content lost focus.
     LOST_FOCUS,
     // Menu got pseudo focus that means focused content isn't changed but
     // keyboard events will be handled by menu.
     MENU_GOT_PSEUDO_FOCUS,
     // Menu lost pseudo focus that means focused content will handle keyboard
     // events.
-    MENU_LOST_PSEUDO_FOCUS
+    MENU_LOST_PSEUDO_FOCUS,
+    // The widget is created.  When a widget is crated, it may need to notify
+    // IME module to initialize its native IME context.  In such case, this is
+    // used.  I.e., this isn't used by IMEStateManager.
+    WIDGET_CREATED
   };
   FocusChange mFocusChange;
 
   bool ContentGotFocusByTrustedCause() const
   {
     return (mFocusChange == GOT_FOCUS &&
             mCause != CAUSE_UNKNOWN);
   }
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -138,16 +138,18 @@ GetFocusChangeName(InputContextAction::F
     case InputContextAction::GOT_FOCUS:
       return "GOT_FOCUS";
     case InputContextAction::LOST_FOCUS:
       return "LOST_FOCUS";
     case InputContextAction::MENU_GOT_PSEUDO_FOCUS:
       return "MENU_GOT_PSEUDO_FOCUS";
     case InputContextAction::MENU_LOST_PSEUDO_FOCUS:
       return "MENU_LOST_PSEUDO_FOCUS";
+    case InputContextAction::WIDGET_CREATED:
+      return "WIDGET_CREATED";
     default:
       return "Unknown";
   }
 }
 
 static nsCString
 GetCLSIDNameStr(REFCLSID aCLSID)
 {
@@ -5785,21 +5787,27 @@ TSFTextStore::GetIMEOpenState()
 void
 TSFTextStore::SetInputContext(nsWindowBase* aWidget,
                              const InputContext& aContext,
                              const InputContextAction& aAction)
 {
   MOZ_LOG(sTextStoreLog, LogLevel::Debug,
     ("TSFTextStore::SetInputContext(aWidget=%p, "
      "aContext=%s, aAction.mFocusChange=%s), "
-     "sEnabledTextStore=0x%p, ThinksHavingFocus()=%s",
+     "sEnabledTextStore(0x%p)={ mWidget=0x%p }, ThinksHavingFocus()=%s",
      aWidget, GetInputContextString(aContext).get(),
      GetFocusChangeName(aAction.mFocusChange), sEnabledTextStore.get(),
+     sEnabledTextStore ? sEnabledTextStore->mWidget.get() : nullptr,
      GetBoolName(ThinksHavingFocus())));
 
+  // When this is called when the widget is created, there is nothing to do.
+  if (aAction.mFocusChange == InputContextAction::WIDGET_CREATED) {
+    return;
+  }
+
   NS_ENSURE_TRUE_VOID(IsInTSFMode());
 
   if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) {
     if (sEnabledTextStore) {
       RefPtr<TSFTextStore> textStore(sEnabledTextStore);
       textStore->SetInputScope(aContext.mHTMLInputType,
                                aContext.mHTMLInputInputmode);
     }
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -488,17 +488,17 @@ IMEHandler::InitInputContext(nsWindow* a
 {
   // For a11y, the default enabled state should be 'enabled'.
   aInputContext.mIMEState.mEnabled = IMEState::ENABLED;
 
 #ifdef NS_ENABLE_TSF
   if (sIsInTSFMode) {
     TSFTextStore::SetInputContext(aWindow, aInputContext,
       InputContextAction(InputContextAction::CAUSE_UNKNOWN,
-                         InputContextAction::GOT_FOCUS));
+                         InputContextAction::WIDGET_CREATED));
     // IME context isn't necessary in pure TSF mode.
     if (!sIsIMMEnabled) {
       AssociateIMEContext(aWindow, false);
     }
     return;
   }
 #endif // #ifdef NS_ENABLE_TSF