author | Masayuki Nakano <masayuki@d-toybox.com> |
Tue, 02 Sep 2014 09:27:24 +0900 | |
changeset 202836 | 615664f7bc69b12c4998908ccbb5d64e898003d0 |
parent 202835 | a9bcb7c881cc887da22ac7622ab7a1e5d36765bd |
child 202837 | a8c91093e63193105385650ee9bce8b38eb75dad |
push id | 48511 |
push user | masayuki@d-toybox.com |
push date | Tue, 02 Sep 2014 00:27:30 +0000 |
treeherder | mozilla-inbound@7b7c24a989fa [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | emk |
bugs | 1052343 |
milestone | 34.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
|
widget/windows/nsTextStore.cpp | file | annotate | diff | comparison | revisions | |
widget/windows/nsTextStore.h | file | annotate | diff | comparison | revisions |
--- a/widget/windows/nsTextStore.cpp +++ b/widget/windows/nsTextStore.cpp @@ -127,17 +127,17 @@ ITfThreadMgr* nsTextStore::sTs ITfMessagePump* nsTextStore::sMessagePump = nullptr; ITfKeystrokeMgr* nsTextStore::sKeystrokeMgr = nullptr; ITfDisplayAttributeMgr* nsTextStore::sDisplayAttrMgr = nullptr; ITfCategoryMgr* nsTextStore::sCategoryMgr = nullptr; ITfDocumentMgr* nsTextStore::sTsfDisabledDocumentMgr = nullptr; ITfContext* nsTextStore::sTsfDisabledContext = nullptr; ITfInputProcessorProfiles* nsTextStore::sInputProcessorProfiles = nullptr; DWORD nsTextStore::sTsfClientId = 0; -nsTextStore* nsTextStore::sTsfTextStore = nullptr; +StaticRefPtr<nsTextStore> nsTextStore::sEnabledTextStore; bool nsTextStore::sCreateNativeCaretForATOK = false; bool nsTextStore::sDoNotReturnNoLayoutErrorToFreeChangJie = false; bool nsTextStore::sDoNotReturnNoLayoutErrorToEasyChangjei = false; #define TIP_NAME_BEGINS_WITH_ATOK \ (NS_LITERAL_STRING("ATOK ")) // NOTE: Free ChangJie 2010 missspells its name... @@ -3658,69 +3658,70 @@ nsTextStore::UnadviseMouseSink(DWORD dwC nsresult nsTextStore::OnFocusChange(bool aGotFocus, nsWindowBase* aFocusedWidget, const IMEState& aIMEState) { PR_LOG(sTextStoreLog, PR_LOG_DEBUG, ("TSF: nsTextStore::OnFocusChange(aGotFocus=%s, " "aFocusedWidget=0x%p, aIMEState={ mEnabled=%s }), " - "sTsfThreadMgr=0x%p, sTsfTextStore=0x%p", + "sTsfThreadMgr=0x%p, sEnabledTextStore=0x%p", GetBoolName(aGotFocus), aFocusedWidget, GetIMEEnabledName(aIMEState.mEnabled), - sTsfThreadMgr, sTsfTextStore)); + sTsfThreadMgr, sEnabledTextStore)); // no change notifications if TSF is disabled - NS_ENSURE_TRUE(sTsfThreadMgr && sTsfTextStore, NS_ERROR_NOT_AVAILABLE); + NS_ENSURE_TRUE(sTsfThreadMgr && sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); nsRefPtr<ITfDocumentMgr> prevFocusedDocumentMgr; if (aGotFocus && aIMEState.IsEditable()) { - bool bRet = sTsfTextStore->Create(aFocusedWidget); + bool bRet = sEnabledTextStore->Create(aFocusedWidget); NS_ENSURE_TRUE(bRet, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(sTsfTextStore->mDocumentMgr, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(sEnabledTextStore->mDocumentMgr, NS_ERROR_FAILURE); if (aIMEState.mEnabled == IMEState::PASSWORD) { - MarkContextAsKeyboardDisabled(sTsfTextStore->mContext); + MarkContextAsKeyboardDisabled(sEnabledTextStore->mContext); nsRefPtr<ITfContext> topContext; - sTsfTextStore->mDocumentMgr->GetTop(getter_AddRefs(topContext)); - if (topContext && topContext != sTsfTextStore->mContext) { + sEnabledTextStore->mDocumentMgr->GetTop(getter_AddRefs(topContext)); + if (topContext && topContext != sEnabledTextStore->mContext) { MarkContextAsKeyboardDisabled(topContext); } } - HRESULT hr = sTsfThreadMgr->SetFocus(sTsfTextStore->mDocumentMgr); + HRESULT hr = sTsfThreadMgr->SetFocus(sEnabledTextStore->mDocumentMgr); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); // Use AssociateFocus() for ensuring that any native focus event // never steal focus from our documentMgr. hr = sTsfThreadMgr->AssociateFocus(aFocusedWidget->GetWindowHandle(), - sTsfTextStore->mDocumentMgr, + sEnabledTextStore->mDocumentMgr, getter_AddRefs(prevFocusedDocumentMgr)); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); } else { if (ThinksHavingFocus()) { - DebugOnly<HRESULT> hr = sTsfThreadMgr->AssociateFocus( - sTsfTextStore->mWidget->GetWindowHandle(), - nullptr, getter_AddRefs(prevFocusedDocumentMgr)); + DebugOnly<HRESULT> hr = + sTsfThreadMgr->AssociateFocus( + sEnabledTextStore->mWidget->GetWindowHandle(), + nullptr, getter_AddRefs(prevFocusedDocumentMgr)); NS_ASSERTION(SUCCEEDED(hr), "Disassociating focus failed"); - NS_ASSERTION(prevFocusedDocumentMgr == sTsfTextStore->mDocumentMgr, + NS_ASSERTION(prevFocusedDocumentMgr == sEnabledTextStore->mDocumentMgr, "different documentMgr has been associated with the window"); - sTsfTextStore->Destroy(); + sEnabledTextStore->Destroy(); } HRESULT hr = sTsfThreadMgr->SetFocus(sTsfDisabledDocumentMgr); NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE); } return NS_OK; } // static nsIMEUpdatePreference nsTextStore::GetIMEUpdatePreference() { - if (sTsfThreadMgr && sTsfTextStore && sTsfTextStore->mDocumentMgr) { + if (sTsfThreadMgr && sEnabledTextStore && sEnabledTextStore->mDocumentMgr) { nsRefPtr<ITfDocumentMgr> docMgr; sTsfThreadMgr->GetFocus(getter_AddRefs(docMgr)); - if (docMgr == sTsfTextStore->mDocumentMgr) { + if (docMgr == sEnabledTextStore->mDocumentMgr) { nsIMEUpdatePreference updatePreference( nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE | nsIMEUpdatePreference::NOTIFY_TEXT_CHANGE | nsIMEUpdatePreference::NOTIFY_POSITION_CHANGE | nsIMEUpdatePreference::NOTIFY_MOUSE_BUTTON_EVENT_ON_CHAR | nsIMEUpdatePreference::NOTIFY_DURING_DEACTIVE); // nsTextStore shouldn't notify TSF of selection change and text change // which are caused by composition. @@ -4207,18 +4208,18 @@ nsTextStore::SetInputContext(nsWindowBas PR_LOG(sTextStoreLog, PR_LOG_DEBUG, ("TSF: nsTextStore::SetInputContext(aWidget=%p, " "aContext.mIMEState.mEnabled=%s, aAction.mFocusChange=%s), " "ThinksHavingFocus()=%s", aWidget, GetIMEEnabledName(aContext.mIMEState.mEnabled), GetFocusChangeName(aAction.mFocusChange), GetBoolName(ThinksHavingFocus()))); - NS_ENSURE_TRUE_VOID(sTsfTextStore); - sTsfTextStore->SetInputScope(aContext.mHTMLInputType); + NS_ENSURE_TRUE_VOID(sEnabledTextStore); + 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. if (!ThinksHavingFocus() && aContext.mIMEState.IsEditable()) { @@ -4484,57 +4485,57 @@ nsTextStore::Initialize() inputProcessorProfiles.swap(sInputProcessorProfiles); threadMgr.swap(sTsfThreadMgr); messagePump.swap(sMessagePump); keystrokeMgr.swap(sKeystrokeMgr); displayAttributeMgr.swap(sDisplayAttrMgr); categoryMgr.swap(sCategoryMgr); disabledDocumentMgr.swap(sTsfDisabledDocumentMgr); disabledContext.swap(sTsfDisabledContext); - textStore.swap(sTsfTextStore); + sEnabledTextStore = textStore; sCreateNativeCaretForATOK = Preferences::GetBool("intl.tsf.hack.atok.create_native_caret", true); sDoNotReturnNoLayoutErrorToFreeChangJie = Preferences::GetBool( "intl.tsf.hack.free_chang_jie.do_not_return_no_layout_error", true); sDoNotReturnNoLayoutErrorToEasyChangjei = Preferences::GetBool( "intl.tsf.hack.easy_changjei.do_not_return_no_layout_error", true); MOZ_ASSERT(!sFlushTIPInputMessage); sFlushTIPInputMessage = ::RegisterWindowMessageW(L"Flush TIP Input Message"); PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, ("TSF: nsTextStore::Initialize(), sTsfThreadMgr=0x%p, " - "sTsfClientId=0x%08X, sTsfTextStore=0x%p, sDisplayAttrMgr=0x%p, " + "sTsfClientId=0x%08X, sEnabledTextStore=0x%p, sDisplayAttrMgr=0x%p, " "sCategoryMgr=0x%p, sTsfDisabledDocumentMgr=0x%p, sTsfDisabledContext=%p, " "sCreateNativeCaretForATOK=%s, " "sDoNotReturnNoLayoutErrorToFreeChangJie=%s, " "sDoNotReturnNoLayoutErrorToEasyChangjei=%s", - sTsfThreadMgr, sTsfClientId, sTsfTextStore, sDisplayAttrMgr, sCategoryMgr, - sTsfDisabledDocumentMgr, sTsfDisabledContext, + sTsfThreadMgr, sTsfClientId, sEnabledTextStore, sDisplayAttrMgr, + sCategoryMgr, sTsfDisabledDocumentMgr, sTsfDisabledContext, GetBoolName(sCreateNativeCaretForATOK), GetBoolName(sDoNotReturnNoLayoutErrorToFreeChangJie), GetBoolName(sDoNotReturnNoLayoutErrorToEasyChangjei))); } // static void nsTextStore::Terminate(void) { PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, ("TSF: nsTextStore::Terminate()")); - if (sTsfTextStore) { - sTsfTextStore->Shutdown(); + if (sEnabledTextStore) { + sEnabledTextStore->Shutdown(); } NS_IF_RELEASE(sDisplayAttrMgr); NS_IF_RELEASE(sCategoryMgr); - NS_IF_RELEASE(sTsfTextStore); + sEnabledTextStore = nullptr; NS_IF_RELEASE(sTsfDisabledDocumentMgr); NS_IF_RELEASE(sTsfDisabledContext); NS_IF_RELEASE(sInputProcessorProfiles); sTsfClientId = 0; if (sTsfThreadMgr) { sTsfThreadMgr->Deactivate(); NS_RELEASE(sTsfThreadMgr); NS_RELEASE(sMessagePump);
--- a/widget/windows/nsTextStore.h +++ b/widget/windows/nsTextStore.h @@ -8,16 +8,17 @@ #include "nsAutoPtr.h" #include "nsString.h" #include "nsCOMPtr.h" #include "nsIWidget.h" #include "nsWindowBase.h" #include "WinUtils.h" #include "mozilla/Attributes.h" +#include "mozilla/StaticPtr.h" #include "mozilla/TextRange.h" #include "mozilla/WindowsVersion.h" #include <msctf.h> #include <textstor.h> // GUID_PROP_INPUTSCOPE is declared in inputscope.h using INIT_GUID. // With initguid.h, we get its instance instead of extern declaration. @@ -128,51 +129,51 @@ public: mozilla::widget::MSGResult& aResult); static void SetIMEOpenState(bool); static bool GetIMEOpenState(void); static void CommitComposition(bool aDiscard) { - NS_ENSURE_TRUE_VOID(sTsfTextStore); - sTsfTextStore->CommitCompositionInternal(aDiscard); + NS_ENSURE_TRUE_VOID(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(sTsfTextStore, NS_ERROR_NOT_AVAILABLE); - return sTsfTextStore->OnTextChangeInternal(aIMENotification); + NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); + return sEnabledTextStore->OnTextChangeInternal(aIMENotification); } static nsresult OnSelectionChange(void) { - NS_ENSURE_TRUE(sTsfTextStore, NS_ERROR_NOT_AVAILABLE); - return sTsfTextStore->OnSelectionChangeInternal(); + NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); + return sEnabledTextStore->OnSelectionChangeInternal(); } static nsresult OnLayoutChange() { - NS_ENSURE_TRUE(sTsfTextStore, NS_ERROR_NOT_AVAILABLE); - return sTsfTextStore->OnLayoutChangeInternal(); + NS_ENSURE_TRUE(sEnabledTextStore, NS_ERROR_NOT_AVAILABLE); + return sEnabledTextStore->OnLayoutChangeInternal(); } static nsresult OnMouseButtonEvent(const IMENotification& aIMENotification) { - if (NS_WARN_IF(!sTsfTextStore)) { + if (NS_WARN_IF(!sEnabledTextStore)) { return NS_ERROR_NOT_AVAILABLE; } - return sTsfTextStore->OnMouseButtonEventInternal(aIMENotification); + return sEnabledTextStore->OnMouseButtonEventInternal(aIMENotification); } 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) { @@ -191,45 +192,46 @@ public: static ITfMessagePump* GetMessagePump() { return sMessagePump; } static void* GetTextStore() { - return static_cast<void*>(sTsfTextStore); + return static_cast<void*>(sEnabledTextStore); } static bool ThinksHavingFocus() { - return (sTsfTextStore && sTsfTextStore->mContext); + return (sEnabledTextStore && sEnabledTextStore->mContext); } static bool IsInTSFMode() { return sTsfThreadMgr != nullptr; } static bool IsComposing() { - return (sTsfTextStore && sTsfTextStore->mComposition.IsComposing()); + return (sEnabledTextStore && sEnabledTextStore->mComposition.IsComposing()); } static bool IsComposingOn(nsWindowBase* aWidget) { - return (IsComposing() && sTsfTextStore->mWidget == aWidget); + return (IsComposing() && sEnabledTextStore->mWidget == aWidget); } static bool IsIMM_IME() { - if (!sTsfTextStore || !sTsfTextStore->EnsureInitActiveTIPKeyboard()) { + if (!sEnabledTextStore || + !sEnabledTextStore->EnsureInitActiveTIPKeyboard()) { return IsIMM_IME(::GetKeyboardLayout(0)); } - return sTsfTextStore->mIsIMM_IME; + return sEnabledTextStore->mIsIMM_IME; } static bool IsIMM_IME(HKL aHKL) { return (::ImmGetIMEFileNameW(aHKL, nullptr, 0) > 0); } #ifdef DEBUG @@ -778,20 +780,21 @@ protected: static ITfKeystrokeMgr* sKeystrokeMgr; // TSF display attribute manager static ITfDisplayAttributeMgr* sDisplayAttrMgr; // TSF category manager static ITfCategoryMgr* sCategoryMgr; // TSF client ID for the current application static DWORD sTsfClientId; - // Current text store. Currently only ONE nsTextStore instance is ever used, + // Current text store which is managing a keyboard enabled editor (i.e., + // editable editor). Currently only ONE nsTextStore instance is ever used, // although Create is called when an editor is focused and Destroy called // when the focused editor is blurred. - static nsTextStore* sTsfTextStore; + static mozilla::StaticRefPtr<nsTextStore> sEnabledTextStore; // For IME (keyboard) disabled state: static ITfDocumentMgr* sTsfDisabledDocumentMgr; static ITfContext* sTsfDisabledContext; static ITfInputProcessorProfiles* sInputProcessorProfiles; // Enables/Disables hack for specific TIP.