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

Side by Side Diff: ui/base/win/tsf_text_store.h

Issue 10831403: TsfTextStore implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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 | « no previous file | ui/base/win/tsf_text_store.cc » ('j') | ui/base/win/tsf_text_store.cc » ('J')
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 #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/string16.h"
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/range/range.h"
13 17
14 namespace ui { 18 namespace ui {
19 class TextInputClient;
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
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
158 // Sends OnLayoutChange() via |text_store_acp_sink_|.
159 void SendOnLayoutChange();
160
147 private: 161 private:
162 friend class TsfTextStoreTest;
163
148 // The refrence count of this instance. 164 // The refrence count of this instance.
149 volatile LONG ref_count_; 165 volatile LONG ref_count_;
150 166
151 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. 167 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink.
152 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; 168 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_;
153 169
154 // The current mask of |text_store_acp_sink_|. 170 // The current mask of |text_store_acp_sink_|.
155 DWORD text_store_acp_sink_mask_; 171 DWORD text_store_acp_sink_mask_;
156 172
173 // HWND of the current view window which is set in SetFocusedTextInputClient.
174 HWND hwnd_;
175
176 // Current TextInputClient which is set in SetFocusedTextInputClient.
177 TextInputClient* text_input_client_;
178
179 // Current status of the text store.
180 struct TextStoreStatus {
Seigo Nonaka 2012/08/21 16:14:06 Do you think this struct should be exposed? If not
horo 2012/08/22 02:22:33 It is exposed because I would like to access to th
181 public:
182 TextStoreStatus()
183 : commited_size_(0),
184 edit_flag_(false) {
185 }
186 void InsertText(int position, const string16& buffer){
187 string_buffer_ = string_buffer_.substr(0, position) +
188 buffer + string_buffer_.substr(position);
189 }
190 void RemoveText(size_t position, size_t count) {
191 string_buffer_ = string_buffer_.substr(0, position) +
192 string_buffer_.substr(position + count);
193 }
194 void MoveSelection(size_t selection_start, size_t selection_end) {
195 size_t text_length = string_buffer_.length();
196 if (selection_start >= text_length)
197 selection_start = text_length;
198 if (selection_end >= text_length)
199 selection_end = text_length;
200 selection_.set_start(selection_start);
201 selection_.set_end(selection_end);
202 }
203
204 // |string_buffer_| contains commited string and composition string.
205 // example: "aoi" is committed, and "umi" is under composition.
206 // |string_buffer_|: "aoiumi"
207 // |commited_size_|: 3
208 string16 string_buffer_;
209 size_t commited_size_;
210
211 // |selection_start_| and |selection_end_| indicates the selection range.
212 // example: "iue" is selected
213 // |string_buffer_|: "aiueo"
214 // |selection_.start()|: 1
215 // |selection_.end()|: 4
216 Range selection_;
217
218 // |start_offset| and |end_offset| of |composition_undelines_| indicates
219 // the offsets in |string_buffer_|.
220 // example: "aoi" is committed. There are two underlines in "umi" and "no".
221 // |string_buffer_|: "aoiumino"
222 // |commited_size_|: 3
223 // composition_undelines_.underlines[0].start_offset: 3
224 // composition_undelines_.underlines[0].end_offset: 6
225 // composition_undelines_.underlines[1].start_offset: 6
226 // composition_undelines_.underlines[1].end_offset: 8
227 CompositionUnderlines composition_undelines_;
228
229 // |edit_flag_| indicates that the status is edited during
230 // ITextStoreACPSink::OnLockGranted().
231 bool edit_flag_;
232 } status_;
233
234 // The type of current lock.
235 // 0: No lock.
236 // TS_LF_READ: read-only lock.
237 // TS_LF_READWRITE: read/write lock.
238 DWORD current_lock_type_;
239
240 // Queue of the lock request used in RequestLock().
241 std::deque<DWORD> lock_queue_;
242
243 // Check if the document has a read-only lock.
244 bool ReaderLocked() const;
245
246 // Check if the document has a read and write lock.
247 bool WriterLocked() const;
248
249 // Category manager and Display attribute manager are used to obtain the
250 // attributes of the composition string.
251 base::win::ScopedComPtr<ITfCategoryMgr> category_manager_;
252 base::win::ScopedComPtr<ITfDisplayAttributeMgr> display_attribute_manager_;
253
254 // Gets the display attribute structure.
255 bool GetDisplayAttribute(TfGuidAtom guid_atom,
256 TF_DISPLAYATTRIBUTE* attribute);
257
258 // Gets the commited string size and underline information of the context.
259 bool GetCompositionStatus(ITfContext* context,
260 const TfEditCookie read_only_edit_cookie,
261 size_t* commited_size,
262 CompositionUnderlines* undelines);
157 DISALLOW_COPY_AND_ASSIGN(TsfTextStore); 263 DISALLOW_COPY_AND_ASSIGN(TsfTextStore);
158 }; 264 };
159 265
160 } // namespace ui 266 } // namespace ui
161 267
162 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_ 268 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_
OLDNEW
« no previous file with comments | « no previous file | ui/base/win/tsf_text_store.cc » ('j') | ui/base/win/tsf_text_store.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698