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/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" |
| 17 #include "ui/base/ui_export.h" |
13 | 18 |
14 namespace ui { | 19 namespace ui { |
| 20 class TextInputClient; |
15 | 21 |
16 // TsfTextStore is used to interact with the system input method via TSF. | 22 // TsfTextStore is used to interact with the system input method via TSF. |
17 class TsfTextStore : public ITextStoreACP, | 23 class UI_EXPORT TsfTextStore : public ITextStoreACP, |
18 public ITfContextOwnerCompositionSink, | 24 public ITfContextOwnerCompositionSink, |
19 public ITfTextEditSink { | 25 public ITfTextEditSink { |
20 public: | 26 public: |
21 TsfTextStore(); | 27 TsfTextStore(); |
22 ~TsfTextStore(); | 28 virtual ~TsfTextStore(); |
23 | 29 |
24 virtual ULONG STDMETHODCALLTYPE AddRef() OVERRIDE; | 30 virtual ULONG STDMETHODCALLTYPE AddRef() OVERRIDE; |
25 virtual ULONG STDMETHODCALLTYPE Release() OVERRIDE; | 31 virtual ULONG STDMETHODCALLTYPE Release() OVERRIDE; |
26 | 32 |
27 // Subclasses should extend this to return any interfaces they provide. | 33 // Subclasses should extend this to return any interfaces they provide. |
28 virtual STDMETHODIMP QueryInterface(REFIID iid, void** ppv) OVERRIDE; | 34 virtual STDMETHODIMP QueryInterface(REFIID iid, void** ppv) OVERRIDE; |
29 | 35 |
30 // ITextStoreACP overrides. | 36 // ITextStoreACP overrides. |
31 virtual STDMETHODIMP AdviseSink(REFIID iid, IUnknown* unknown, | 37 virtual STDMETHODIMP AdviseSink(REFIID iid, IUnknown* unknown, |
32 DWORD mask) OVERRIDE; | 38 DWORD mask) OVERRIDE; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 virtual STDMETHODIMP OnUpdateComposition(ITfCompositionView* composition_view, | 143 virtual STDMETHODIMP OnUpdateComposition(ITfCompositionView* composition_view, |
138 ITfRange* range) OVERRIDE; | 144 ITfRange* range) OVERRIDE; |
139 virtual STDMETHODIMP OnEndComposition( | 145 virtual STDMETHODIMP OnEndComposition( |
140 ITfCompositionView* composition_view) OVERRIDE; | 146 ITfCompositionView* composition_view) OVERRIDE; |
141 | 147 |
142 // ITfTextEditSink overrides. | 148 // ITfTextEditSink overrides. |
143 virtual STDMETHODIMP OnEndEdit(ITfContext* context, | 149 virtual STDMETHODIMP OnEndEdit(ITfContext* context, |
144 TfEditCookie read_only_edit_cookie, | 150 TfEditCookie read_only_edit_cookie, |
145 ITfEditRecord* edit_record) OVERRIDE; | 151 ITfEditRecord* edit_record) OVERRIDE; |
146 | 152 |
| 153 // Sets currently focused TextInputClient. |
| 154 void SetFocusedTextInputClient(HWND focused_window, |
| 155 TextInputClient* text_input_client); |
| 156 // Removes currently focused TextInputClient. |
| 157 void RemoveFocusedTextInputClient(TextInputClient* text_input_client); |
| 158 |
| 159 // Sends OnLayoutChange() via |text_store_acp_sink_|. |
| 160 void SendOnLayoutChange(); |
| 161 |
147 private: | 162 private: |
| 163 friend class TsfTextStoreTest; |
| 164 friend class TsfTextStoreTestCallback; |
| 165 |
| 166 // Checks if the document has a read-only lock. |
| 167 bool HasReadLock() const; |
| 168 |
| 169 // Checks if the document has a read and write lock. |
| 170 bool HasReadWriteLock() const; |
| 171 |
| 172 // Gets the display attribute structure. |
| 173 bool GetDisplayAttribute(TfGuidAtom guid_atom, |
| 174 TF_DISPLAYATTRIBUTE* attribute); |
| 175 |
| 176 // Gets the committed string size and underline information of the context. |
| 177 bool GetCompositionStatus(ITfContext* context, |
| 178 const TfEditCookie read_only_edit_cookie, |
| 179 size_t* committed_size, |
| 180 CompositionUnderlines* undelines); |
| 181 |
148 // The refrence count of this instance. | 182 // The refrence count of this instance. |
149 volatile LONG ref_count_; | 183 volatile LONG ref_count_; |
150 | 184 |
151 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. | 185 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. |
152 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; | 186 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; |
153 | 187 |
154 // The current mask of |text_store_acp_sink_|. | 188 // The current mask of |text_store_acp_sink_|. |
155 DWORD text_store_acp_sink_mask_; | 189 DWORD text_store_acp_sink_mask_; |
156 | 190 |
| 191 // HWND of the current view window which is set in SetFocusedTextInputClient. |
| 192 HWND window_handle_; |
| 193 |
| 194 // Current TextInputClient which is set in SetFocusedTextInputClient. |
| 195 TextInputClient* text_input_client_; |
| 196 |
| 197 // |string_buffer_| contains committed string and composition string. |
| 198 // example: "aoi" is committed, and "umi" is under composition. |
| 199 // |string_buffer_|: "aoiumi" |
| 200 // |committed_size_|: 3 |
| 201 string16 string_buffer_; |
| 202 size_t committed_size_; |
| 203 |
| 204 // |selection_start_| and |selection_end_| indicates the selection range. |
| 205 // example: "iue" is selected |
| 206 // |string_buffer_|: "aiueo" |
| 207 // |selection_.start()|: 1 |
| 208 // |selection_.end()|: 4 |
| 209 Range selection_; |
| 210 |
| 211 // |start_offset| and |end_offset| of |composition_undelines_| indicates |
| 212 // the offsets in |string_buffer_|. |
| 213 // example: "aoi" is committed. There are two underlines in "umi" and "no". |
| 214 // |string_buffer_|: "aoiumino" |
| 215 // |committed_size_|: 3 |
| 216 // composition_undelines_.underlines[0].start_offset: 3 |
| 217 // composition_undelines_.underlines[0].end_offset: 6 |
| 218 // composition_undelines_.underlines[1].start_offset: 6 |
| 219 // composition_undelines_.underlines[1].end_offset: 8 |
| 220 CompositionUnderlines composition_undelines_; |
| 221 |
| 222 // |edit_flag_| indicates that the status is edited during |
| 223 // ITextStoreACPSink::OnLockGranted(). |
| 224 bool edit_flag_; |
| 225 |
| 226 // The type of current lock. |
| 227 // 0: No lock. |
| 228 // TS_LF_READ: read-only lock. |
| 229 // TS_LF_READWRITE: read/write lock. |
| 230 DWORD current_lock_type_; |
| 231 |
| 232 // Queue of the lock request used in RequestLock(). |
| 233 std::deque<DWORD> lock_queue_; |
| 234 |
| 235 // Category manager and Display attribute manager are used to obtain the |
| 236 // attributes of the composition string. |
| 237 base::win::ScopedComPtr<ITfCategoryMgr> category_manager_; |
| 238 base::win::ScopedComPtr<ITfDisplayAttributeMgr> display_attribute_manager_; |
| 239 |
157 DISALLOW_COPY_AND_ASSIGN(TsfTextStore); | 240 DISALLOW_COPY_AND_ASSIGN(TsfTextStore); |
158 }; | 241 }; |
159 | 242 |
160 } // namespace ui | 243 } // namespace ui |
161 | 244 |
162 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_ | 245 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_ |
OLD | NEW |