Bug 1052343 part.2 Don't assume that there is nsTextStore instance even during in TSF mode r=emk
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 02 Sep 2014 09:27:25 +0900
changeset 224533 a8c91093e63193105385650ee9bce8b38eb75dad
parent 224532 615664f7bc69b12c4998908ccbb5d64e898003d0
child 224534 f9e2e2b2b065c5f49dea5419e9c87e11d575ca28
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1052343
milestone34.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 1052343 part.2 Don't assume that there is nsTextStore instance even during in TSF mode r=emk
widget/windows/WinIMEHandler.cpp
widget/windows/nsTextStore.cpp
widget/windows/nsTextStore.h
widget/windows/winrt/MetroWidget.cpp
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -284,17 +284,17 @@ IMEHandler::SetInputContext(nsWindow* aW
 
   aInputContext.mNativeIMEContext = nullptr;
 
 #ifdef NS_ENABLE_TSF
   // Note that even while a plugin has focus, we need to notify TSF of that.
   if (sIsInTSFMode) {
     nsTextStore::SetInputContext(aWindow, aInputContext, aAction);
     if (IsTSFAvailable()) {
-      aInputContext.mNativeIMEContext = nsTextStore::GetTextStore();
+      aInputContext.mNativeIMEContext = nsTextStore::GetThreadManager();
       if (sIsIMMEnabled) {
         // Associate IME context for IMM-IMEs.
         AssociateIMEContext(aWindow, enable);
       } else if (oldInputContext.mIMEState.mEnabled == IMEState::PLUGIN) {
         // Disassociate the IME context from the window when plugin loses focus
         // in pure TSF mode.
         AssociateIMEContext(aWindow, false);
       }
@@ -349,17 +349,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) {
     nsTextStore::SetInputContext(aWindow, aInputContext,
       InputContextAction(InputContextAction::CAUSE_UNKNOWN,
                          InputContextAction::GOT_FOCUS));
-    aInputContext.mNativeIMEContext = nsTextStore::GetTextStore();
+    aInputContext.mNativeIMEContext = nsTextStore::GetThreadManager();
     MOZ_ASSERT(aInputContext.mNativeIMEContext);
     // IME context isn't necessary in pure TSF mode.
     if (!sIsIMMEnabled) {
       AssociateIMEContext(aWindow, false);
     }
     return;
   }
 #endif // #ifdef NS_ENABLE_TSF
--- a/widget/windows/nsTextStore.cpp
+++ b/widget/windows/nsTextStore.cpp
@@ -3664,17 +3664,17 @@ nsTextStore::OnFocusChange(bool aGotFocu
          ("TSF:   nsTextStore::OnFocusChange(aGotFocus=%s, "
           "aFocusedWidget=0x%p, aIMEState={ mEnabled=%s }), "
           "sTsfThreadMgr=0x%p, sEnabledTextStore=0x%p",
           GetBoolName(aGotFocus), aFocusedWidget,
           GetIMEEnabledName(aIMEState.mEnabled),
           sTsfThreadMgr, sEnabledTextStore));
 
   // no change notifications if TSF is disabled
-  NS_ENSURE_TRUE(sTsfThreadMgr && sEnabledTextStore, NS_ERROR_NOT_AVAILABLE);
+  NS_ENSURE_TRUE(IsInTSFMode(), NS_ERROR_NOT_AVAILABLE);
 
   nsRefPtr<ITfDocumentMgr> prevFocusedDocumentMgr;
   if (aGotFocus && aIMEState.IsEditable()) {
     bool bRet = sEnabledTextStore->Create(aFocusedWidget);
     NS_ENSURE_TRUE(bRet, NS_ERROR_FAILURE);
     NS_ENSURE_TRUE(sEnabledTextStore->mDocumentMgr, NS_ERROR_FAILURE);
     if (aIMEState.mEnabled == IMEState::PASSWORD) {
       MarkContextAsKeyboardDisabled(sEnabledTextStore->mContext);
@@ -4203,22 +4203,27 @@ nsTextStore::GetIMEOpenState(void)
 void
 nsTextStore::SetInputContext(nsWindowBase* aWidget,
                              const InputContext& aContext,
                              const InputContextAction& aAction)
 {
   PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
          ("TSF: nsTextStore::SetInputContext(aWidget=%p, "
           "aContext.mIMEState.mEnabled=%s, aAction.mFocusChange=%s), "
-          "ThinksHavingFocus()=%s",
+          "sEnabledTextStore=0x%p, ThinksHavingFocus()=%s",
           aWidget, GetIMEEnabledName(aContext.mIMEState.mEnabled),
-          GetFocusChangeName(aAction.mFocusChange),
+          GetFocusChangeName(aAction.mFocusChange), sEnabledTextStore,
           GetBoolName(ThinksHavingFocus())));
 
-  NS_ENSURE_TRUE_VOID(sEnabledTextStore);
+  NS_ENSURE_TRUE_VOID(IsInTSFMode());
+
+  if (!sEnabledTextStore) {
+    return;
+  }
+
   sEnabledTextStore->SetInputScope(aContext.mHTMLInputType);
 
   if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) {
     return;
   }
 
   // If focus isn't actually changed but the enabled state is changed,
   // emulate the focus move.
--- a/widget/windows/nsTextStore.h
+++ b/widget/windows/nsTextStore.h
@@ -129,51 +129,55 @@ public:
                                  mozilla::widget::MSGResult& aResult);
 
 
   static void     SetIMEOpenState(bool);
   static bool     GetIMEOpenState(void);
 
   static void     CommitComposition(bool aDiscard)
   {
-    NS_ENSURE_TRUE_VOID(sEnabledTextStore);
-    sEnabledTextStore->CommitCompositionInternal(aDiscard);
+    NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
+    if (sEnabledTextStore) {
+      sEnabledTextStore->CommitCompositionInternal(aDiscard);
+    }
   }
 
   static void SetInputContext(nsWindowBase* aWidget,
                               const InputContext& aContext,
                               const InputContextAction& aAction);
 
   static nsresult OnFocusChange(bool aGotFocus,
                                 nsWindowBase* aFocusedWidget,
                                 const IMEState& aIMEState);
   static nsresult OnTextChange(const IMENotification& aIMENotification)
   {
-    NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE);
-    return sEnabledTextStore->OnTextChangeInternal(aIMENotification);
+    NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
+    return sEnabledTextStore ?
+      sEnabledTextStore->OnTextChangeInternal(aIMENotification) : NS_OK;
   }
 
   static nsresult OnSelectionChange(void)
   {
-    NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE);
-    return sEnabledTextStore->OnSelectionChangeInternal();
+    NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
+    return sEnabledTextStore ?
+      sEnabledTextStore->OnSelectionChangeInternal() : NS_OK;
   }
 
   static nsresult OnLayoutChange()
   {
-    NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE);
-    return sEnabledTextStore->OnLayoutChangeInternal();
+    NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
+    return sEnabledTextStore ?
+      sEnabledTextStore->OnLayoutChangeInternal() : NS_OK;
   }
 
   static nsresult OnMouseButtonEvent(const IMENotification& aIMENotification)
   {
-    if (NS_WARN_IF(!sEnabledTextStore)) {
-      return NS_ERROR_NOT_AVAILABLE;
-    }
-    return sEnabledTextStore->OnMouseButtonEventInternal(aIMENotification);
+    NS_ASSERTION(IsInTSFMode(), "Not in TSF mode, shouldn't be called");
+    return sEnabledTextStore ?
+      sEnabledTextStore->OnMouseButtonEventInternal(aIMENotification) : NS_OK;
   }
 
   static nsIMEUpdatePreference GetIMEUpdatePreference();
 
   // Returns the address of the pointer so that the TSF automatic test can
   // replace the system object with a custom implementation for testing.
   static void* GetNativeData(uint32_t aDataType)
   {
@@ -190,51 +194,51 @@ public:
     }
   }
 
   static ITfMessagePump* GetMessagePump()
   {
     return sMessagePump;
   }
 
