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" |
11 #include "base/message_loop/message_loop.h" | |
11 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
12 | 13 |
13 namespace ui { | 14 namespace ui { |
14 namespace tsf_inputscope { | 15 namespace tsf_inputscope { |
15 namespace { | 16 namespace { |
16 | 17 |
17 class TSFInputScope : public ITfInputScope { | 18 class TSFInputScope : public ITfInputScope { |
18 public: | 19 public: |
19 explicit TSFInputScope(InputScope input_scope) | 20 explicit TSFInputScope(InputScope input_scope) |
20 : input_scope_(input_scope), | 21 : input_scope_(input_scope), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 private: | 81 private: |
81 // The corresponding text input type. | 82 // The corresponding text input type. |
82 InputScope input_scope_; | 83 InputScope input_scope_; |
83 | 84 |
84 // The refrence count of this instance. | 85 // The refrence count of this instance. |
85 volatile LONG ref_count_; | 86 volatile LONG ref_count_; |
86 | 87 |
87 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); | 88 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); |
88 }; | 89 }; |
89 | 90 |
90 typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, | 91 typedef HRESULT (WINAPI *SetInputScopesFunc)(HWND window_handle, |
91 InputScope input_scope); | 92 const InputScope* input_scope_list, |
93 UINT num_input_scopes, | |
94 WCHAR**, /* unused */ | |
95 UINT, /* unused */ | |
96 WCHAR*, /* unused */ | |
97 WCHAR* /* unused */); | |
92 | 98 |
93 SetInputScopeFunc g_set_input_scope = NULL; | 99 SetInputScopesFunc g_set_input_scopes = NULL; |
94 bool g_get_proc_done = false; | 100 bool g_get_proc_done = false; |
95 | 101 |
96 SetInputScopeFunc GetSetInputScope() { | 102 SetInputScopesFunc GetSetInputScopes() { |
97 // Thread safety is not required. | 103 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type()); |
104 // Thread safety is not required because this function is under ui thread. | |
Yohei Yukawa
2013/08/05 08:25:50
s/ui/UI/
yoichio
2013/08/05 08:30:41
Done.
| |
98 if (!g_get_proc_done) { | 105 if (!g_get_proc_done) { |
99 g_get_proc_done = true; | 106 g_get_proc_done = true; |
100 | 107 |
101 // For stability reasons, we do not support Windows XP. | 108 // For stability reasons, we do not support Windows XP. |
102 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 109 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
103 return NULL; | 110 return NULL; |
104 | 111 |
105 HMODULE module = NULL; | 112 HMODULE module = NULL; |
106 if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll", | 113 if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll", |
107 &module)) { | 114 &module)) { |
108 return NULL; | 115 return NULL; |
109 } | 116 } |
110 g_set_input_scope = reinterpret_cast<SetInputScopeFunc>( | 117 g_set_input_scopes = reinterpret_cast<SetInputScopesFunc>( |
111 GetProcAddress(module, "SetInputScope")); | 118 GetProcAddress(module, "SetInputScopes")); |
112 } | 119 } |
113 return g_set_input_scope; | 120 return g_set_input_scopes; |
114 } | 121 } |
115 | 122 |
116 InputScope GetInputScopeType(TextInputType text_input_type) { | 123 InputScope ConvertTextInputTypeToInputScope(TextInputType text_input_type) { |
117 // Following mapping is based in IE10 on Windows 8. | 124 // Following mapping is based in IE10 on Windows 8. |
118 switch (text_input_type) { | 125 switch (text_input_type) { |
119 case TEXT_INPUT_TYPE_PASSWORD: | 126 case TEXT_INPUT_TYPE_PASSWORD: |
120 return IS_PASSWORD; | 127 return IS_PASSWORD; |
121 case TEXT_INPUT_TYPE_SEARCH: | 128 case TEXT_INPUT_TYPE_SEARCH: |
122 return IS_SEARCH; | 129 return IS_SEARCH; |
123 case TEXT_INPUT_TYPE_EMAIL: | 130 case TEXT_INPUT_TYPE_EMAIL: |
124 return IS_EMAIL_SMTPEMAILADDRESS; | 131 return IS_EMAIL_SMTPEMAILADDRESS; |
125 case TEXT_INPUT_TYPE_NUMBER: | 132 case TEXT_INPUT_TYPE_NUMBER: |
126 return IS_NUMBER; | 133 return IS_NUMBER; |
127 case TEXT_INPUT_TYPE_TELEPHONE: | 134 case TEXT_INPUT_TYPE_TELEPHONE: |
128 return IS_TELEPHONE_FULLTELEPHONENUMBER; | 135 return IS_TELEPHONE_FULLTELEPHONENUMBER; |
129 case TEXT_INPUT_TYPE_URL: | 136 case TEXT_INPUT_TYPE_URL: |
130 return IS_URL; | 137 return IS_URL; |
131 default: | 138 default: |
132 return IS_DEFAULT; | 139 return IS_DEFAULT; |
133 } | 140 } |
134 } | 141 } |
135 | 142 |
143 InputScope ConvertTextInputModeToInputScope(TextInputMode text_input_mode) { | |
144 switch (text_input_mode) { | |
145 case TEXT_INPUT_MODE_VERBATIM: | |
146 case TEXT_INPUT_MODE_LATIN: | |
147 case TEXT_INPUT_MODE_LATIN_NAME: | |
148 case TEXT_INPUT_MODE_LATIN_PROSE: | |
149 return IS_ALPHANUMERIC_HALFWIDTH; | |
150 case TEXT_INPUT_MODE_FULL_WIDTH_LATIN: | |
151 return IS_ALPHANUMERIC_FULLWIDTH; | |
152 case TEXT_INPUT_MODE_KANA: | |
153 return IS_HIRAGANA; | |
154 case TEXT_INPUT_MODE_KATAKANA: | |
155 return IS_KATAKANA_FULLWIDTH; | |
156 case TEXT_INPUT_MODE_NUMERIC: | |
157 return IS_NUMBER; | |
158 case TEXT_INPUT_MODE_TEL: | |
159 return IS_TELEPHONE_FULLTELEPHONENUMBER; | |
160 case TEXT_INPUT_MODE_EMAIL: | |
161 return IS_EMAIL_SMTPEMAILADDRESS; | |
162 case TEXT_INPUT_MODE_URL: | |
163 return IS_URL; | |
164 default: | |
165 return IS_DEFAULT; | |
166 } | |
167 } | |
168 | |
136 } // namespace | 169 } // namespace |
137 | 170 |
138 ITfInputScope* CreateInputScope(TextInputType text_input_type) { | 171 ITfInputScope* CreateInputScope(TextInputType text_input_type) { |
139 return new TSFInputScope(GetInputScopeType(text_input_type)); | 172 return new TSFInputScope(ConvertTextInputTypeToInputScope(text_input_type)); |
140 } | 173 } |
141 | 174 |
142 void SetInputScopeForTsfUnawareWindow(HWND window_handle, | 175 void SetInputScopeForTsfUnawareWindow( |
143 TextInputType text_input_type) { | 176 HWND window_handle, |
144 SetInputScopeFunc set_input_scope = GetSetInputScope(); | 177 TextInputType text_input_type, |
145 if (set_input_scope) | 178 TextInputMode text_input_mode) { |
146 set_input_scope(window_handle, GetInputScopeType(text_input_type)); | 179 SetInputScopesFunc set_input_scopes = GetSetInputScopes(); |
180 if (!set_input_scopes) | |
181 return; | |
182 | |
183 InputScope input_scopes[] = { | |
184 ConvertTextInputTypeToInputScope(text_input_type), | |
185 ConvertTextInputModeToInputScope(text_input_mode), | |
186 }; | |
187 | |
188 set_input_scopes(window_handle, input_scopes, | |
189 (input_scopes[0] == input_scopes[1] ? 1 : 2), NULL, 0, NULL, | |
190 NULL); | |
147 } | 191 } |
148 | 192 |
149 } // namespace tsf_inputscope | 193 } // namespace tsf_inputscope |
150 } // namespace ui | 194 } // namespace ui |
OLD | NEW |