Index: ui/base/ime/win/tsf_input_scope.cc |
diff --git a/ui/base/ime/win/tsf_input_scope.cc b/ui/base/ime/win/tsf_input_scope.cc |
index dac701b0a8b85e41694515b1a90ec0affc81653f..0559491d17e19ff13127ed282bcc2638e498f8e6 100644 |
--- a/ui/base/ime/win/tsf_input_scope.cc |
+++ b/ui/base/ime/win/tsf_input_scope.cc |
@@ -87,16 +87,13 @@ class TSFInputScope : public ITfInputScope { |
DISALLOW_COPY_AND_ASSIGN(TSFInputScope); |
}; |
-typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, |
- InputScope input_scope); |
- |
-SetInputScopeFunc g_set_input_scope = NULL; |
-bool g_get_proc_done = false; |
- |
-SetInputScopeFunc GetSetInputScope() { |
+template <typename Proc> |
+Proc GetTSFProcedure(const char* procedure_name) { |
+ static Proc procedure = NULL; |
+ static bool get_proc_done = false; |
// Thread safety is not required. |
- if (!g_get_proc_done) { |
- g_get_proc_done = true; |
+ if (!get_proc_done) { |
+ get_proc_done = true; |
// For stability reasons, we do not support Windows XP. |
if (base::win::GetVersion() < base::win::VERSION_VISTA) |
@@ -107,12 +104,15 @@ SetInputScopeFunc GetSetInputScope() { |
&module)) { |
return NULL; |
} |
- g_set_input_scope = reinterpret_cast<SetInputScopeFunc>( |
- GetProcAddress(module, "SetInputScope")); |
+ |
+ procedure = reinterpret_cast<Proc>(GetProcAddress(module, procedure_name)); |
} |
- return g_set_input_scope; |
+ return procedure; |
} |
+typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, |
+ InputScope input_scope); |
+ |
InputScope GetInputScopeType(TextInputType text_input_type) { |
// Following mapping is based in IE10 on Windows 8. |
switch (text_input_type) { |
@@ -133,6 +133,40 @@ InputScope GetInputScopeType(TextInputType text_input_type) { |
} |
} |
+typedef HRESULT (WINAPI *SetInputScopesFunc)(HWND window_handle, |
+ const InputScope *pInputScopes, |
+ UINT cInputScopes, |
+ WCHAR **ppszPhraseList, |
+ UINT cPhrases, |
+ WCHAR *pszRegExp, |
+ WCHAR *pszSRGS); |
+ |
+InputScope GetInputScopeType(TextInputMode text_input_mode) { |
Yohei Yukawa
2013/07/31 06:44:15
We prefer to avoid function overloading.
yoichio
2013/07/31 06:49:34
Done.
|
+ switch (text_input_mode) { |
+ case TEXT_INPUT_MODE_VERBATIM: |
+ case TEXT_INPUT_MODE_LATIN: |
+ case TEXT_INPUT_MODE_LATIN_NAME: |
+ case TEXT_INPUT_MODE_LATIN_PROSE: |
+ return IS_ALPHANUMERIC_HALFWIDTH; |
+ case TEXT_INPUT_MODE_FULL_WIDTH_LATIN: |
+ return IS_ALPHANUMERIC_FULLWIDTH; |
+ case TEXT_INPUT_MODE_KANA: |
+ return IS_HIRAGANA; |
+ case TEXT_INPUT_MODE_KATAKANA: |
+ return IS_KATAKANA_FULLWIDTH; |
+ case TEXT_INPUT_MODE_NUMERIC: |
+ return IS_NUMBER; |
+ case TEXT_INPUT_MODE_TEL: |
+ return IS_TELEPHONE_FULLTELEPHONENUMBER; |
+ case TEXT_INPUT_MODE_EMAIL: |
+ return IS_EMAIL_SMTPEMAILADDRESS; |
+ case TEXT_INPUT_MODE_URL: |
+ return IS_URL; |
+ default: |
+ return IS_DEFAULT; |
+ } |
+} |
+ |
} // namespace |
ITfInputScope* CreateInputScope(TextInputType text_input_type) { |
@@ -141,10 +175,29 @@ ITfInputScope* CreateInputScope(TextInputType text_input_type) { |
void SetInputScopeForTsfUnawareWindow(HWND window_handle, |
TextInputType text_input_type) { |
- SetInputScopeFunc set_input_scope = GetSetInputScope(); |
+ SetInputScopeFunc set_input_scope = |
+ GetTSFProcedure<SetInputScopeFunc>("SetInputScope"); |
if (set_input_scope) |
set_input_scope(window_handle, GetInputScopeType(text_input_type)); |
} |
+void SetInputScopesForTsfUnawareWindow( |
+ HWND window_handle, |
+ TextInputType text_input_type, |
+ TextInputMode text_input_mode) { |
+ SetInputScopesFunc set_input_scopes = |
+ GetTSFProcedure<SetInputScopesFunc>("SetInputScopes"); |
+ if (set_input_scopes) { |
+ InputScope input_scopes[] = { |
+ GetInputScopeType(text_input_type), |
+ GetInputScopeType(text_input_mode), |
+ }; |
+ |
+ set_input_scopes(window_handle, input_scopes, |
+ (input_scopes[0] == input_scopes[1] ? 1 : 2), NULL, 0, |
+ NULL, NULL); |
+ } |
+} |
+ |
} // namespace tsf_inputscope |
} // namespace ui |