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..f2a8067d3e8cc92a657cee906cee6efaa55cc022 100644 |
--- a/ui/base/ime/win/tsf_input_scope.cc |
+++ b/ui/base/ime/win/tsf_input_scope.cc |
@@ -8,6 +8,7 @@ |
#include "base/compiler_specific.h" |
#include "base/logging.h" |
+#include "base/memory/singleton.h" |
#include "base/win/windows_version.h" |
namespace ui { |
@@ -87,17 +88,30 @@ class TSFInputScope : public ITfInputScope { |
DISALLOW_COPY_AND_ASSIGN(TSFInputScope); |
}; |
-typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, |
- InputScope input_scope); |
+typedef HRESULT (WINAPI *SetInputScopesFunc)(HWND window_handle, |
+ const InputScope* input_scope_list, |
+ UINT num_input_scopes, |
+ WCHAR**, /* unused */ |
+ UINT, /* unused */ |
+ WCHAR*, /* unused */ |
+ WCHAR* /* unused */); |
-SetInputScopeFunc g_set_input_scope = NULL; |
-bool g_get_proc_done = false; |
+class TSFProceduresSingleton { |
Seigo Nonaka
2013/08/01 17:07:59
I think thread check is enough but if you want to
yoichio
2013/08/05 08:19:50
Add only thread checking.
|
+ public: |
+ static TSFProceduresSingleton* GetInstance() { |
+ return Singleton<TSFProceduresSingleton>::get(); |
+ } |
+ |
+ TSFProceduresSingleton() |
+ : set_input_scopes(GetTSFProcedure<SetInputScopesFunc>("SetInputScopes")) |
+ {} |
-SetInputScopeFunc GetSetInputScope() { |
- // Thread safety is not required. |
- if (!g_get_proc_done) { |
- g_get_proc_done = true; |
+ const SetInputScopesFunc set_input_scopes; |
+private: |
+ |
Seigo Nonaka
2013/08/01 17:07:59
nit: no need this blank line.
yoichio
2013/08/05 08:19:50
Done.
|
+ template <typename Proc> |
+ Proc GetTSFProcedure(const char* procedure_name) { |
// For stability reasons, we do not support Windows XP. |
if (base::win::GetVersion() < base::win::VERSION_VISTA) |
return NULL; |
@@ -107,13 +121,15 @@ SetInputScopeFunc GetSetInputScope() { |
&module)) { |
return NULL; |
} |
- g_set_input_scope = reinterpret_cast<SetInputScopeFunc>( |
- GetProcAddress(module, "SetInputScope")); |
+ |
+ return reinterpret_cast<Proc>(GetProcAddress(module, procedure_name)); |
} |
- return g_set_input_scope; |
-} |
-InputScope GetInputScopeType(TextInputType text_input_type) { |
+ friend struct DefaultSingletonTraits<TSFProceduresSingleton>; |
+ DISALLOW_COPY_AND_ASSIGN(TSFProceduresSingleton); |
+}; |
+ |
+InputScope ConvertTextInputTypeToInputScope(TextInputType text_input_type) { |
// Following mapping is based in IE10 on Windows 8. |
switch (text_input_type) { |
case TEXT_INPUT_TYPE_PASSWORD: |
@@ -133,17 +149,56 @@ InputScope GetInputScopeType(TextInputType text_input_type) { |
} |
} |
+InputScope ConvertTextInputModeToInputScope(TextInputMode text_input_mode) { |
+ 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) { |
- return new TSFInputScope(GetInputScopeType(text_input_type)); |
+ return new TSFInputScope(ConvertTextInputTypeToInputScope(text_input_type)); |
} |
-void SetInputScopeForTsfUnawareWindow(HWND window_handle, |
- TextInputType text_input_type) { |
- SetInputScopeFunc set_input_scope = GetSetInputScope(); |
- if (set_input_scope) |
- set_input_scope(window_handle, GetInputScopeType(text_input_type)); |
+void SetInputScopeForTsfUnawareWindow( |
+ HWND window_handle, |
+ TextInputType text_input_type, |
+ TextInputMode text_input_mode) { |
+ SetInputScopesFunc set_input_scopes = |
+ TSFProceduresSingleton::GetInstance()->set_input_scopes; |
+ if (!set_input_scopes) |
+ return; |
+ |
+ InputScope input_scopes[] = { |
+ ConvertTextInputTypeToInputScope(text_input_type), |
+ ConvertTextInputModeToInputScope(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 |