[go: up one dir, main page]

Override IsInputLocaleCJK() in InputMethodWinTSF.

We should return true in InputMethodWinTSF::IsInputLocaleCJK() if
current active input language is Chinese, Japanese and Korean.

TBR=siliu@microsoft.com

(cherry picked from commit 9ff13081c1766eac6edc574d3af12e72519e8091)

Bug: 965319
Change-Id: Iac359a9d435efc16760e0b5f28da58aa0615054b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1637921
Commit-Queue: Siye Liu <siliu@microsoft.com>
Reviewed-by: Shu Chen <shuchen@chromium.org>
Reviewed-by: Yohei Yukawa <yukawa@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#669065}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662501
Reviewed-by: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#365}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/ui/base/ime/win/input_method_win_tsf.cc b/ui/base/ime/win/input_method_win_tsf.cc
index 5eff607..972945e 100644
--- a/ui/base/ime/win/input_method_win_tsf.cc
+++ b/ui/base/ime/win/input_method_win_tsf.cc
@@ -129,6 +129,14 @@
   ui::TSFBridge::GetInstance()->RemoveFocusedClient(client);
 }
 
+bool InputMethodWinTSF::IsInputLocaleCJK() const {
+  if (!ui::TSFBridge::GetInstance()) {
+    return false;
+  }
+
+  return ui::TSFBridge::GetInstance()->IsInputLanguageCJK();
+}
+
 bool InputMethodWinTSF::IsCandidatePopupOpen() const {
   return tsf_event_observer_->IsCandidatePopupOpen();
 }
diff --git a/ui/base/ime/win/input_method_win_tsf.h b/ui/base/ime/win/input_method_win_tsf.h
index b04867d6..9fcf1701 100644
--- a/ui/base/ime/win/input_method_win_tsf.h
+++ b/ui/base/ime/win/input_method_win_tsf.h
@@ -33,6 +33,7 @@
   void OnCaretBoundsChanged(const TextInputClient* client) override;
   void CancelComposition(const TextInputClient* client) override;
   void DetachTextInputClient(TextInputClient* client) override;
+  bool IsInputLocaleCJK() const override;
   bool IsCandidatePopupOpen() const override;
 
   // Overridden from InputMethodBase:
diff --git a/ui/base/ime/win/tsf_bridge.cc b/ui/base/ime/win/tsf_bridge.cc
index 6025a79..e70f1b9 100644
--- a/ui/base/ime/win/tsf_bridge.cc
+++ b/ui/base/ime/win/tsf_bridge.cc
@@ -42,6 +42,7 @@
   void RemoveFocusedClient(TextInputClient* client) override;
   void SetInputMethodDelegate(internal::InputMethodDelegate* delegate) override;
   void RemoveInputMethodDelegate() override;
+  bool IsInputLanguageCJK() override;
   Microsoft::WRL::ComPtr<ITfThreadMgr> GetThreadManager() override;
   TextInputClient* GetFocusedTextInputClient() const override;
 
@@ -109,6 +110,10 @@
   // An ITfThreadMgr object to be used in focus and document management.
   Microsoft::WRL::ComPtr<ITfThreadMgr> thread_manager_;
 
+  // An ITfInputProcessorProfiles object to be used to get current language
+  // locale profile.
+  Microsoft::WRL::ComPtr<ITfInputProcessorProfiles> input_processor_profiles_;
+
   // A map from TextInputType to an editable document for TSF. We use multiple
   // TSF documents that have different InputScopes and TSF attributes based on
   // the TextInputType associated with the target document. For a TextInputType
@@ -172,6 +177,13 @@
     return false;
   }
 
+  if (FAILED(::CoCreateInstance(CLSID_TF_InputProcessorProfiles, nullptr,
+                                CLSCTX_ALL,
+                                IID_PPV_ARGS(&input_processor_profiles_)))) {
+    DVLOG(1) << "Failed to create InputProcessorProfiles instance.";
+    return false;
+  }
+
   if (FAILED(::CoCreateInstance(CLSID_TF_ThreadMgr, nullptr, CLSCTX_ALL,
                                 IID_PPV_ARGS(&thread_manager_)))) {
     DVLOG(1) << "Failed to create ThreadManager instance.";
@@ -332,6 +344,17 @@
   }
 }
 
+bool TSFBridgeImpl::IsInputLanguageCJK() {
+  LANGID lang_locale;
+  if (SUCCEEDED(input_processor_profiles_->GetCurrentLanguage(&lang_locale))) {
+    lang_locale = PRIMARYLANGID(lang_locale);
+    return lang_locale == LANG_CHINESE || lang_locale == LANG_JAPANESE ||
+           lang_locale == LANG_KOREAN;
+  } else {
+    return false;
+  }
+}
+
 TextInputClient* TSFBridgeImpl::GetFocusedTextInputClient() const {
   return client_;
 }
diff --git a/ui/base/ime/win/tsf_bridge.h b/ui/base/ime/win/tsf_bridge.h
index 2fbc7bf..0082f52 100644
--- a/ui/base/ime/win/tsf_bridge.h
+++ b/ui/base/ime/win/tsf_bridge.h
@@ -82,6 +82,9 @@
   // Remove InputMethodDelegate instance from TSFTextStore when not in focus.
   virtual void RemoveInputMethodDelegate() = 0;
 
+  // Returns whether the system's input language is CJK.
+  virtual bool IsInputLanguageCJK() = 0;
+
   // Obtains current thread manager.
   virtual Microsoft::WRL::ComPtr<ITfThreadMgr> GetThreadManager() = 0;