OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/ime/win/tsf_input_scope.h" | 5 #include "ui/base/ime/win/tsf_input_scope.h" |
6 | 6 |
7 #include <InputScope.h> | 7 #include <InputScope.h> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 private: | 80 private: |
81 // The corresponding text input type. | 81 // The corresponding text input type. |
82 InputScope input_scope_; | 82 InputScope input_scope_; |
83 | 83 |
84 // The refrence count of this instance. | 84 // The refrence count of this instance. |
85 volatile LONG ref_count_; | 85 volatile LONG ref_count_; |
86 | 86 |
87 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); | 87 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); |
88 }; | 88 }; |
89 | 89 |
90 typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, | 90 template <typename Proc> |
91 InputScope input_scope); | 91 Proc GetTSFProcedure(const char* procedure_name) { |
92 | 92 static Proc procedure = NULL; |
93 SetInputScopeFunc g_set_input_scope = NULL; | 93 static bool get_proc_done = false; |
94 bool g_get_proc_done = false; | |
95 | |
96 SetInputScopeFunc GetSetInputScope() { | |
97 // Thread safety is not required. | 94 // Thread safety is not required. |
Seigo Nonaka
2013/07/31 13:23:09
Sorry this is not introduced by this CL but please
yoichio
2013/08/01 10:29:22
Done.
Seigo Nonaka
2013/08/01 17:07:59
Sorry for confusing you.
I'd not like to say makin
| |
98 if (!g_get_proc_done) { | 95 if (!get_proc_done) { |
99 g_get_proc_done = true; | 96 get_proc_done = true; |
100 | 97 |
101 // For stability reasons, we do not support Windows XP. | 98 // For stability reasons, we do not support Windows XP. |
102 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 99 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
103 return NULL; | 100 return NULL; |
104 | 101 |
105 HMODULE module = NULL; | 102 HMODULE module = NULL; |
106 if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll", | 103 if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll", |
107 &module)) { | 104 &module)) { |
108 return NULL; | 105 return NULL; |
109 } | 106 } |
110 g_set_input_scope = reinterpret_cast<SetInputScopeFunc>( | 107 |
111 GetProcAddress(module, "SetInputScope")); | 108 procedure = reinterpret_cast<Proc>(GetProcAddress(module, procedure_name)); |
112 } | 109 } |
113 return g_set_input_scope; | 110 return procedure; |
114 } | 111 } |
115 | 112 |
116 InputScope GetInputScopeType(TextInputType text_input_type) { | 113 typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, |
Seigo Nonaka
2013/07/31 13:23:09
Can we use SetInputScopesFunc for both case?
yoichio
2013/08/01 10:29:22
I think yes and manually tested.
| |
114 InputScope input_scope); | |
115 | |
116 InputScope ConvertTextInputTypeToInputScope(TextInputType text_input_type) { | |
117 // Following mapping is based in IE10 on Windows 8. | 117 // Following mapping is based in IE10 on Windows 8. |
118 switch (text_input_type) { | 118 switch (text_input_type) { |
119 case TEXT_INPUT_TYPE_PASSWORD: | 119 case TEXT_INPUT_TYPE_PASSWORD: |
120 return IS_PASSWORD; | 120 return IS_PASSWORD; |
121 case TEXT_INPUT_TYPE_SEARCH: | 121 case TEXT_INPUT_TYPE_SEARCH: |
122 return IS_SEARCH; | 122 return IS_SEARCH; |
123 case TEXT_INPUT_TYPE_EMAIL: | 123 case TEXT_INPUT_TYPE_EMAIL: |
124 return IS_EMAIL_SMTPEMAILADDRESS; | 124 return IS_EMAIL_SMTPEMAILADDRESS; |
125 case TEXT_INPUT_TYPE_NUMBER: | 125 case TEXT_INPUT_TYPE_NUMBER: |
126 return IS_NUMBER; | 126 return IS_NUMBER; |
127 case TEXT_INPUT_TYPE_TELEPHONE: | 127 case TEXT_INPUT_TYPE_TELEPHONE: |
128 return IS_TELEPHONE_FULLTELEPHONENUMBER; | 128 return IS_TELEPHONE_FULLTELEPHONENUMBER; |
129 case TEXT_INPUT_TYPE_URL: | 129 case TEXT_INPUT_TYPE_URL: |
130 return IS_URL; | 130 return IS_URL; |
131 default: | 131 default: |
132 return IS_DEFAULT; | 132 return IS_DEFAULT; |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 typedef HRESULT (WINAPI *SetInputScopesFunc)(HWND window_handle, | |
137 const InputScope* input_scope_list, | |
138 UINT num_input_scopes, | |
139 WCHAR** phrase_list, | |
140 UINT num_phrases, | |
141 WCHAR* regular_expression, | |
142 WCHAR* speech_recognition_hints); | |
143 | |
144 InputScope ConvertTextInputModeToInputScope(TextInputMode text_input_mode) { | |
145 switch (text_input_mode) { | |
146 case TEXT_INPUT_MODE_VERBATIM: | |
147 case TEXT_INPUT_MODE_LATIN: | |
148 case TEXT_INPUT_MODE_LATIN_NAME: | |
149 case TEXT_INPUT_MODE_LATIN_PROSE: | |
150 return IS_ALPHANUMERIC_HALFWIDTH; | |
151 case TEXT_INPUT_MODE_FULL_WIDTH_LATIN: | |
152 return IS_ALPHANUMERIC_FULLWIDTH; | |
153 case TEXT_INPUT_MODE_KANA: | |
154 return IS_HIRAGANA; | |
155 case TEXT_INPUT_MODE_KATAKANA: | |
156 return IS_KATAKANA_FULLWIDTH; | |
157 case TEXT_INPUT_MODE_NUMERIC: | |
158 return IS_NUMBER; | |
159 case TEXT_INPUT_MODE_TEL: | |
160 return IS_TELEPHONE_FULLTELEPHONENUMBER; | |
161 case TEXT_INPUT_MODE_EMAIL: | |
162 return IS_EMAIL_SMTPEMAILADDRESS; | |
163 case TEXT_INPUT_MODE_URL: | |
164 return IS_URL; | |
165 default: | |
166 return IS_DEFAULT; | |
167 } | |
168 } | |
169 | |
136 } // namespace | 170 } // namespace |
137 | 171 |
138 ITfInputScope* CreateInputScope(TextInputType text_input_type) { | 172 ITfInputScope* CreateInputScope(TextInputType text_input_type) { |
139 return new TSFInputScope(GetInputScopeType(text_input_type)); | 173 return new TSFInputScope(ConvertTextInputTypeToInputScope(text_input_type)); |
140 } | 174 } |
141 | 175 |
142 void SetInputScopeForTsfUnawareWindow(HWND window_handle, | 176 void SetInputScopeForTsfUnawareWindow(HWND window_handle, |
143 TextInputType text_input_type) { | 177 TextInputType text_input_type) { |
144 SetInputScopeFunc set_input_scope = GetSetInputScope(); | 178 SetInputScopeFunc set_input_scope = |
179 GetTSFProcedure<SetInputScopeFunc>("SetInputScope"); | |
145 if (set_input_scope) | 180 if (set_input_scope) |
146 set_input_scope(window_handle, GetInputScopeType(text_input_type)); | 181 set_input_scope(window_handle, |
182 ConvertTextInputTypeToInputScope(text_input_type)); | |
183 } | |
184 | |
185 void SetInputScopesForTsfUnawareWindow( | |
186 HWND window_handle, | |
187 TextInputType text_input_type, | |
188 TextInputMode text_input_mode) { | |
189 SetInputScopesFunc set_input_scopes = | |
190 GetTSFProcedure<SetInputScopesFunc>("SetInputScopes"); | |
191 if (set_input_scopes) { | |
Seigo Nonaka
2013/07/31 13:23:09
nit: I prefer early exit, but up to you.
yoichio
2013/08/01 10:29:22
Done.
| |
192 InputScope input_scopes[] = { | |
193 ConvertTextInputTypeToInputScope(text_input_type), | |
194 ConvertTextInputModeToInputScope(text_input_mode), | |
195 }; | |
196 | |
197 set_input_scopes(window_handle, input_scopes, | |
198 (input_scopes[0] == input_scopes[1] ? 1 : 2), NULL, 0, | |
199 NULL, NULL); | |
200 } | |
147 } | 201 } |
148 | 202 |
149 } // namespace tsf_inputscope | 203 } // namespace tsf_inputscope |
150 } // namespace ui | 204 } // namespace ui |
OLD | NEW |