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