Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: ui/base/ime/win/tsf_input_scope.cc

Issue 21157006: change tsf_input_scopes::SetInputScopeForTsfUnawareWindow to SetInputScopesForTsfUnawareWindow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Thread safe Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/ime/win/tsf_input_scope.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/singleton.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
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 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.
94 bool g_get_proc_done = false; 100 public:
101 static TSFProceduresSingleton* GetInstance() {
102 return Singleton<TSFProceduresSingleton>::get();
103 }
95 104
96 SetInputScopeFunc GetSetInputScope() { 105 TSFProceduresSingleton()
97 // Thread safety is not required. 106 : set_input_scopes(GetTSFProcedure<SetInputScopesFunc>("SetInputScopes"))
98 if (!g_get_proc_done) { 107 {}
99 g_get_proc_done = true;
100 108
109 const SetInputScopesFunc set_input_scopes;
110
111 private:
112
Seigo Nonaka 2013/08/01 17:07:59 nit: no need this blank line.
yoichio 2013/08/05 08:19:50 Done.
113 template <typename Proc>
114 Proc GetTSFProcedure(const char* procedure_name) {
101 // For stability reasons, we do not support Windows XP. 115 // For stability reasons, we do not support Windows XP.
102 if (base::win::GetVersion() < base::win::VERSION_VISTA) 116 if (base::win::GetVersion() < base::win::VERSION_VISTA)
103 return NULL; 117 return NULL;
104 118
105 HMODULE module = NULL; 119 HMODULE module = NULL;
106 if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll", 120 if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll",
107 &module)) { 121 &module)) {
108 return NULL; 122 return NULL;
109 } 123 }
110 g_set_input_scope = reinterpret_cast<SetInputScopeFunc>( 124
111 GetProcAddress(module, "SetInputScope")); 125 return reinterpret_cast<Proc>(GetProcAddress(module, procedure_name));
112 } 126 }
113 return g_set_input_scope;
114 }
115 127
116 InputScope GetInputScopeType(TextInputType text_input_type) { 128 friend struct DefaultSingletonTraits<TSFProceduresSingleton>;
129 DISALLOW_COPY_AND_ASSIGN(TSFProceduresSingleton);
130 };
131
132 InputScope ConvertTextInputTypeToInputScope(TextInputType text_input_type) {
117 // Following mapping is based in IE10 on Windows 8. 133 // Following mapping is based in IE10 on Windows 8.
118 switch (text_input_type) { 134 switch (text_input_type) {
119 case TEXT_INPUT_TYPE_PASSWORD: 135 case TEXT_INPUT_TYPE_PASSWORD:
120 return IS_PASSWORD; 136 return IS_PASSWORD;
121 case TEXT_INPUT_TYPE_SEARCH: 137 case TEXT_INPUT_TYPE_SEARCH:
122 return IS_SEARCH; 138 return IS_SEARCH;
123 case TEXT_INPUT_TYPE_EMAIL: 139 case TEXT_INPUT_TYPE_EMAIL:
124 return IS_EMAIL_SMTPEMAILADDRESS; 140 return IS_EMAIL_SMTPEMAILADDRESS;
125 case TEXT_INPUT_TYPE_NUMBER: 141 case TEXT_INPUT_TYPE_NUMBER:
126 return IS_NUMBER; 142 return IS_NUMBER;
127 case TEXT_INPUT_TYPE_TELEPHONE: 143 case TEXT_INPUT_TYPE_TELEPHONE:
128 return IS_TELEPHONE_FULLTELEPHONENUMBER; 144 return IS_TELEPHONE_FULLTELEPHONENUMBER;
129 case TEXT_INPUT_TYPE_URL: 145 case TEXT_INPUT_TYPE_URL:
130 return IS_URL; 146 return IS_URL;
131 default: 147 default:
132 return IS_DEFAULT; 148 return IS_DEFAULT;
133 } 149 }
134 } 150 }
135 151
152 InputScope ConvertTextInputModeToInputScope(TextInputMode text_input_mode) {
153 switch (text_input_mode) {
154 case TEXT_INPUT_MODE_VERBATIM:
155 case TEXT_INPUT_MODE_LATIN:
156 case TEXT_INPUT_MODE_LATIN_NAME:
157 case TEXT_INPUT_MODE_LATIN_PROSE:
158 return IS_ALPHANUMERIC_HALFWIDTH;
159 case TEXT_INPUT_MODE_FULL_WIDTH_LATIN:
160 return IS_ALPHANUMERIC_FULLWIDTH;
161 case TEXT_INPUT_MODE_KANA:
162 return IS_HIRAGANA;
163 case TEXT_INPUT_MODE_KATAKANA:
164 return IS_KATAKANA_FULLWIDTH;
165 case TEXT_INPUT_MODE_NUMERIC:
166 return IS_NUMBER;
167 case TEXT_INPUT_MODE_TEL:
168 return IS_TELEPHONE_FULLTELEPHONENUMBER;
169 case TEXT_INPUT_MODE_EMAIL:
170 return IS_EMAIL_SMTPEMAILADDRESS;
171 case TEXT_INPUT_MODE_URL:
172 return IS_URL;
173 default:
174 return IS_DEFAULT;
175 }
176 }
177
136 } // namespace 178 } // namespace
137 179
138 ITfInputScope* CreateInputScope(TextInputType text_input_type) { 180 ITfInputScope* CreateInputScope(TextInputType text_input_type) {
139 return new TSFInputScope(GetInputScopeType(text_input_type)); 181 return new TSFInputScope(ConvertTextInputTypeToInputScope(text_input_type));
140 } 182 }
141 183
142 void SetInputScopeForTsfUnawareWindow(HWND window_handle, 184 void SetInputScopeForTsfUnawareWindow(
143 TextInputType text_input_type) { 185 HWND window_handle,
144 SetInputScopeFunc set_input_scope = GetSetInputScope(); 186 TextInputType text_input_type,
145 if (set_input_scope) 187 TextInputMode text_input_mode) {
146 set_input_scope(window_handle, GetInputScopeType(text_input_type)); 188 SetInputScopesFunc set_input_scopes =
189 TSFProceduresSingleton::GetInstance()->set_input_scopes;
190 if (!set_input_scopes)
191 return;
192
193 InputScope input_scopes[] = {
194 ConvertTextInputTypeToInputScope(text_input_type),
195 ConvertTextInputModeToInputScope(text_input_mode),
196 };
197
198 set_input_scopes(window_handle, input_scopes,
199 (input_scopes[0] == input_scopes[1] ? 1 : 2), NULL, 0, NULL,
200 NULL);
201
147 } 202 }
148 203
149 } // namespace tsf_inputscope 204 } // namespace tsf_inputscope
150 } // namespace ui 205 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/win/tsf_input_scope.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698