--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -21,17 +21,16 @@
#define INPUTSCOPE_INIT_GUID
#define TEXTATTRS_INIT_GUID
#include "TSFTextStore.h"
namespace mozilla {
namespace widget {
static const char* kPrefNameEnableTSF = "intl.tsf.enable";
-static const char* kPrefNameForceEnableTSF = "intl.tsf.force_enable";
/**
* TSF related code should log its behavior even on release build especially
* in the interface methods.
*
* In interface methods, use LogLevel::Info.
* In internal methods, use LogLevel::Debug for logging normal behavior.
* For logging error, use LogLevel::Error.
@@ -730,18 +729,17 @@ public:
private:
nsTArray<InputScope> mInputScopes;
};
/******************************************************************/
/* TSFStaticSink */
/******************************************************************/
-class TSFStaticSink final : public ITfActiveLanguageProfileNotifySink
- , public ITfInputProcessorProfileActivationSink
+class TSFStaticSink final : public ITfInputProcessorProfileActivationSink
{
public:
static TSFStaticSink* GetInstance()
{
if (!sInstance) {
sInstance = new TSFStaticSink();
}
return sInstance;
@@ -756,19 +754,17 @@ public:
}
bool Init(ITfThreadMgr* aThreadMgr,
ITfInputProcessorProfiles* aInputProcessorProfiles);
STDMETHODIMP QueryInterface(REFIID riid, void** ppv)
{
*ppv = nullptr;
if (IID_IUnknown == riid ||
- IID_ITfActiveLanguageProfileNotifySink == riid) {
- *ppv = static_cast<ITfActiveLanguageProfileNotifySink*>(this);
- } else if (IID_ITfInputProcessorProfileActivationSink == riid) {
+ IID_ITfInputProcessorProfileActivationSink == riid) {
*ppv = static_cast<ITfInputProcessorProfileActivationSink*>(this);
}
if (*ppv) {
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
@@ -887,20 +883,16 @@ public:
{
return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft Wubi") ||
mActiveTIPKeyboardDescription.Equals(
NS_LITERAL_STRING("\x5FAE\x8F6F\x4E94\x7B14")) ||
mActiveTIPKeyboardDescription.Equals(
NS_LITERAL_STRING("\x5FAE\x8EDF\x4E94\x7B46"));
}
-public: // ITfActiveLanguageProfileNotifySink
- STDMETHODIMP OnActivated(REFCLSID clsid, REFGUID guidProfile,
- BOOL fActivated);
-
public: // ITfInputProcessorProfileActivationSink
STDMETHODIMP OnActivated(DWORD, LANGID, REFCLSID, REFGUID, REFGUID,
HKL, DWORD);
private:
TSFStaticSink();
virtual ~TSFStaticSink() {}
@@ -908,18 +900,16 @@ private:
void GetTIPDescription(REFCLSID aTextService, LANGID aLangID,
REFGUID aProfile, nsAString& aDescription);
bool IsTIPCategoryKeyboard(REFCLSID aTextService, LANGID aLangID,
REFGUID aProfile);
// Cookie of installing ITfInputProcessorProfileActivationSink
DWORD mIPProfileCookie;
- // Cookie of installing ITfActiveLanguageProfileNotifySink
- DWORD mLangProfileCookie;
LANGID mLangID;
// True if current IME is implemented with IMM.
bool mIsIMM_IME;
// True if OnActivated() is already called
bool mOnActivatedCalled;
@@ -935,17 +925,16 @@ private:
static StaticRefPtr<TSFStaticSink> sInstance;
};
StaticRefPtr<TSFStaticSink> TSFStaticSink::sInstance;
TSFStaticSink::TSFStaticSink()
: mIPProfileCookie(TF_INVALID_COOKIE)
- , mLangProfileCookie(TF_INVALID_COOKIE)
, mLangID(0)
, mIsIMM_IME(false)
, mOnActivatedCalled(false)
, mActiveTIPGUID(GUID_NULL)
{
}
bool
@@ -963,56 +952,42 @@ TSFStaticSink::Init(ITfThreadMgr* aThrea
mThreadMgr->QueryInterface(IID_ITfSource, getter_AddRefs(source));
if (FAILED(hr)) {
MOZ_LOG(sTextStoreLog, LogLevel::Error,
("TSF: 0x%p TSFStaticSink::Init() FAILED to get ITfSource "
"instance (0x%08X)", this, hr));
return false;
}
- // On Vista or later, Windows let us know activate IME changed only with
- // ITfInputProcessorProfileActivationSink. However, it's not available on XP.
- // On XP, ITfActiveLanguageProfileNotifySink is available for it.
- // NOTE: Each OnActivated() should be called when TSF becomes available.
- if (IsVistaOrLater()) {
- hr = source->AdviseSink(IID_ITfInputProcessorProfileActivationSink,
- static_cast<ITfInputProcessorProfileActivationSink*>(this),
- &mIPProfileCookie);
- if (FAILED(hr) || mIPProfileCookie == TF_INVALID_COOKIE) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: 0x%p TSFStaticSink::Init() FAILED to install "
- "ITfInputProcessorProfileActivationSink (0x%08X)", this, hr));
- return false;
- }
- } else {
- hr = source->AdviseSink(IID_ITfActiveLanguageProfileNotifySink,
- static_cast<ITfActiveLanguageProfileNotifySink*>(this),
- &mLangProfileCookie);
- if (FAILED(hr) || mLangProfileCookie == TF_INVALID_COOKIE) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: 0x%p TSFStaticSink::Init() FAILED to install "
- "ITfActiveLanguageProfileNotifySink (0x%08X)", this, hr));
- return false;
- }
+ // NOTE: On Vista or later, Windows let us know activate IME changed only
+ // with ITfInputProcessorProfileActivationSink.
+ hr = source->AdviseSink(IID_ITfInputProcessorProfileActivationSink,
+ static_cast<ITfInputProcessorProfileActivationSink*>(this),
+ &mIPProfileCookie);
+ if (FAILED(hr) || mIPProfileCookie == TF_INVALID_COOKIE) {
+ MOZ_LOG(sTextStoreLog, LogLevel::Error,
+ ("TSF: 0x%p TSFStaticSink::Init() FAILED to install "
+ "ITfInputProcessorProfileActivationSink (0x%08X)", this, hr));
+ return false;
}
MOZ_LOG(sTextStoreLog, LogLevel::Info,
("TSF: 0x%p TSFStaticSink::Init(), "
- "mIPProfileCookie=0x%08X, mLangProfileCookie=0x%08X",
- this, mIPProfileCookie, mLangProfileCookie));
+ "mIPProfileCookie=0x%08X",
+ this, mIPProfileCookie));
return true;
}
void
TSFStaticSink::Destroy()
{
MOZ_LOG(sTextStoreLog, LogLevel::Info,
("TSF: 0x%p TSFStaticSink::Shutdown() "
- "mIPProfileCookie=0x%08X, mLangProfileCookie=0x%08X",
- this, mIPProfileCookie, mLangProfileCookie));
+ "mIPProfileCookie=0x%08X",
+ this, mIPProfileCookie));
if (mIPProfileCookie != TF_INVALID_COOKIE) {
RefPtr<ITfSource> source;
HRESULT hr =
mThreadMgr->QueryInterface(IID_ITfSource, getter_AddRefs(source));
if (FAILED(hr)) {
MOZ_LOG(sTextStoreLog, LogLevel::Error,
("TSF: 0x%p TSFStaticSink::Shutdown() FAILED to get "
@@ -1023,86 +998,29 @@ TSFStaticSink::Destroy()
MOZ_LOG(sTextStoreLog, LogLevel::Error,
("TSF: 0x%p TSFTextStore::Shutdown() FAILED to uninstall "
"ITfInputProcessorProfileActivationSink (0x%08X)",
this, hr));
}
}
}
- if (mLangProfileCookie != TF_INVALID_COOKIE) {
- RefPtr<ITfSource> source;
- HRESULT hr =
- mThreadMgr->QueryInterface(IID_ITfSource, getter_AddRefs(source));
- if (FAILED(hr)) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: 0x%p TSFStaticSink::Shutdown() FAILED to get "
- "ITfSource instance (0x%08X)", this, hr));
- } else {
- hr = source->UnadviseSink(mLangProfileCookie);
- if (FAILED(hr)) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: 0x%p TSFStaticSink::Shutdown() FAILED to uninstall "
- "ITfActiveLanguageProfileNotifySink (0x%08X)",
- this, hr));
- }
- }
- }
-
mThreadMgr = nullptr;
mInputProcessorProfiles = nullptr;
}
STDMETHODIMP
-TSFStaticSink::OnActivated(REFCLSID clsid, REFGUID guidProfile,
- BOOL fActivated)
-{
- // NOTE: This is installed only on XP or Server 2003.
- if (fActivated) {
- // TODO: We should check if the profile's category is keyboard or not.
- mOnActivatedCalled = true;
- mActiveTIPGUID = guidProfile;
- mIsIMM_IME = IsIMM_IME(::GetKeyboardLayout(0));
-
- HRESULT hr = mInputProcessorProfiles->GetCurrentLanguage(&mLangID);
- if (FAILED(hr)) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: TSFStaticSink::OnActivated() FAILED due to "
- "GetCurrentLanguage() failure, hr=0x%08X", hr));
- } else if (IsTIPCategoryKeyboard(clsid, mLangID, guidProfile)) {
- GetTIPDescription(clsid, mLangID, guidProfile,
- mActiveTIPKeyboardDescription);
- } else if (clsid == CLSID_NULL || guidProfile == GUID_NULL) {
- // Perhaps, this case is that keyboard layout without TIP is activated.
- mActiveTIPKeyboardDescription.Truncate();
- }
- }
-
- MOZ_LOG(sTextStoreLog, LogLevel::Info,
- ("TSF: 0x%p TSFStaticSink::OnActivated(rclsid=%s, guidProfile=%s, "
- "fActivated=%s), mIsIMM_IME=%s, mActiveTIPDescription=\"%s\"",
- this, GetCLSIDNameStr(clsid).get(),
- GetGUIDNameStr(guidProfile).get(), GetBoolName(fActivated),
- GetBoolName(mIsIMM_IME),
- NS_ConvertUTF16toUTF8(mActiveTIPKeyboardDescription).get()));
- return S_OK;
-}
-
-STDMETHODIMP
TSFStaticSink::OnActivated(DWORD dwProfileType,
LANGID langid,
REFCLSID rclsid,
REFGUID catid,
REFGUID guidProfile,
HKL hkl,
DWORD dwFlags)
{
- // NOTE: This is installed only on Vista or later. However, this may be
- // called by EnsureInitActiveLanguageProfile() even on XP or Server
- // 2003.
if ((dwFlags & TF_IPSINK_FLAG_ACTIVE) &&
(dwProfileType == TF_PROFILETYPE_KEYBOARDLAYOUT ||
catid == GUID_TFCAT_TIP_KEYBOARD)) {
mOnActivatedCalled = true;
mActiveTIPGUID = guidProfile;
mLangID = langid;
mIsIMM_IME = IsIMM_IME(hkl);
GetTIPDescription(rclsid, mLangID, guidProfile,
@@ -1127,98 +1045,50 @@ TSFStaticSink::OnActivated(DWORD dwProfi
bool
TSFStaticSink::EnsureInitActiveTIPKeyboard()
{
if (mOnActivatedCalled) {
return true;
}
- if (IsVistaOrLater()) {
- RefPtr<ITfInputProcessorProfileMgr> profileMgr;
- HRESULT hr =
- mInputProcessorProfiles->QueryInterface(IID_ITfInputProcessorProfileMgr,
- getter_AddRefs(profileMgr));
- if (FAILED(hr) || !profileMgr) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), FAILED "
- "to get input processor profile manager, hr=0x%08X", this, hr));
- return false;
- }
-
- TF_INPUTPROCESSORPROFILE profile;
- hr = profileMgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &profile);
- if (hr == S_FALSE) {
- MOZ_LOG(sTextStoreLog, LogLevel::Info,
- ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), FAILED "
- "to get active keyboard layout profile due to no active profile, "
- "hr=0x%08X", this, hr));
- // XXX Should we call OnActivated() with arguments like non-TIP in this
- // case?
- return false;
- }
- if (FAILED(hr)) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), FAILED "
- "to get active TIP keyboard, hr=0x%08X", this, hr));
- return false;
- }
-
+ RefPtr<ITfInputProcessorProfileMgr> profileMgr;
+ HRESULT hr =
+ mInputProcessorProfiles->QueryInterface(IID_ITfInputProcessorProfileMgr,
+ getter_AddRefs(profileMgr));
+ if (FAILED(hr) || !profileMgr) {
+ MOZ_LOG(sTextStoreLog, LogLevel::Error,
+ ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), FAILED "
+ "to get input processor profile manager, hr=0x%08X", this, hr));
+ return false;
+ }
+
+ TF_INPUTPROCESSORPROFILE profile;
+ hr = profileMgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &profile);
+ if (hr == S_FALSE) {
MOZ_LOG(sTextStoreLog, LogLevel::Info,
- ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), "
- "calling OnActivated() manually...", this));
- OnActivated(profile.dwProfileType, profile.langid, profile.clsid,
- profile.catid, profile.guidProfile, ::GetKeyboardLayout(0),
- TF_IPSINK_FLAG_ACTIVE);
- return true;
- }
-
- LANGID langID;
- HRESULT hr = mInputProcessorProfiles->GetCurrentLanguage(&langID);
+ ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), FAILED "
+ "to get active keyboard layout profile due to no active profile, "
+ "hr=0x%08X", this, hr));
+ // XXX Should we call OnActivated() with arguments like non-TIP in this
+ // case?
+ return false;
+ }
if (FAILED(hr)) {
MOZ_LOG(sTextStoreLog, LogLevel::Error,
("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), FAILED "
- "to get current language ID, hr=0x%08X", this, hr));
- return false;
- }
-
- RefPtr<IEnumTfLanguageProfiles> enumLangProfiles;
- hr = mInputProcessorProfiles->EnumLanguageProfiles(langID,
- getter_AddRefs(enumLangProfiles));
- if (FAILED(hr) || !enumLangProfiles) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), FAILED "
- "to get language profiles enumerator, hr=0x%08X", this, hr));
+ "to get active TIP keyboard, hr=0x%08X", this, hr));
return false;
}
- TF_LANGUAGEPROFILE profile;
- ULONG fetch = 0;
- while (SUCCEEDED(enumLangProfiles->Next(1, &profile, &fetch)) && fetch) {
- if (!profile.fActive || profile.catid != GUID_TFCAT_TIP_KEYBOARD) {
- continue;
- }
- MOZ_LOG(sTextStoreLog, LogLevel::Info,
- ("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), "
- "calling OnActivated() manually...", this));
- bool isTIP = profile.guidProfile != GUID_NULL;
- OnActivated(isTIP ? TF_PROFILETYPE_INPUTPROCESSOR :
- TF_PROFILETYPE_KEYBOARDLAYOUT,
- profile.langid, profile.clsid, profile.catid,
- profile.guidProfile, ::GetKeyboardLayout(0),
- TF_IPSINK_FLAG_ACTIVE);
- return true;
- }
-
MOZ_LOG(sTextStoreLog, LogLevel::Info,
("TSF: 0x%p TSFStaticSink::EnsureInitActiveLanguageProfile(), "
- "calling OnActivated() without active TIP manually...", this));
- OnActivated(TF_PROFILETYPE_KEYBOARDLAYOUT,
- langID, CLSID_NULL, GUID_TFCAT_TIP_KEYBOARD,
- GUID_NULL, ::GetKeyboardLayout(0),
+ "calling OnActivated() manually...", this));
+ OnActivated(profile.dwProfileType, profile.langid, profile.clsid,
+ profile.catid, profile.guidProfile, ::GetKeyboardLayout(0),
TF_IPSINK_FLAG_ACTIVE);
return true;
}
void
TSFStaticSink::GetTIPDescription(REFCLSID aTextService, LANGID aLangID,
REFGUID aProfile, nsAString& aDescription)
{
@@ -5385,18 +5255,17 @@ TSFTextStore::Initialize()
if (sThreadMgr) {
MOZ_LOG(sTextStoreLog, LogLevel::Error,
("TSF: TSFTextStore::Initialize() FAILED due to already initialized"));
return;
}
bool enableTsf =
- Preferences::GetBool(kPrefNameForceEnableTSF, false) ||
- (IsVistaOrLater() && Preferences::GetBool(kPrefNameEnableTSF, false));
+ IsVistaOrLater() && Preferences::GetBool(kPrefNameEnableTSF, false);
MOZ_LOG(sTextStoreLog, LogLevel::Info,
("TSF: TSFTextStore::Initialize(), TSF is %s",
enableTsf ? "enabled" : "disabled"));
if (!enableTsf) {
return;
}
// XXX MSDN documents that ITfInputProcessorProfiles is available only on
@@ -5991,26 +5860,20 @@ TSFTextStore::CurrentKeyboardLayoutHasIM
RefPtr<ITfInputProcessorProfileMgr> profileMgr;
HRESULT hr =
sInputProcessorProfiles->QueryInterface(IID_ITfInputProcessorProfileMgr,
getter_AddRefs(profileMgr));
if (FAILED(hr) || !profileMgr) {
// On Windows Vista or later, ImmIsIME() API always returns true.
// If we failed to obtain the profile manager, we cannot know if current
// keyboard layout has IME.
- if (IsVistaOrLater()) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- ("TSF: TSFTextStore::CurrentKeyboardLayoutHasIME() FAILED to query "
- "ITfInputProcessorProfileMgr"));
- return false;
- }
- // If the profiles instance doesn't have ITfInputProcessorProfileMgr
- // interface, that means probably we're running on WinXP or WinServer2003
- // (except WinServer2003 R2). Then, we should use ImmIsIME().
- return ::ImmIsIME(::GetKeyboardLayout(0));
+ MOZ_LOG(sTextStoreLog, LogLevel::Error,
+ ("TSF: TSFTextStore::CurrentKeyboardLayoutHasIME() FAILED to query "
+ "ITfInputProcessorProfileMgr"));
+ return false;
}
TF_INPUTPROCESSORPROFILE profile;
hr = profileMgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &profile);
if (hr == S_FALSE) {
return false; // not found or not active
}
if (FAILED(hr)) {