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 | 9 |
9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 11 #include "base/logging.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_list, size_t num_scopes) |
yukawa_g
2013/07/31 09:44:52
How about receiving std::vector<InputScope>?
| |
20 : input_scope_(input_scope), | 21 : input_scope_list_(num_scopes), |
21 ref_count_(0) {} | 22 ref_count_(0) { |
23 for (size_t i = 0; i < num_scopes; i++) | |
24 input_scope_list_.push_back(input_scope_list[i]); | |
25 } | |
22 | 26 |
23 // ITfInputScope: | 27 // ITfInputScope: |
24 STDMETHOD_(ULONG, AddRef)() OVERRIDE { | 28 STDMETHOD_(ULONG, AddRef)() OVERRIDE { |
25 return InterlockedIncrement(&ref_count_); | 29 return InterlockedIncrement(&ref_count_); |
26 } | 30 } |
27 | 31 |
28 STDMETHOD_(ULONG, Release)() OVERRIDE { | 32 STDMETHOD_(ULONG, Release)() OVERRIDE { |
29 const LONG count = InterlockedDecrement(&ref_count_); | 33 const LONG count = InterlockedDecrement(&ref_count_); |
30 if (!count) { | 34 if (!count) { |
31 delete this; | 35 delete this; |
(...skipping 12 matching lines...) Expand all Loading... | |
44 return E_NOINTERFACE; | 48 return E_NOINTERFACE; |
45 } | 49 } |
46 AddRef(); | 50 AddRef(); |
47 return S_OK; | 51 return S_OK; |
48 } | 52 } |
49 | 53 |
50 STDMETHOD(GetInputScopes)(InputScope** input_scopes, UINT* count) OVERRIDE { | 54 STDMETHOD(GetInputScopes)(InputScope** input_scopes, UINT* count) OVERRIDE { |
51 if (!count || !input_scopes) | 55 if (!count || !input_scopes) |
52 return E_INVALIDARG; | 56 return E_INVALIDARG; |
53 *input_scopes = static_cast<InputScope*>(CoTaskMemAlloc( | 57 *input_scopes = static_cast<InputScope*>(CoTaskMemAlloc( |
54 sizeof(InputScope))); | 58 sizeof(InputScope) * input_scope_list_.size())); |
55 if (!input_scopes) { | 59 if (!input_scopes) { |
56 *count = 0; | 60 *count = 0; |
57 return E_OUTOFMEMORY; | 61 return E_OUTOFMEMORY; |
58 } | 62 } |
59 (*input_scopes)[0] = input_scope_; | 63 |
60 *count = 1; | 64 for (size_t i = 0; i < input_scope_list_.size(); ++i) |
65 (*input_scopes)[i] = input_scope_list_[i]; | |
66 *count = input_scope_list_.size(); | |
61 return S_OK; | 67 return S_OK; |
62 } | 68 } |
63 | 69 |
64 STDMETHOD(GetPhrase)(BSTR** phrases, UINT* count) OVERRIDE { | 70 STDMETHOD(GetPhrase)(BSTR** phrases, UINT* count) OVERRIDE { |
65 return E_NOTIMPL; | 71 return E_NOTIMPL; |
66 } | 72 } |
67 | 73 |
68 STDMETHOD(GetRegularExpression)(BSTR* regexp) OVERRIDE { | 74 STDMETHOD(GetRegularExpression)(BSTR* regexp) OVERRIDE { |
69 return E_NOTIMPL; | 75 return E_NOTIMPL; |
70 } | 76 } |
71 | 77 |
72 STDMETHOD(GetSRGS)(BSTR* srgs) OVERRIDE { | 78 STDMETHOD(GetSRGS)(BSTR* srgs) OVERRIDE { |
73 return E_NOTIMPL; | 79 return E_NOTIMPL; |
74 } | 80 } |
75 | 81 |
76 STDMETHOD(GetXML)(BSTR* xml) OVERRIDE { | 82 STDMETHOD(GetXML)(BSTR* xml) OVERRIDE { |
77 return E_NOTIMPL; | 83 return E_NOTIMPL; |
78 } | 84 } |
79 | 85 |
80 private: | 86 private: |
81 // The corresponding text input type. | 87 // The corresponding text input types. |
82 InputScope input_scope_; | 88 std::vector<InputScope> input_scope_list_; |
83 | 89 |
84 // The refrence count of this instance. | 90 // The refrence count of this instance. |
85 volatile LONG ref_count_; | 91 volatile LONG ref_count_; |
86 | 92 |
87 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); | 93 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); |
88 }; | 94 }; |
89 | 95 |
90 template <typename Proc> | 96 template <typename Proc> |
91 Proc GetTSFProcedure(const char* procedure_name) { | 97 Proc GetTSFProcedure(const char* procedure_name) { |
92 static Proc procedure = NULL; | 98 static Proc procedure = NULL; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 case TEXT_INPUT_MODE_URL: | 169 case TEXT_INPUT_MODE_URL: |
164 return IS_URL; | 170 return IS_URL; |
165 default: | 171 default: |
166 return IS_DEFAULT; | 172 return IS_DEFAULT; |
167 } | 173 } |
168 } | 174 } |
169 | 175 |
170 } // namespace | 176 } // namespace |
171 | 177 |
172 ITfInputScope* CreateInputScope(TextInputType text_input_type) { | 178 ITfInputScope* CreateInputScope(TextInputType text_input_type) { |
173 return new TSFInputScope(ConvertTextInputTypeToInputScope(text_input_type)); | 179 InputScope input_scopes[] = { |
180 ConvertTextInputTypeToInputScope(text_input_type), | |
yukawa_g
2013/07/31 09:44:52
nit: indent.
| |
181 }; | |
182 return new TSFInputScope(input_scopes, 1); | |
174 } | 183 } |
175 | 184 |
176 void SetInputScopeForTsfUnawareWindow(HWND window_handle, | 185 void SetInputScopeForTsfUnawareWindow(HWND window_handle, |
177 TextInputType text_input_type) { | 186 TextInputType text_input_type) { |
178 SetInputScopeFunc set_input_scope = | 187 SetInputScopeFunc set_input_scope = |
179 GetTSFProcedure<SetInputScopeFunc>("SetInputScope"); | 188 GetTSFProcedure<SetInputScopeFunc>("SetInputScope"); |
180 if (set_input_scope) | 189 if (set_input_scope) |
181 set_input_scope(window_handle, | 190 set_input_scope(window_handle, |
182 ConvertTextInputTypeToInputScope(text_input_type)); | 191 ConvertTextInputTypeToInputScope(text_input_type)); |
183 } | 192 } |
(...skipping 11 matching lines...) Expand all Loading... | |
195 }; | 204 }; |
196 | 205 |
197 set_input_scopes(window_handle, input_scopes, | 206 set_input_scopes(window_handle, input_scopes, |
198 (input_scopes[0] == input_scopes[1] ? 1 : 2), NULL, 0, | 207 (input_scopes[0] == input_scopes[1] ? 1 : 2), NULL, 0, |
199 NULL, NULL); | 208 NULL, NULL); |
200 } | 209 } |
201 } | 210 } |
202 | 211 |
203 } // namespace tsf_inputscope | 212 } // namespace tsf_inputscope |
204 } // namespace ui | 213 } // namespace ui |
OLD | NEW |