From bc41125f3fca8208253f23468414ebbbec7770ad Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 2 Sep 2014 09:27:25 +0900 Subject: [PATCH] Bug 1052343 part.2 Don't assume that there is nsTextStore instance even during in TSF mode r=emk --- widget/windows/WinIMEHandler.cpp | 4 +-- widget/windows/nsTextStore.cpp | 13 +++++--- widget/windows/nsTextStore.h | 44 +++++++++++++++------------- widget/windows/winrt/MetroWidget.cpp | 1 + 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/widget/windows/WinIMEHandler.cpp b/widget/windows/WinIMEHandler.cpp index 40b7ad5e3b1..ed4e8c6ce10 100644 --- a/widget/windows/WinIMEHandler.cpp +++ b/widget/windows/WinIMEHandler.cpp @@ -289,7 +289,7 @@ IMEHandler::SetInputContext(nsWindow* aWindow, 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); @@ -354,7 +354,7 @@ IMEHandler::InitInputContext(nsWindow* aWindow, InputContext& aInputContext) 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) { diff --git a/widget/windows/nsTextStore.cpp b/widget/windows/nsTextStore.cpp index 3902b1619e3..97e94068718 100644 --- a/widget/windows/nsTextStore.cpp +++ b/widget/windows/nsTextStore.cpp @@ -3669,7 +3669,7 @@ nsTextStore::OnFocusChange(bool aGotFocus, 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 prevFocusedDocumentMgr; if (aGotFocus && aIMEState.IsEditable()) { @@ -4208,12 +4208,17 @@ nsTextStore::SetInputContext(nsWindowBase* aWidget, 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) { diff --git a/widget/windows/nsTextStore.h b/widget/windows/nsTextStore.h index e429c92801d..a57b95e6ee8 100644 --- a/widget/windows/nsTextStore.h +++ b/widget/windows/nsTextStore.h @@ -134,8 +134,10 @@ public: 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, @@ -147,28 +149,30 @@ public: 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(); @@ -195,32 +199,32 @@ public: return sMessagePump; } - static void* GetTextStore() + static void* GetThreadManager() { - return static_cast(sEnabledTextStore); + return static_cast(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()) { @@ -229,7 +233,7 @@ public: return sEnabledTextStore->mIsIMM_IME; } - static bool IsIMM_IME(HKL aHKL) + static bool IsIMM_IME(HKL aHKL) { return (::ImmGetIMEFileNameW(aHKL, nullptr, 0) > 0); } diff --git a/widget/windows/winrt/MetroWidget.cpp b/widget/windows/winrt/MetroWidget.cpp index e1b35e07adf..36dcefa2b73 100644 --- a/widget/windows/winrt/MetroWidget.cpp +++ b/widget/windows/winrt/MetroWidget.cpp @@ -1542,6 +1542,7 @@ 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 ||