-  static void*    GetTextStore()
+  static void* GetThreadManager()
   {
-    return static_cast<void*>(sEnabledTextStore);
+    return static_cast<void*>(sTsfThreadMgr);
   }
 
-  static bool     ThinksHavingFocus()
+  static bool ThinksHavingFocus()
   {
     return (sEnabledTextStore && sEnabledTextStore->mContext);
   }
 
-  static bool     IsInTSFMode()
+  static bool IsInTSFMode()
   {
     return sTsfThreadMgr != nullptr;
   }
 
-  static bool     IsComposing()
+  static bool IsComposing()
   {
     return (sEnabledTextStore && sEnabledTextStore->mComposition.IsComposing());
   }
 
-  static bool     IsComposingOn(nsWindowBase* aWidget)
+  static bool IsComposingOn(nsWindowBase* aWidget)
   {
     return (IsComposing() && sEnabledTextStore->mWidget == aWidget);
   }
 
-  static bool     IsIMM_IME()
+  static bool IsIMM_IME()
   {
     if (!sEnabledTextStore ||
         !sEnabledTextStore->EnsureInitActiveTIPKeyboard()) {
       return IsIMM_IME(::GetKeyboardLayout(0));
     }
     return sEnabledTextStore->mIsIMM_IME;
   }
 
-  static bool     IsIMM_IME(HKL aHKL)
+  static bool IsIMM_IME(HKL aHKL)
   {
      return (::ImmGetIMEFileNameW(aHKL, nullptr, 0) > 0);
   }
 
 #ifdef DEBUG
   // Returns true when keyboard layout has IME (TIP).
   static bool     CurrentKeyboardLayoutHasIME();
 #endif // #ifdef DEBUG
--- a/widget/windows/winrt/MetroWidget.cpp
+++ b/widget/windows/winrt/MetroWidget.cpp
@@ -1537,16 +1537,17 @@ MetroWidget::CaptureRollupEvents(nsIRoll
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP_(void)
 MetroWidget::SetInputContext(const InputContext& aContext,
                              const InputContextAction& aAction)
 {
+  // XXX This should set mInputContext.mNativeIMEContext properly
   mInputContext = aContext;
   nsTextStore::SetInputContext(this, mInputContext, aAction);
   bool enable = (mInputContext.mIMEState.mEnabled == IMEState::ENABLED ||
                  mInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
   if (enable &&
       mInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE) {
     bool open = (mInputContext.mIMEState.mOpen == IMEState::OPEN);
     nsTextStore::SetIMEOpenState(open);