Bug 1420215 - Make TSFTextStore set input scope of URL bar to IS_DEFAULT when some Microsoft's Trandtional and Simplified Chinese IMEs and some Microsoft's Korean IMEs which change their open state to "closed" when input scope is IS_URL r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 19 Dec 2017 13:13:45 +0900
changeset 712960 b05df734e0d51791f83a2c6324210f5012089295
parent 712959 ae1c9342bd6363fca2fa0cbc45d90bed81064023
child 712999 71a5de8f2afa01497d2c15e115f757f4359bc4be
push id93507
push usermasayuki@d-toybox.com
push dateTue, 19 Dec 2017 09:14:35 +0000
reviewersm_kato
bugs1420215
milestone59.0a1
Bug 1420215 - Make TSFTextStore set input scope of URL bar to IS_DEFAULT when some Microsoft's Trandtional and Simplified Chinese IMEs and some Microsoft's Korean IMEs which change their open state to "closed" when input scope is IS_URL r?m_kato This patch adds following Microsoft's IMEs into the black list which set their open state to "closed" when input scope is set to IS_URL and sets input scope for the URL bar to IS_DEFAULT. Additionally, this adds a new pref to disable this hack because a lot of users will affect this hack but perhaps, somebody may not like this if they use tablet. The new black listed IMEs: - Microsoft Bopomofo - Microsoft ChangJie - Microsoft Phonetic - Microsoft Quick - Microsoft New ChangJie - Microsoft New Phonetic - Microsoft New Quick - Microsoft Pinyin - Microsoft Pinyin New Experience Input Style - Microsoft Wubi - Microsoft IME for Korean (except on Win7) - Microsoft Old Hangul MozReview-Commit-ID: BwJKFcu80B8
modules/libpref/init/all.js
widget/windows/TSFTextStore.cpp
widget/windows/TSFTextStore.h
widget/windows/WinIMEHandler.cpp
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -3860,18 +3860,42 @@ pref("print.extend_native_print_dialog",
 pref("plugin.scan.plid.all", true);
 
 // Whether sending WM_MOUSEWHEEL and WM_MOUSEHWHEEL to plugins on Windows.
 pref("plugin.mousewheel.enabled", true);
 
 // Switch the keyboard layout per window
 pref("intl.keyboard.per_window_layout", false);
 
+// Whether Gecko sets input scope of the URL bar to IS_DEFAULT when black
+// listed IMEs are active.  If you use tablet mode mainly and you want to
+// use touch keyboard for URL when you set focus to the URL bar, you can
+// set this to false.  Then, you'll see, e.g., ".com" key on the keyboard.
+// However, if you set this to false, such IMEs set its open state to "closed"
+// when you set focus to the URL bar.  I.e., input mode is automatically
+// changed to English input mode.
+// Black listed IMEs:
+//   - Microsoft IME for Japanese
+//   - Google Japanese Input
+//   - Microsoft Bopomofo
+//   - Microsoft ChangJie
+//   - Microsoft Phonetic
+//   - Microsoft Quick
+//   - Microsoft New ChangJie
+//   - Microsoft New Phonetic
+//   - Microsoft New Quick
+//   - Microsoft Pinyin
+//   - Microsoft Pinyin New Experience Input Style
+//   - Microsoft Wubi
+//   - Microsoft IME for Korean (except on Win7)
+//   - Microsoft Old Hangul
+pref("intl.ime.hack.set_input_scope_of_url_bar_to_default", true);
+
 #ifdef NS_ENABLE_TSF
-// Enable/Disable TSF support on Vista or later.
+// Enable/Disable TSF support.
 pref("intl.tsf.enable", true);
 
 // Support IMEs implemented with IMM in TSF mode.
 pref("intl.tsf.support_imm", true);
 
 // This is referred only when both "intl.tsf.enable" and "intl.tsf.support_imm"
 // are true.  When this is true, default IMC is associated with focused window
 // only when active keyboard layout is a legacy IMM-IME.
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -1092,23 +1092,32 @@ public:
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsATOKActive)
   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(IsMSBopomofoActive)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSChangJieActive)
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSPhoneticActive)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSQuickActive)
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSNewChangJieActive)
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSNewPhoneticActive)
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSNewQuickActive)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsFreeChangJieActive)
 
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSPinyinActive)
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSPinyinNewExperienceInputStyleActive)
   DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSWubiActive)
 
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSKoreanIMEActive)
+  DECL_AND_IMPL_IS_TIP_ACTIVE(IsMSOldHangulActive)
+
 #undef DECL_AND_IMPL_IS_TIP_ACTIVE
 
   // Note that ATOK 2011 - 2016 refers native caret position for deciding its
   // popup window position.
   static bool IsATOKReferringNativeCaretActive()
   {
     RefPtr<TSFStaticSink> staticSink = GetInstance();
     if (NS_WARN_IF(!staticSink) ||
@@ -1233,51 +1242,91 @@ private:
 
   // * ATOK 2017
   //   - {6DBFD8F5-701D-11E6-920F-782BCBA6348F}
 
   /****************************************************************************
    * Traditional Chinese TIP
    ****************************************************************************/
 
+  bool IsMSBopomofoActiveInternal() const
+  {
+    // {B2F9C502-1742-11D4-9790-0080C882687E} (Win8.1, Win10)
+    static const GUID kGUID = {
+      0xB2F9C502, 0x1742, 0x11D4,
+        { 0x97, 0x90, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
   bool IsMSChangJieActiveInternal() 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 IsMSPhoneticActiveInternal() const
+  {
+    // {761309DE-317A-11D4-9B5D-0080C882687E} (Win7)
+    static const GUID kGUID = {
+      0x761309DE, 0x317A, 0x11D4,
+        { 0x9B, 0x5D, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
   bool IsMSQuickActiveInternal() const
   {
     // {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;
   }
 
+  bool IsMSNewChangJieActiveInternal() const
+  {
+    // {F3BA907A-6C7E-11D4-97FA-0080C882687E} (Win7)
+    static const GUID kGUID = {
+      0xF3BA907A, 0x6C7E, 0x11D4,
+        { 0x97, 0xFA, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
+  bool IsMSNewPhoneticActiveInternal() const
+  {
+    // {B2F9C502-1742-11D4-9790-0080C882687E} (Win7)
+    static const GUID kGUID = {
+      0xB2F9C502, 0x1742, 0x11D4,
+        { 0x97, 0x90, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
+  bool IsMSNewQuickActiveInternal() const
+  {
+    // {0B883BA0-C1C7-11D4-87F9-0080C882687E} (Win7)
+    static const GUID kGUID = {
+      0x0B883BA0, 0xC1C7, 0x11D4,
+        { 0x87, 0xF9, 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
   {
     // {B58630B5-0ED3-4335-BBC9-E77BBCB43CAD}
     static const GUID kGUID = {
       0xB58630B5, 0x0ED3, 0x4335,
         { 0xBB, 0xC9, 0xE7, 0x7B, 0xBC, 0xB4, 0x3C, 0xAD }
     };
@@ -1296,16 +1345,26 @@ private:
     // {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 IsMSPinyinNewExperienceInputStyleActiveInternal() const
+  {
+    // {F3BA9077-6C7E-11D4-97FA-0080C882687E} (Win7)
+    static const GUID kGUID = {
+      0xF3BA9077, 0x6C7E, 0x11D4,
+        { 0x97, 0xFA, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
   bool IsMSWubiActiveInternal() const
   {
     // {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;
@@ -1315,18 +1374,44 @@ private:
   // * 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)
+
+  /****************************************************************************
+   * Korean TIP
+   ****************************************************************************/
+
+  bool IsMSKoreanIMEActiveInternal() const
+  {
+    // {B5FE1F02-D5F2-4445-9C03-C568F23C99A1} (Win7, Win8.1, Win10)
+    static const GUID kGUID = {
+      0xB5FE1F02, 0xD5F2, 0x4445,
+        { 0x9C, 0x03, 0xC5, 0x68, 0xF2, 0x3C, 0x99, 0xA1 }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
+  bool IsMSOldHangulActiveInternal() const
+  {
+    // {B60AF051-257A-46BC-B9D3-84DAD819BAFB} (Win8.1, Win10)
+    static const GUID kGUID = {
+      0xB60AF051, 0x257A, 0x46BC,
+        { 0xB9, 0xD3, 0x84, 0xDA, 0xD8, 0x19, 0xBA, 0xFB }
+    };
+    return mActiveTIPGUID == kGUID;
+  }
+
+  // NOTE: There is the other Korean TIP installed in Windows:
+  // * Microsoft IME 2010
+  //   - {48878C45-93F9-4aaf-A6A1-272CD863C4F5} (Win7)
 
 public: // ITfInputProcessorProfileActivationSink
   STDMETHODIMP OnActivated(DWORD, LANGID, REFCLSID, REFGUID, REFGUID,
                            HKL, DWORD);
 
 private:
   TSFStaticSink();
   virtual ~TSFStaticSink() {}
@@ -1600,16 +1685,19 @@ public:
   static bool aName ()                                                         \
   {                                                                            \
     static bool s ## aName ## Value =                                          \
       Preferences::GetBool(aPref, aDefaultValue);                              \
     return s ## aName ## Value;                                                \
   }
 
   DECL_AND_IMPL_BOOL_PREF(
+    "intl.ime.hack.set_input_scope_of_url_bar_to_default",
+    ShouldSetInputScopeOfURLBarToDefault, true)
+  DECL_AND_IMPL_BOOL_PREF(
     "intl.tsf.hack.atok.create_native_caret",
     NeedToCreateNativeCaretForLegacyATOK, true)
   DECL_AND_IMPL_BOOL_PREF(
     "intl.tsf.hack.atok.do_not_return_no_layout_error_of_composition_string",
     DoNotReturnNoLayoutErrorToATOKOfCompositionString, true)
   DECL_AND_IMPL_BOOL_PREF(
     "intl.tsf.hack.ms_simplified_chinese.do_not_return_no_layout_error",
     DoNotReturnNoLayoutErrorToMSSimplifiedTIP, true)
@@ -3614,43 +3702,64 @@ TSFTextStore::InsertEmbedded(DWORD dwFla
   MOZ_LOG(sTextStoreLog, LogLevel::Info,
     ("0x%p TSFTextStore::InsertEmbedded() called "
      "but not supported (E_NOTIMPL)", this));
 
   // embedded objects are not supported
   return E_NOTIMPL;
 }
 
+// static
+bool
+TSFTextStore::ShouldSetInputScopeOfURLBarToDefault()
+{
+  // FYI: Google Japanese Input may be an IMM-IME.  If it's installed on
+  //      Win7, it's always IMM-IME.  Otherwise, basically, it's a TIP.
+  //      However, if it's installed on Win7 and has not been updated yet
+  //      after the OS is upgraded to Win8 or later, it's still an IMM-IME.
+  //      Therefore, we also need to check with IMMHandler here.
+  return TSFPrefs::ShouldSetInputScopeOfURLBarToDefault() &&
+         (IMMHandler::IsGoogleJapaneseInputActive() ||
+          (!TSFTextStore::IsIMM_IMEActive() &&
+           (TSFStaticSink::IsMSJapaneseIMEActive() ||
+            TSFStaticSink::IsGoogleJapaneseInputActive() ||
+            TSFStaticSink::IsMSBopomofoActive() ||
+            TSFStaticSink::IsMSChangJieActive() ||
+            TSFStaticSink::IsMSPhoneticActive() ||
+            TSFStaticSink::IsMSQuickActive() ||
+            TSFStaticSink::IsMSNewChangJieActive() ||
+            TSFStaticSink::IsMSNewPhoneticActive() ||
+            TSFStaticSink::IsMSNewQuickActive() ||
+            TSFStaticSink::IsMSPinyinActive() ||
+            TSFStaticSink::IsMSPinyinNewExperienceInputStyleActive() ||
+            (IsWin8OrLater() && TSFStaticSink::IsMSKoreanIMEActive()) ||
+            TSFStaticSink::IsMSOldHangulActive() ||
+            TSFStaticSink::IsMSWubiActive())));
+}
+
 void
 TSFTextStore::SetInputScope(const nsString& aHTMLInputType,
                             const nsString& aHTMLInputInputMode)
 {
   mInputScopes.Clear();
   if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) {
     if (aHTMLInputInputMode.EqualsLiteral("url")) {
       mInputScopes.AppendElement(IS_URL);
     } else if (aHTMLInputInputMode.EqualsLiteral("mozAwesomebar")) {
       // Even if Awesomebar has focus, user may not input URL directly.
       // However, on-screen keyboard for URL should be shown because it has
       // some useful additional keys like ".com" and they are not hindrances
       // even when inputting non-URL text, e.g., words to search something in
-      // the web.  On the other hand, MS-IME for Japanese and Google Japanese
-      // Input make their open state "closed" automatically if we notify them
-      // of URL as the input scope.  However, this is very annoying for the
-      // users when they try to input some words to search the web or
+      // the web.  On the other hand, a lot of Microsoft's IMEs and Google
+      // Japanese Input make their open state "closed" automatically if we
+      // notify them of URL as the input scope.  However, this is very annoying
+      // for the users when they try to input some words to search the web or
       // bookmark/history items.  Therefore, if they are active, we need to
       // notify them of the default input scope for avoiding this issue.
-      // FYI: Google Japanese Input may be an IMM-IME.  If it's installed on
-      //      Win7, it's always IMM-IME.  Otherwise, basically, it's a TIP.
-      //      However, if it's installed on Win7 and has not been updated yet
-      //      after the OS is upgraded to Win8 or later, it's still an IMM-IME.
-      //      Therefore, we also need to check with IMMHandler here.
-      if (TSFStaticSink::IsMSJapaneseIMEActive() ||
-          TSFStaticSink::IsGoogleJapaneseInputActive() ||
-          IMMHandler::IsGoogleJapaneseInputActive()) {
+      if (TSFTextStore::ShouldSetInputScopeOfURLBarToDefault()) {
         return;
       }
       // Don't append IS_SEARCH here for showing on-screen keyboard for URL.
       mInputScopes.AppendElement(IS_URL);
     } else if (aHTMLInputInputMode.EqualsLiteral("email")) {
       mInputScopes.AppendElement(IS_EMAIL_SMTPEMAILADDRESS);
     } else if (aHTMLInputType.EqualsLiteral("tel")) {
       mInputScopes.AppendElement(IS_TELEPHONE_FULLTELEPHONENUMBER);
--- a/widget/windows/TSFTextStore.h
+++ b/widget/windows/TSFTextStore.h
@@ -254,16 +254,22 @@ public:
    * Returns true if active TIP is Google Japanese Input.
    * Note that if Google Japanese Input is installed as an IMM-IME,
    * this return false even if Google Japanese Input is active.
    * So, you may need to check IMMHandler::IsGoogleJapaneseInputActive() too.
    */
   static bool IsGoogleJapaneseInputActive();
 
   /**
+   * Returns true if active TIP or IME is a black listed one and we should
+   * set input scope of URL bar to IS_DEFAULT rather than IS_URL.
+   */
+  static bool ShouldSetInputScopeOfURLBarToDefault();
+
+  /**
    * Returns true if TSF may crash if GetSelection() returns E_FAIL.
    */
   static bool DoNotReturnErrorFromGetSelection();
 
 #ifdef DEBUG
   // Returns true when keyboard layout has IME (TIP).
   static bool     CurrentKeyboardLayoutHasIME();
 #endif // #ifdef DEBUG
--- a/widget/windows/WinIMEHandler.cpp
+++ b/widget/windows/WinIMEHandler.cpp
@@ -632,29 +632,29 @@ IMEHandler::SetInputScopeForIMM32(nsWind
       static const InputScope inputScopes[] = { IS_URL };
       scopes = &inputScopes[0];
       arraySize = ArrayLength(inputScopes);
     } else if (aHTMLInputInputmode.EqualsLiteral("mozAwesomebar")) {
       // Even if Awesomebar has focus, user may not input URL directly.
       // However, on-screen keyboard for URL should be shown because it has
       // some useful additional keys like ".com" and they are not hindrances
       // even when inputting non-URL text, e.g., words to search something in
-      // the web.  On the other hand, MS-IME for Japanese and Google Japanese
-      // Input make their open state "closed" automatically if we notify them
-      // of URL as the input scope.  However, this is very annoying for the
-      // users when they try to input some words to search the web or
+      // the web.  On the other hand, a lot of Microsoft's IMEs and Google
+      // Japanese Input make their open state "closed" automatically if we
+      // notify them of URL as the input scope.  However, this is very annoying
+      // for the users when they try to input some words to search the web or
       // bookmark/history items.  Therefore, if they are active, we need to
       // notify them of the default input scope for avoiding this issue.
       // FYI: We cannot check active TIP without TSF.  Therefore, if it's
-      //      not in TSF mode, we can check only if active IMM-IME is Google
+      //      not in TSF mode, this will check only if active IMM-IME is Google
       //      Japanese Input.  Google Japanese Input is a TIP of TSF basically.
       //      However, if the OS is Win7 or it's installed on Win7 but has not
       //      been updated yet even after the OS is upgraded to Win8 or later,
       //      it's installed as IMM-IME.
-      if (IMMHandler::IsGoogleJapaneseInputActive()) {
+      if (TSFTextStore::ShouldSetInputScopeOfURLBarToDefault()) {
         static const InputScope inputScopes[] = { IS_DEFAULT };
         scopes = &inputScopes[0];
         arraySize = ArrayLength(inputScopes);
       } else {
         static const InputScope inputScopes[] = { IS_URL };
         scopes = &inputScopes[0];
         arraySize = ArrayLength(inputScopes);
       }