Bug 1372516 - TSFStaticSink should compare GUID rather than name when checking active TIP r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 13 Jun 2017 18:36:21 +0900
changeset 593236 6abf4f481ec76d4ef050a350aa0244772aa5b177
parent 593235 be6b3339189dfd92e4e1559be542139862748212
child 633066 8de1ff798e9913fcb7be1b4aa063cca0b0261b76
push id63646
push usermasayuki@d-toybox.com
push dateTue, 13 Jun 2017 11:02:04 +0000
reviewersm_kato
bugs1372516
milestone56.0a1
Bug 1372516 - TSFStaticSink should compare GUID rather than name when checking active TIP r?m_kato TIP name may be localed on some locales of Windows. Additionally, names may be updated in the future releases. So, it's safer to use GUID rather than name when TSFStaticSink checks active TIP is a specific one. MozReview-Commit-ID: 6HNePZV7kgJ
widget/windows/TSFTextStore.cpp
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -1091,17 +1091,17 @@ public:
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsATOK2011Active)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsATOK2012Active)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsATOK2013Active)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsATOK2014Active)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsATOK2015Active)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsATOK2016Active)
 
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSChangJieActive)
-  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSQuickQuickActive)
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSQuickActive)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsFreeChangJieActive)
 
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSPinyinActive)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSWubiActive)
 
 #undef DECL_AND_IMPL_IS_TIP_ACTIVE
 
   // Note that ATOK 2011 - 2016 refers native caret position for deciding its
@@ -1124,30 +1124,27 @@ public:
 
 private:
   /****************************************************************************
    * Japanese TIP
    ****************************************************************************/
 
   // Note that TIP name may depend on the language of the environment.
   // For example, some TIP may use localized name for its target language
