mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1062053 part.1 nsTextStore should use StaticRefPtr for storing COM objects r=jimm
This commit is contained in:
parent
d47b903e09
commit
7b8a0d1be9
@ -1476,6 +1476,8 @@ TestApp::Init(void)
|
||||
nsresult rv = baseWindow->GetMainWidget(getter_AddRefs(widget));
|
||||
NS_ENSURE_TRUE(widget, NS_ERROR_UNEXPECTED);
|
||||
|
||||
static_assert(false,
|
||||
"GetNativeData() returns pointer to StaticRefPtr<>, fix here for it");
|
||||
ITfThreadMgr **threadMgr = reinterpret_cast<ITfThreadMgr**>(
|
||||
widget->GetNativeData(NS_NATIVE_TSF_THREAD_MGR));
|
||||
if (!threadMgr) {
|
||||
|
@ -705,7 +705,7 @@ public:
|
||||
static TSFStaticSink* GetInstance()
|
||||
{
|
||||
if (!sInstance) {
|
||||
NS_ADDREF(sInstance = new TSFStaticSink());
|
||||
sInstance = new TSFStaticSink();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
@ -714,7 +714,7 @@ public:
|
||||
{
|
||||
if (sInstance) {
|
||||
sInstance->Destroy();
|
||||
NS_RELEASE(sInstance);
|
||||
sInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -794,10 +794,10 @@ private:
|
||||
// i.e., IMM-IME or just a keyboard layout, this is empty.
|
||||
nsString mActiveTIPKeyboardDescription;
|
||||
|
||||
static TSFStaticSink* sInstance;
|
||||
static StaticRefPtr<TSFStaticSink> sInstance;
|
||||
};
|
||||
|
||||
TSFStaticSink* TSFStaticSink::sInstance = nullptr;
|
||||
StaticRefPtr<TSFStaticSink> TSFStaticSink::sInstance;
|
||||
|
||||
TSFStaticSink::TSFStaticSink()
|
||||
: mIPProfileCookie(TF_INVALID_COOKIE)
|
||||
@ -1141,14 +1141,14 @@ TSFStaticSink::IsTIPCategoryKeyboard(REFCLSID aTextService, LANGID aLangID,
|
||||
/* nsTextStore */
|
||||
/******************************************************************/
|
||||
|
||||
ITfThreadMgr* nsTextStore::sTsfThreadMgr = nullptr;
|
||||
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;
|
||||
StaticRefPtr<ITfThreadMgr> nsTextStore::sThreadMgr;
|
||||
StaticRefPtr<ITfMessagePump> nsTextStore::sMessagePump;
|
||||
StaticRefPtr<ITfKeystrokeMgr> nsTextStore::sKeystrokeMgr;
|
||||
StaticRefPtr<ITfDisplayAttributeMgr> nsTextStore::sDisplayAttrMgr;
|
||||
StaticRefPtr<ITfCategoryMgr> nsTextStore::sCategoryMgr;
|
||||
StaticRefPtr<ITfDocumentMgr> nsTextStore::sDisabledDocumentMgr;
|
||||
StaticRefPtr<ITfContext> nsTextStore::sDisabledContext;
|
||||
StaticRefPtr<ITfInputProcessorProfiles> nsTextStore::sInputProcessorProfiles;
|
||||
DWORD nsTextStore::sTsfClientId = 0;
|
||||
StaticRefPtr<nsTextStore> nsTextStore::sEnabledTextStore;
|
||||
|
||||
@ -1214,8 +1214,7 @@ nsTextStore::Init(nsWindowBase* aWidget)
|
||||
}
|
||||
|
||||
// Create document manager
|
||||
HRESULT hr = sTsfThreadMgr->CreateDocumentMgr(
|
||||
getter_AddRefs(mDocumentMgr));
|
||||
HRESULT hr = sThreadMgr->CreateDocumentMgr(getter_AddRefs(mDocumentMgr));
|
||||
if (FAILED(hr)) {
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
||||
("TSF: 0x%p nsTextStore::Init() FAILED to create DocumentMgr "
|
||||
@ -3931,11 +3930,11 @@ nsTextStore::OnFocusChange(bool aGotFocus,
|
||||
("TSF: nsTextStore::OnFocusChange(aGotFocus=%s, "
|
||||
"aFocusedWidget=0x%p, aContext={ mIMEState={ mEnabled=%s }, "
|
||||
"mHTMLInputType=\"%s\" }), "
|
||||
"sTsfThreadMgr=0x%p, sEnabledTextStore=0x%p",
|
||||
"sThreadMgr=0x%p, sEnabledTextStore=0x%p",
|
||||
GetBoolName(aGotFocus), aFocusedWidget,
|
||||
GetIMEEnabledName(aContext.mIMEState.mEnabled),
|
||||
NS_ConvertUTF16toUTF8(aContext.mHTMLInputType).get(),
|
||||
sTsfThreadMgr, sEnabledTextStore));
|
||||
sThreadMgr.get(), sEnabledTextStore.get()));
|
||||
|
||||
if (NS_WARN_IF(!IsInTSFMode())) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
@ -3945,7 +3944,7 @@ nsTextStore::OnFocusChange(bool aGotFocus,
|
||||
if (ThinksHavingFocus()) {
|
||||
nsRefPtr<ITfDocumentMgr> prevFocusedDocumentMgr;
|
||||
DebugOnly<HRESULT> hr =
|
||||
sTsfThreadMgr->AssociateFocus(
|
||||
sThreadMgr->AssociateFocus(
|
||||
sEnabledTextStore->mWidget->GetWindowHandle(),
|
||||
nullptr, getter_AddRefs(prevFocusedDocumentMgr));
|
||||
NS_ASSERTION(SUCCEEDED(hr), "Disassociating focus failed");
|
||||
@ -3957,13 +3956,13 @@ nsTextStore::OnFocusChange(bool aGotFocus,
|
||||
// Release it now.
|
||||
if (sEnabledTextStore) {
|
||||
sEnabledTextStore->Destroy();
|
||||
NS_RELEASE(sEnabledTextStore);
|
||||
sEnabledTextStore = nullptr;
|
||||
}
|
||||
|
||||
// If this is a notification of blur, move focus to the dummy document
|
||||
// manager.
|
||||
if (!aGotFocus || !aContext.mIMEState.IsEditable()) {
|
||||
HRESULT hr = sTsfThreadMgr->SetFocus(sTsfDisabledDocumentMgr);
|
||||
HRESULT hr = sThreadMgr->SetFocus(sDisabledDocumentMgr);
|
||||
if (NS_WARN_IF(FAILED(hr))) {
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
||||
("TSF: nsTextStore::OnFocusChange() FAILED due to "
|
||||
@ -3982,7 +3981,7 @@ nsTextStore::OnFocusChange(bool aGotFocus,
|
||||
// it causes memory leak.
|
||||
if (sEnabledTextStore) {
|
||||
sEnabledTextStore->Destroy();
|
||||
NS_RELEASE(sEnabledTextStore);
|
||||
sEnabledTextStore = nullptr;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -3997,7 +3996,7 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget,
|
||||
// TSF might do something which causes that we need to access static methods
|
||||
// of nsTextStore. At that time, sEnabledTextStore may be necessary.
|
||||
// So, we should set sEnabledTextStore directly.
|
||||
NS_ADDREF(sEnabledTextStore = new nsTextStore());
|
||||
sEnabledTextStore = new nsTextStore();
|
||||
if (NS_WARN_IF(!sEnabledTextStore->Init(aFocusedWidget))) {
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
||||
("TSF: nsTextStore::CreateAndSetFocus() FAILED due to "
|
||||
@ -4018,7 +4017,7 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget,
|
||||
MarkContextAsKeyboardDisabled(topContext);
|
||||
}
|
||||
}
|
||||
HRESULT hr = sTsfThreadMgr->SetFocus(sEnabledTextStore->mDocumentMgr);
|
||||
HRESULT hr = sThreadMgr->SetFocus(sEnabledTextStore->mDocumentMgr);
|
||||
if (NS_WARN_IF(FAILED(hr))) {
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
||||
("TSF: nsTextStore::CreateAndSetFocus() FAILED due to "
|
||||
@ -4028,9 +4027,9 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget,
|
||||
// Use AssociateFocus() for ensuring that any native focus event
|
||||
// never steal focus from our documentMgr.
|
||||
nsRefPtr<ITfDocumentMgr> prevFocusedDocumentMgr;
|
||||
hr = sTsfThreadMgr->AssociateFocus(aFocusedWidget->GetWindowHandle(),
|
||||
sEnabledTextStore->mDocumentMgr,
|
||||
getter_AddRefs(prevFocusedDocumentMgr));
|
||||
hr = sThreadMgr->AssociateFocus(aFocusedWidget->GetWindowHandle(),
|
||||
sEnabledTextStore->mDocumentMgr,
|
||||
getter_AddRefs(prevFocusedDocumentMgr));
|
||||
if (NS_WARN_IF(FAILED(hr))) {
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
||||
("TSF: nsTextStore::CreateAndSetFocus() FAILED due to "
|
||||
@ -4045,9 +4044,9 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget,
|
||||
nsIMEUpdatePreference
|
||||
nsTextStore::GetIMEUpdatePreference()
|
||||
{
|
||||
if (sTsfThreadMgr && sEnabledTextStore && sEnabledTextStore->mDocumentMgr) {
|
||||
if (sThreadMgr && sEnabledTextStore && sEnabledTextStore->mDocumentMgr) {
|
||||
nsRefPtr<ITfDocumentMgr> docMgr;
|
||||
sTsfThreadMgr->GetFocus(getter_AddRefs(docMgr));
|
||||
sThreadMgr->GetFocus(getter_AddRefs(docMgr));
|
||||
if (docMgr == sEnabledTextStore->mDocumentMgr) {
|
||||
nsIMEUpdatePreference updatePreference(
|
||||
nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE |
|
||||
@ -4400,7 +4399,7 @@ nsTextStore::SetIMEOpenState(bool aState)
|
||||
("TSF: nsTextStore::SetIMEOpenState(aState=%s)", GetBoolName(aState)));
|
||||
|
||||
nsRefPtr<ITfCompartment> comp;
|
||||
if (!GetCompartment(sTsfThreadMgr,
|
||||
if (!GetCompartment(sThreadMgr,
|
||||
GUID_COMPARTMENT_KEYBOARD_OPENCLOSE,
|
||||
getter_AddRefs(comp))) {
|
||||
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
||||
@ -4424,7 +4423,7 @@ bool
|
||||
nsTextStore::GetIMEOpenState(void)
|
||||
{
|
||||
nsRefPtr<ITfCompartment> comp;
|
||||
if (!GetCompartment(sTsfThreadMgr,
|
||||
if (!GetCompartment(sThreadMgr,
|
||||
GUID_COMPARTMENT_KEYBOARD_OPENCLOSE,
|
||||
getter_AddRefs(comp)))
|
||||
return false;
|
||||
@ -4449,7 +4448,7 @@ nsTextStore::SetInputContext(nsWindowBase* aWidget,
|
||||
"aContext.mIMEState.mEnabled=%s, aAction.mFocusChange=%s), "
|
||||
"sEnabledTextStore=0x%p, ThinksHavingFocus()=%s",
|
||||
aWidget, GetIMEEnabledName(aContext.mIMEState.mEnabled),
|
||||
GetFocusChangeName(aAction.mFocusChange), sEnabledTextStore,
|
||||
GetFocusChangeName(aAction.mFocusChange), sEnabledTextStore.get(),
|
||||
GetBoolName(ThinksHavingFocus())));
|
||||
|
||||
NS_ENSURE_TRUE_VOID(IsInTSFMode());
|
||||
@ -4532,7 +4531,7 @@ nsTextStore::Initialize()
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
||||
("TSF: nsTextStore::Initialize() is called..."));
|
||||
|
||||
if (sTsfThreadMgr) {
|
||||
if (sThreadMgr) {
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
||||
("TSF: nsTextStore::Initialize() FAILED due to already initialized"));
|
||||
return;
|
||||
@ -4661,14 +4660,14 @@ nsTextStore::Initialize()
|
||||
return;
|
||||
}
|
||||
|
||||
inputProcessorProfiles.swap(sInputProcessorProfiles);
|
||||
threadMgr.swap(sTsfThreadMgr);
|
||||
messagePump.swap(sMessagePump);
|
||||
keystrokeMgr.swap(sKeystrokeMgr);
|
||||
displayAttributeMgr.swap(sDisplayAttrMgr);
|
||||
categoryMgr.swap(sCategoryMgr);
|
||||
disabledDocumentMgr.swap(sTsfDisabledDocumentMgr);
|
||||
disabledContext.swap(sTsfDisabledContext);
|
||||
sInputProcessorProfiles = inputProcessorProfiles;
|
||||
sThreadMgr = threadMgr;
|
||||
sMessagePump = messagePump;
|
||||
sKeystrokeMgr = keystrokeMgr;
|
||||
sDisplayAttrMgr = displayAttributeMgr;
|
||||
sCategoryMgr = categoryMgr;
|
||||
sDisabledDocumentMgr = disabledDocumentMgr;
|
||||
sDisabledContext = disabledContext;
|
||||
|
||||
sCreateNativeCaretForATOK =
|
||||
Preferences::GetBool("intl.tsf.hack.atok.create_native_caret", true);
|
||||
@ -4680,14 +4679,14 @@ nsTextStore::Initialize()
|
||||
"intl.tsf.hack.easy_changjei.do_not_return_no_layout_error", true);
|
||||
|
||||
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
||||
("TSF: nsTextStore::Initialize(), sTsfThreadMgr=0x%p, "
|
||||
("TSF: nsTextStore::Initialize(), sThreadMgr=0x%p, "
|
||||
"sTsfClientId=0x%08X, sDisplayAttrMgr=0x%p, "
|
||||
"sCategoryMgr=0x%p, sTsfDisabledDocumentMgr=0x%p, sTsfDisabledContext=%p, "
|
||||
"sCategoryMgr=0x%p, sDisabledDocumentMgr=0x%p, sDisabledContext=%p, "
|
||||
"sCreateNativeCaretForATOK=%s, "
|
||||
"sDoNotReturnNoLayoutErrorToFreeChangJie=%s, "
|
||||
"sDoNotReturnNoLayoutErrorToEasyChangjei=%s",
|
||||
sTsfThreadMgr, sTsfClientId, sDisplayAttrMgr,
|
||||
sCategoryMgr, sTsfDisabledDocumentMgr, sTsfDisabledContext,
|
||||
sThreadMgr.get(), sTsfClientId, sDisplayAttrMgr.get(),
|
||||
sCategoryMgr.get(), sDisabledDocumentMgr.get(), sDisabledContext.get(),
|
||||
GetBoolName(sCreateNativeCaretForATOK),
|
||||
GetBoolName(sDoNotReturnNoLayoutErrorToFreeChangJie),
|
||||
GetBoolName(sDoNotReturnNoLayoutErrorToEasyChangjei)));
|
||||
@ -4701,18 +4700,18 @@ nsTextStore::Terminate(void)
|
||||
|
||||
TSFStaticSink::Shutdown();
|
||||
|
||||
NS_IF_RELEASE(sDisplayAttrMgr);
|
||||
NS_IF_RELEASE(sCategoryMgr);
|
||||
sDisplayAttrMgr = nullptr;
|
||||
sCategoryMgr = nullptr;
|
||||
sEnabledTextStore = nullptr;
|
||||
NS_IF_RELEASE(sTsfDisabledDocumentMgr);
|
||||
NS_IF_RELEASE(sTsfDisabledContext);
|
||||
NS_IF_RELEASE(sInputProcessorProfiles);
|
||||
sDisabledDocumentMgr = nullptr;
|
||||
sDisabledContext = nullptr;
|
||||
sInputProcessorProfiles = nullptr;
|
||||
sTsfClientId = 0;
|
||||
if (sTsfThreadMgr) {
|
||||
sTsfThreadMgr->Deactivate();
|
||||
NS_RELEASE(sTsfThreadMgr);
|
||||
NS_RELEASE(sMessagePump);
|
||||
NS_RELEASE(sKeystrokeMgr);
|
||||
if (sThreadMgr) {
|
||||
sThreadMgr->Deactivate();
|
||||
sThreadMgr = nullptr;
|
||||
sMessagePump = nullptr;
|
||||
sKeystrokeMgr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,12 +170,13 @@ public:
|
||||
|
||||
// Returns the address of the pointer so that the TSF automatic test can
|
||||
// replace the system object with a custom implementation for testing.
|
||||
// XXX TSF doesn't work now. Should we remove it?
|
||||
static void* GetNativeData(uint32_t aDataType)
|
||||
{
|
||||
switch (aDataType) {
|
||||
case NS_NATIVE_TSF_THREAD_MGR:
|
||||
Initialize(); // Apply any previous changes
|
||||
return static_cast<void*>(&sTsfThreadMgr);
|
||||
return static_cast<void*>(&sThreadMgr);
|
||||
case NS_NATIVE_TSF_CATEGORY_MGR:
|
||||
return static_cast<void*>(&sCategoryMgr);
|
||||
case NS_NATIVE_TSF_DISPLAY_ATTR_MGR:
|
||||
@ -192,7 +193,7 @@ public:
|
||||
|
||||
static void* GetThreadManager()
|
||||
{
|
||||
return static_cast<void*>(sTsfThreadMgr);
|
||||
return static_cast<void*>(sThreadMgr);
|
||||
}
|
||||
|
||||
static bool ThinksHavingFocus()
|
||||
@ -202,7 +203,7 @@ public:
|
||||
|
||||
static bool IsInTSFMode()
|
||||
{
|
||||
return sTsfThreadMgr != nullptr;
|
||||
return sThreadMgr != nullptr;
|
||||
}
|
||||
|
||||
static bool IsComposing()
|
||||
@ -739,15 +740,15 @@ protected:
|
||||
bool mNativeCaretIsCreated;
|
||||
|
||||
// TSF thread manager object for the current application
|
||||
static ITfThreadMgr* sTsfThreadMgr;
|
||||
// sMessagePump is QI'ed from sTsfThreadMgr
|
||||
static ITfMessagePump* sMessagePump;
|
||||
// sKeystrokeMgr is QI'ed from sTsfThreadMgr
|
||||
static ITfKeystrokeMgr* sKeystrokeMgr;
|
||||
static mozilla::StaticRefPtr<ITfThreadMgr> sThreadMgr;
|
||||
// sMessagePump is QI'ed from sThreadMgr
|
||||
static mozilla::StaticRefPtr<ITfMessagePump> sMessagePump;
|
||||
// sKeystrokeMgr is QI'ed from sThreadMgr
|
||||
static mozilla::StaticRefPtr<ITfKeystrokeMgr> sKeystrokeMgr;
|
||||
// TSF display attribute manager
|
||||
static ITfDisplayAttributeMgr* sDisplayAttrMgr;
|
||||
static mozilla::StaticRefPtr<ITfDisplayAttributeMgr> sDisplayAttrMgr;
|
||||
// TSF category manager
|
||||
static ITfCategoryMgr* sCategoryMgr;
|
||||
static mozilla::StaticRefPtr<ITfCategoryMgr> sCategoryMgr;
|
||||
|
||||
// TSF client ID for the current application
|
||||
static DWORD sTsfClientId;
|
||||
@ -758,10 +759,11 @@ protected:
|
||||
static mozilla::StaticRefPtr<nsTextStore> sEnabledTextStore;
|
||||
|
||||
// For IME (keyboard) disabled state:
|
||||
static ITfDocumentMgr* sTsfDisabledDocumentMgr;
|
||||
static ITfContext* sTsfDisabledContext;
|
||||
static mozilla::StaticRefPtr<ITfDocumentMgr> sDisabledDocumentMgr;
|
||||
static mozilla::StaticRefPtr<ITfContext> sDisabledContext;
|
||||
|
||||
static ITfInputProcessorProfiles* sInputProcessorProfiles;
|
||||
static mozilla::StaticRefPtr<ITfInputProcessorProfiles>
|
||||
sInputProcessorProfiles;
|
||||
|
||||
// Enables/Disables hack for specific TIP.
|
||||
static bool sCreateNativeCaretForATOK;
|
||||
|
Loading…
Reference in New Issue
Block a user