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(const std::vector<InputScope>& input_scopes) |
20 : input_scope_(input_scope), | 21 : input_scopes_(input_scopes), |
21 ref_count_(0) {} | 22 ref_count_(0) {} |
22 | 23 |
23 // ITfInputScope: | 24 // ITfInputScope: |
24 STDMETHOD_(ULONG, AddRef)() OVERRIDE { | 25 STDMETHOD_(ULONG, AddRef)() OVERRIDE { |
25 return InterlockedIncrement(&ref_count_); | 26 return InterlockedIncrement(&ref_count_); |
26 } | 27 } |
27 | 28 |
28 STDMETHOD_(ULONG, Release)() OVERRIDE { | 29 STDMETHOD_(ULONG, Release)() OVERRIDE { |
29 const LONG count = InterlockedDecrement(&ref_count_); | 30 const LONG count = InterlockedDecrement(&ref_count_); |
30 if (!count) { | 31 if (!count) { |
(...skipping 13 matching lines...) Expand all Loading... |
44 return E_NOINTERFACE; | 45 return E_NOINTERFACE; |
45 } | 46 } |
46 AddRef(); | 47 AddRef(); |
47 return S_OK; | 48 return S_OK; |
48 } | 49 } |
49 | 50 |
50 STDMETHOD(GetInputScopes)(InputScope** input_scopes, UINT* count) OVERRIDE { | 51 STDMETHOD(GetInputScopes)(InputScope** input_scopes, UINT* count) OVERRIDE { |
51 if (!count || !input_scopes) | 52 if (!count || !input_scopes) |
52 return E_INVALIDARG; | 53 return E_INVALIDARG; |
53 *input_scopes = static_cast<InputScope*>(CoTaskMemAlloc( | 54 *input_scopes = static_cast<InputScope*>(CoTaskMemAlloc( |
54 sizeof(InputScope))); | 55 sizeof(InputScope) * input_scopes_.size())); |
55 if (!input_scopes) { | 56 if (!input_scopes) { |
56 *count = 0; | 57 *count = 0; |
57 return E_OUTOFMEMORY; | 58 return E_OUTOFMEMORY; |
58 } | 59 } |
59 (*input_scopes)[0] = input_scope_; | 60 |
60 *count = 1; | 61 for (size_t i = 0; i < input_scopes_.size(); ++i) |
| 62 (*input_scopes)[i] = input_scopes_[i]; |
| 63 *count = input_scopes_.size(); |
61 return S_OK; | 64 return S_OK; |
62 } | 65 } |
63 | 66 |
64 STDMETHOD(GetPhrase)(BSTR** phrases, UINT* count) OVERRIDE { | 67 STDMETHOD(GetPhrase)(BSTR** phrases, UINT* count) OVERRIDE { |
65 return E_NOTIMPL; | 68 return E_NOTIMPL; |
66 } | 69 } |
67 | 70 |
68 STDMETHOD(GetRegularExpression)(BSTR* regexp) OVERRIDE { | 71 STDMETHOD(GetRegularExpression)(BSTR* regexp) OVERRIDE { |
69 return E_NOTIMPL; | 72 return E_NOTIMPL; |
70 } | 73 } |
71 | 74 |
72 STDMETHOD(GetSRGS)(BSTR* srgs) OVERRIDE { | 75 STDMETHOD(GetSRGS)(BSTR* srgs) OVERRIDE { |
73 return E_NOTIMPL; | 76 return E_NOTIMPL; |
74 } | 77 } |
75 | 78 |
76 STDMETHOD(GetXML)(BSTR* xml) OVERRIDE { | 79 STDMETHOD(GetXML)(BSTR* xml) OVERRIDE { |
77 return E_NOTIMPL; | 80 return E_NOTIMPL; |
78 } | 81 } |
79 | 82 |
80 private: | 83 private: |
81 // The corresponding text input type. | 84 // The corresponding text input types. |
82 InputScope input_scope_; | 85 std::vector<InputScope> input_scopes_; |
83 | 86 |
84 // The refrence count of this instance. | 87 // The refrence count of this instance. |
85 volatile LONG ref_count_; | 88 volatile LONG ref_count_; |
86 | 89 |
87 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); | 90 DISALLOW_COPY_AND_ASSIGN(TSFInputScope); |
88 }; | 91 }; |
89 | 92 |
90 typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, | 93 typedef HRESULT (WINAPI *SetInputScopeFunc)(HWND window_handle, |
91 InputScope input_scope); | 94 InputScope input_scope); |
92 | 95 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 case TEXT_INPUT_TYPE_URL: | 132 case TEXT_INPUT_TYPE_URL: |
130 return IS_URL; | 133 return IS_URL; |
131 default: | 134 default: |
132 return IS_DEFAULT; | 135 return IS_DEFAULT; |
133 } | 136 } |
134 } | 137 } |
135 | 138 |
136 } // namespace | 139 } // namespace |
137 | 140 |
138 ITfInputScope* CreateInputScope(TextInputType text_input_type) { | 141 ITfInputScope* CreateInputScope(TextInputType text_input_type) { |
139 return new TSFInputScope(GetInputScopeType(text_input_type)); | 142 std::vector<InputScope> input_scopes(1); |
| 143 input_scopes.push_back(GetInputScopeType(text_input_type)); |
| 144 return new TSFInputScope(input_scopes); |
140 } | 145 } |
141 | 146 |
142 void SetInputScopeForTsfUnawareWindow(HWND window_handle, | 147 void SetInputScopeForTsfUnawareWindow(HWND window_handle, |
143 TextInputType text_input_type) { | 148 TextInputType text_input_type) { |
144 SetInputScopeFunc set_input_scope = GetSetInputScope(); | 149 SetInputScopeFunc set_input_scope = GetSetInputScope(); |
145 if (set_input_scope) | 150 if (set_input_scope) |
146 set_input_scope(window_handle, GetInputScopeType(text_input_type)); | 151 set_input_scope(window_handle, GetInputScopeType(text_input_type)); |
147 } | 152 } |
148 | 153 |
149 } // namespace tsf_inputscope | 154 } // namespace tsf_inputscope |
150 } // namespace ui | 155 } // namespace ui |
OLD | NEW |