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 #ifndef UI_BASE_WIN_TSF_TEXT_STORE_H_ | 5 #ifndef UI_BASE_WIN_TSF_TEXT_STORE_H_ |
6 #define UI_BASE_WIN_TSF_TEXT_STORE_H_ | 6 #define UI_BASE_WIN_TSF_TEXT_STORE_H_ |
7 | 7 |
8 #include <msctf.h> | 8 #include <msctf.h> |
9 #include <deque> | |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | |
Seigo Nonaka
2012/08/21 12:22:41
We can omit this line.
horo
2012/08/21 13:59:57
Done.
| |
12 #include "base/win/scoped_comptr.h" | 14 #include "base/win/scoped_comptr.h" |
15 #include "ui/base/ime/composition_underline.h" | |
16 #include "ui/base/ime/text_input_client.h" | |
Seigo Nonaka
2012/08/21 12:22:41
plz use forward declaration instead.
horo
2012/08/21 13:59:57
Done.
| |
17 #include "ui/base/ui_export.h" | |
Seigo Nonaka
2012/08/21 12:22:41
Do you need UI_EXPORT?
horo
2012/08/21 13:59:57
deleted
| |
13 | 18 |
14 namespace ui { | 19 namespace ui { |
15 | 20 |
16 // TsfTextStore is used to interact with the system input method via TSF. | 21 // TsfTextStore is used to interact with the system input method via TSF. |
17 class TsfTextStore : public ITextStoreACP, | 22 class TsfTextStore : public ITextStoreACP, |
18 public ITfContextOwnerCompositionSink, | 23 public ITfContextOwnerCompositionSink, |
19 public ITfTextEditSink { | 24 public ITfTextEditSink { |
20 public: | 25 public: |
21 TsfTextStore(); | 26 TsfTextStore(); |
22 ~TsfTextStore(); | 27 virtual ~TsfTextStore(); |
23 | 28 |
24 virtual ULONG STDMETHODCALLTYPE AddRef() OVERRIDE; | 29 virtual ULONG STDMETHODCALLTYPE AddRef() OVERRIDE; |
25 virtual ULONG STDMETHODCALLTYPE Release() OVERRIDE; | 30 virtual ULONG STDMETHODCALLTYPE Release() OVERRIDE; |
26 | 31 |
27 // Subclasses should extend this to return any interfaces they provide. | 32 // Subclasses should extend this to return any interfaces they provide. |
28 virtual STDMETHODIMP QueryInterface(REFIID iid, void** ppv) OVERRIDE; | 33 virtual STDMETHODIMP QueryInterface(REFIID iid, void** ppv) OVERRIDE; |
29 | 34 |
30 // ITextStoreACP overrides. | 35 // ITextStoreACP overrides. |
31 virtual STDMETHODIMP AdviseSink(REFIID iid, IUnknown* unknown, | 36 virtual STDMETHODIMP AdviseSink(REFIID iid, IUnknown* unknown, |
32 DWORD mask) OVERRIDE; | 37 DWORD mask) OVERRIDE; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 virtual STDMETHODIMP OnUpdateComposition(ITfCompositionView* composition_view, | 142 virtual STDMETHODIMP OnUpdateComposition(ITfCompositionView* composition_view, |
138 ITfRange* range) OVERRIDE; | 143 ITfRange* range) OVERRIDE; |
139 virtual STDMETHODIMP OnEndComposition( | 144 virtual STDMETHODIMP OnEndComposition( |
140 ITfCompositionView* composition_view) OVERRIDE; | 145 ITfCompositionView* composition_view) OVERRIDE; |
141 | 146 |
142 // ITfTextEditSink overrides. | 147 // ITfTextEditSink overrides. |
143 virtual STDMETHODIMP OnEndEdit(ITfContext* context, | 148 virtual STDMETHODIMP OnEndEdit(ITfContext* context, |
144 TfEditCookie read_only_edit_cookie, | 149 TfEditCookie read_only_edit_cookie, |
145 ITfEditRecord* edit_record) OVERRIDE; | 150 ITfEditRecord* edit_record) OVERRIDE; |
146 | 151 |
152 // Sets currently focused TextInputClient. | |
153 void SetFocusedTextInputClient(HWND focused_window, | |
154 TextInputClient* text_input_client); | |
155 // Removes currently focused TextInputClient. | |
156 void RemoveFocusedTextInputClient(TextInputClient* text_input_client); | |
157 | |
147 private: | 158 private: |
159 friend class TsfTextStoreTest; | |
160 | |
148 // The refrence count of this instance. | 161 // The refrence count of this instance. |
149 volatile LONG ref_count_; | 162 volatile LONG ref_count_; |
150 | 163 |
151 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. | 164 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. |
152 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; | 165 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; |
153 | 166 |
154 // The current mask of |text_store_acp_sink_|. | 167 // The current mask of |text_store_acp_sink_|. |
155 DWORD text_store_acp_sink_mask_; | 168 DWORD text_store_acp_sink_mask_; |
156 | 169 |
170 // HWND of the current view window which is set in SetFocus(). | |
Seigo Nonaka
2012/08/21 12:22:41
nit: SetFocusedTextInputClient
horo
2012/08/21 13:59:57
Done.
| |
171 HWND hwnd_; | |
172 | |
173 // Current TextInputClien which is set in SetFocus(). | |
Seigo Nonaka
2012/08/21 12:22:41
/TextInputClien/TextInputClient/
/SetFocus/SetFocu
horo
2012/08/21 13:59:57
Done.
| |
174 TextInputClient* text_input_client_; | |
175 | |
176 // Current status of the text store. | |
177 struct TextStoreStatus { | |
178 public: | |
179 TextStoreStatus() : commited_size_(0), selection_start_(0), | |
Seigo Nonaka
2012/08/21 12:22:41
Plz initialize one line one variable.
http://googl
horo
2012/08/21 13:59:57
Done.
| |
180 selection_end_(0), edit_flag_(false) { | |
181 } | |
182 void InsertText(int nPos, const string16 &buffer){ | |
Seigo Nonaka
2012/08/21 12:22:41
/string16 &/string16& /
Seigo Nonaka
2012/08/21 12:22:41
nit: /nPos/position/
horo
2012/08/21 13:59:57
Done.
horo
2012/08/21 13:59:57
Done.
| |
183 string_buffer_ = string_buffer_.substr(0, nPos) + | |
184 buffer + string_buffer_.substr(nPos); | |
185 } | |
186 void RemoveText(size_t pos, size_t count) { | |
187 string_buffer_ = string_buffer_.substr(0, pos) + | |
188 string_buffer_.substr(pos + count); | |
189 } | |
190 void MoveSelection(size_t selection_start, size_t selection_end) { | |
191 size_t nTextLength = string_buffer_.length(); | |
192 if (selection_start >= nTextLength) | |
193 selection_start = nTextLength; | |
194 if (selection_end >= nTextLength) | |
195 selection_end = nTextLength; | |
196 selection_start_ = selection_start; | |
197 selection_end_ = selection_end; | |
198 } | |
199 | |
200 // |string_buffer_| contains commited string and composition string. | |
201 // example: "aoi" is committed, and "umi" is under composition. | |
202 // |string_buffer_|: "aoiumi" | |
203 // |commited_size_|: 3 | |
204 string16 string_buffer_; | |
205 size_t commited_size_; | |
206 | |
207 // |selection_start_| and |selection_end_| indicates the selection range. | |
208 // example: "iue" is selected | |
209 // |string_buffer_|: "aiueo" | |
210 // |selection_start_|: 1 | |
211 // |selection_end_|: 4 | |
212 size_t selection_start_; | |
213 size_t selection_end_; | |
Seigo Nonaka
2012/08/21 12:22:41
How about introduce ui::Range object?
horo
2012/08/21 13:59:57
Done.
| |
214 | |
215 // |start_offset| and |end_offset| of |composition_undelines_| indicates | |
216 // the offsets in |string_buffer_|. | |
217 // example: "aoi" is committed. There are two underlines in "umi" and "no". | |
218 // |string_buffer_|: "aoiumino" | |
219 // |commited_size_|: 3 | |
220 // composition_undelines_.underlines[0].start_offset: 3 | |
221 // composition_undelines_.underlines[0].end_offset: 6 | |
222 // composition_undelines_.underlines[1].start_offset: 6 | |
223 // composition_undelines_.underlines[1].end_offset: 8 | |
224 CompositionUnderlines composition_undelines_; | |
225 | |
226 // |edit_flag_| indicates that the status is edited during | |
227 // ITextStoreACPSink::OnLockGranted(). | |
228 bool edit_flag_; | |
229 } status_; | |
230 | |
231 // The type of current lock. | |
232 // 0: No lock. | |
233 // TS_LF_READ: read-only lock. | |
234 // TS_LF_READWRITE: read/write lock. | |
235 DWORD current_lock_type_; | |
236 // Queue of the lock request used in RequestLock(). | |
Seigo Nonaka
2012/08/21 12:22:41
Please add one line before line comment.
horo
2012/08/21 13:59:57
Done.
| |
237 std::deque<DWORD> lock_queue_; | |
238 // Check if the document has a read-only lock. | |
239 bool ReaderLocked() const; | |
240 // Check if the document has a read and write lock. | |
241 bool WriterLocked() const; | |
242 | |
243 // Category manager and Display attribute manager are used to obtain the | |
244 // attributes of the composition string. | |
245 base::win::ScopedComPtr<ITfCategoryMgr> category_mgr_; | |
Seigo Nonaka
2012/08/21 12:22:41
Plz do not abbreviate the variables.
http://google
horo
2012/08/21 13:59:57
Done.
| |
246 base::win::ScopedComPtr<ITfDisplayAttributeMgr> display_attribute_mgr_; | |
247 | |
248 // Gets the display attribute structure. | |
249 bool GetDisplayAttribute(TfGuidAtom guid_atom, | |
250 TF_DISPLAYATTRIBUTE* attribute); | |
251 | |
252 // Gets the commited string size and underline information of the context. | |
253 bool GetCompositionStatus(ITfContext* context, | |
254 const TfEditCookie read_only_edit_cookie, | |
255 size_t* commited_size, | |
256 CompositionUnderlines* undelines); | |
157 DISALLOW_COPY_AND_ASSIGN(TsfTextStore); | 257 DISALLOW_COPY_AND_ASSIGN(TsfTextStore); |
158 }; | 258 }; |
159 | 259 |
160 } // namespace ui | 260 } // namespace ui |
161 | 261 |
162 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_ | 262 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_ |
OLD | NEW |