-  // environment but English name for the others.
+  // environment but English name for the others.  Therefore, we should
+  // compare GUID as far as possible.
 
   bool IsMSJapaneseIMEActiveInternal() const
   {
-    // FYI: Name of MS-IME for Japanese is same as MS-IME for Korean.
-    //      Therefore, we need to check the langid too.
-    return mLangID == 0x411 &&
-      (mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft IME") ||
-       mActiveTIPKeyboardDescription.Equals(
-         NS_LITERAL_STRING(u"Microsoft \xC785\xB825\xAE30")) ||
-       mActiveTIPKeyboardDescription.Equals(
-         NS_LITERAL_STRING(u"\x5FAE\x8F6F\x8F93\x5165\x6CD5")) ||
-       mActiveTIPKeyboardDescription.Equals(
-         NS_LITERAL_STRING(u"\x5FAE\x8EDF\x8F38\x5165\x6CD5")));
+    // {A76C93D9-5523-4E90-AAFA-4DB112F9AC76} (Win7, Win8.1, Win10)
+    static const GUID kGUID = {
+      0xA76C93D9, 0x5523, 0x4E90,
+        { 0xAA, 0xFA, 0x4D, 0xB1, 0x12, 0xF9, 0xAC, 0x76 }
+    };
+    return mActiveTIPGUID == kGUID;
   }
 
   bool IsMSOfficeJapaneseIME2010ActiveInternal() const
   {
     // {54EDCC94-1524-4BB1-9FB7-7BABE4F4CA64}
     static const GUID kGUID = {
       0x54EDCC94, 0x1524, 0x4BB1,
         { 0x9F, 0xB7, 0x7B, 0xAB, 0xE4, 0xF4, 0xCA, 0x64 }
@@ -1217,65 +1214,109 @@ private:
     // {0B557B4C-5740-4110-A60A-1493FA10BF2B}
     static const GUID kGUID = {
       0x0B557B4C, 0x5740, 0x4110,
         { 0xA6, 0x0A, 0x14, 0x93, 0xFA, 0x10, 0xBF, 0x2B }
     };
     return mActiveTIPGUID == kGUID;
   }
 
+  // * ATOK 2017
+  //   - {6DBFD8F5-701D-11E6-920F-782BCBA6348F}
+  // * Google Japanese Input
+  //   - {773EB24E-CA1D-4B1B-B420-FA985BB0B80D}
+
   /****************************************************************************
    * Traditional Chinese TIP
    ****************************************************************************/
 
   bool IsMSChangJieActiveInternal() const
   {
-    return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft ChangJie") ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8F6F\x4ED3\x9889")) ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8EDF\x5009\x9821"));
-  }
-
-  bool IsMSQuickQuickActiveInternal() const
+    // {4BDF9F03-C7D3-11D4-B2AB-0080C882687E} (Win7, Win8.1, Win10)
+    static const GUID kGUID = {
+      0x4BDF9F03, 0xC7D3, 0x11D4,
+        { 0xB2, 0xAB, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
+  bool IsMSQuickActiveInternal() const
   {
-    return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft Quick") ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8F6F\x901F\x6210")) ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8EDF\x901F\x6210"));
-  }
+    // {6024B45F-5C54-11D4-B921-0080C882687E} (Win7, Win8.1, Win10)
+    static const GUID kGUID = {
+      0x6024B45F, 0x5C54, 0x11D4,
+        { 0xB9, 0x21, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
+  // NOTE: There are some other Traditional Chinese TIPs installed in Windows:
+  // * Microsoft Bopomofo
+  //   - {B2F9C502-1742-11D4-9790-0080C882687E} (Win8.1, Win10)
+  // * Chinese Traditional Array (version 6.0)
+  //   - {D38EFF65-AA46-4FD5-91A7-67845FB02F5B} (Win7, Win8.1)
+  // * Chinese Traditional DaYi (version 6.0)
+  //   - {037B2C25-480C-4D7F-B027-D6CA6B69788A} (Win7, Win8.1)
+  // * Phonetic
+  //   - {761309DE-317A-11D4-9B5D-0080C882687E} (Win7)
+  // * New ChangJie
+  //   - {F3BA907A-6C7E-11D4-97FA-0080C882687E} (Win7)
+  // * New Phonetic
+  //   - {B2F9C502-1742-11D4-9790-0080C882687E} (Win7)
+  // * New Quick
+  //   - {0B883BA0-C1C7-11D4-87F9-0080C882687E} (Win7)
 
   bool IsFreeChangJieActiveInternal() const
   {
-    // FYI: The TIP name is misspelled...
-    return mActiveTIPKeyboardDescription.EqualsLiteral("Free CangJie IME 10");
+    // {B58630B5-0ED3-4335-BBC9-E77BBCB43CAD}
+    static const GUID kGUID = {
+      0xB58630B5, 0x0ED3, 0x4335,
+        { 0xBB, 0xC9, 0xE7, 0x7B, 0xBC, 0xB4, 0x3C, 0xAD }
+    };
+    return mActiveTIPGUID == kGUID;
   }
 
   /****************************************************************************
    * Simplified Chinese TIP
    ****************************************************************************/
 
   bool IsMSPinyinActiveInternal() const
   {
-    return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft Pinyin") ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8F6F\x62FC\x97F3")) ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8EDF\x62FC\x97F3"));
+    // FYI: This matches with neither "Microsoft Pinyin ABC Input Style" nor
+    //      "Microsoft Pinyin New Experience Input Style" on Win7.
+
+    // {FA550B04-5AD7-411F-A5AC-CA038EC515D7} (Win8.1, Win10)
+    static const GUID kGUID = {
+      0xFA550B04, 0x5AD7, 0x411F,
+        { 0xA5, 0xAC, 0xCA, 0x03, 0x8E, 0xC5, 0x15, 0xD7 }
+    };
+    return mActiveTIPGUID == kGUID;
   }
 
   bool IsMSWubiActiveInternal() const
   {
-    return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft Wubi") ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8F6F\x4E94\x7B14")) ||
-      mActiveTIPKeyboardDescription.Equals(
-        NS_LITERAL_STRING(u"\x5FAE\x8EDF\x4E94\x7B46"));
-  }
+    // {82590C13-F4DD-44F4-BA1D-8667246FDF8E} (Win8.1, Win10)
+    static const GUID kGUID = {
+      0x82590C13, 0xF4DD, 0x44F4,
+        { 0xBA, 0x1D, 0x86, 0x67, 0x24, 0x6F, 0xDF, 0x8E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
+  // NOTE: There are some other Simplified Chinese TIPs installed in Windows:
+  // * Chinese Simplified QuanPin (version 6.0)
+  //   - {54FC610E-6ABD-4685-9DDD-A130BDF1B170} (Win8.1)
+  // * Chinese Simplified ZhengMa (version 6.0)
+  //   - {733B4D81-3BC3-4132-B91A-E9CDD5E2BFC9} (Win8.1)
+  // * Chinese Simplified ShuangPin (version 6.0)
+  //   - {EF63706D-31C4-490E-9DBB-BD150ADC454B} (Win8.1)
+  // * Microsoft Pinyin ABC Input Style
+  //   - {FCA121D2-8C6D-41FB-B2DE-A2AD110D4820} (Win7)
+  // * Microsoft Pinyin New Experience Input Style
+  //   - {F3BA9077-6C7E-11D4-97FA-0080C882687E} (Win7)
 
 public: // ITfInputProcessorProfileActivationSink
   STDMETHODIMP OnActivated(DWORD, LANGID, REFCLSID, REFGUID, REFGUID,
                            HKL, DWORD);
 
 private:
   TSFStaticSink();
   virtual ~TSFStaticSink() {}
@@ -2380,17 +2421,17 @@ TSFTextStore::QueryInsert(LONG acpTestSt
     return E_INVALIDARG;
   }
 
   // XXX need to adjust to cluster boundary
   // Assume we are given good offsets for now
   if (IsWin8OrLater() && !mComposition.IsComposing() &&
       ((TSFPrefs::NeedToHackQueryInsertForMSTraditionalTIP() &&
          (TSFStaticSink::IsMSChangJieActive() ||
-          TSFStaticSink::IsMSQuickQuickActive())) ||
+          TSFStaticSink::IsMSQuickActive())) ||
        (TSFPrefs::NeedToHackQueryInsertForMSSimplifiedTIP() &&
          (TSFStaticSink::IsMSPinyinActive() ||
           TSFStaticSink::IsMSWubiActive())))) {
     MOZ_LOG(sTextStoreLog, LogLevel::Warning,
       ("0x%p   TSFTextStore::QueryInsert() WARNING using different "
        "result for the TIP", this));
     // Chinese TIPs of Microsoft assume that QueryInsert() returns selected
     // range which should be removed.
@@ -4145,17 +4186,17 @@ TSFTextStore::GetTextExt(TsViewCookie vc
       dontReturnNoLayoutError = true;
     }
     // Some Chinese TIPs of Microsoft doesn't show candidate window in e10s
     // mode on Win8 or later.
     else if (
       IsWin8OrLater() &&
       ((TSFPrefs::DoNotReturnNoLayoutErrorToMSTraditionalTIP() &&
         (TSFStaticSink::IsMSChangJieActive() ||
-         TSFStaticSink::IsMSQuickQuickActive())) ||
+         TSFStaticSink::IsMSQuickActive())) ||
        (TSFPrefs::DoNotReturnNoLayoutErrorToMSSimplifiedTIP() &&
          (TSFStaticSink::IsMSPinyinActive() ||
           TSFStaticSink::IsMSWubiActive())))) {
       acpEnd = mComposition.mStart;
       acpStart = std::min(acpStart, acpEnd);
       dontReturnNoLayoutError = true;
     }