Chromium Code Reviews| 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 input method via TSF manager. |
| 17 class TsfTextStore : public ITextStoreACP, | 23 // TsfTextStore have a string buffer which is manipulated by TSF manager through |
| 18 public ITfContextOwnerCompositionSink, | 24 // ITextStoreACP interface methods such as SetText(). |
| 19 public ITfTextEditSink { | 25 // When the input method updates the composition, TsfTextStore calls |
| 26 // TextInputClient::SetCompositionText(). And when the input method finishes the | |
| 27 // composition, TsfTextStore calls TextInputClient::InsertText() and clears the | |
| 28 // buffer. | |
| 29 // | |
| 30 // How TsfTextStore works: | |
| 31 // - The user enter "a". | |
|
cpu_(ooo_6.6-7.5)
2012/08/24 21:12:44
the user enters 'a".
same for line 44, 55
horo
2012/08/27 03:46:49
Done.
| |
| 32 // - The input method set composition as "a". | |
| 33 // - TSF manager calls TsfTextStore::RequestLock(). | |
| 34 // - TsfTextStore callbacks ITextStoreACPSink::OnLockGranted(). | |
| 35 // - In OnLockGranted(), TSF manager calls | |
| 36 // - TsfTextStore::OnStartComposition() | |
| 37 // - TsfTextStore::SetText() | |
| 38 // The string buffer is set as "a". | |
| 39 // - TsfTextStore::OnUpdateComposition() | |
| 40 // - TsfTextStore::OnEndEdit() | |
| 41 // TsfTextStore can get the composition information such as underlines. | |
| 42 // - TsfTextStore calls TextInputClient::SetCompositionText(). | |
| 43 // "a" is shown with an underline as composition string. | |
| 44 // - The user enter <space>. | |
| 45 // - The input method set composition as "A". | |
| 46 // - TSF manager calls TsfTextStore::RequestLock(). | |
| 47 // - TsfTextStore callbacks ITextStoreACPSink::OnLockGranted(). | |
| 48 // - In OnLockGranted(), TSF manager calls | |
| 49 // - TsfTextStore::SetText() | |
| 50 // The string buffer is set as "A". | |
| 51 // - TsfTextStore::OnUpdateComposition() | |
| 52 // - TsfTextStore::OnEndEdit() | |
| 53 // - TsfTextStore calls TextInputClient::SetCompositionText(). | |
| 54 // "A" is shown with an underline as composition string. | |
| 55 // - The user enter <enter>. | |
| 56 // - The input method commits "A". | |
| 57 // - TSF manager calls TsfTextStore::RequestLock(). | |
| 58 // - TsfTextStore callbacks ITextStoreACPSink::OnLockGranted(). | |
| 59 // - In OnLockGranted(), TSF manager calls | |
| 60 // - TsfTextStore::OnEndComposition() | |
| 61 // - TsfTextStore::OnEndEdit() | |
| 62 // TsfTextStore knows "A" is committed. | |
| 63 // - TsfTextStore calls TextInputClient::InsertText(). | |
| 64 // "A" is shown as committed string. | |
| 65 // - TsfTextStore clears the string buffer. | |
| 66 // - TsfTextStore calls OnSelectionChange(), OnLayoutChange() and | |
| 67 // OnTextChange() of ITextStoreACPSink to let TSF manager know that the | |
| 68 // string buffer has been changed. | |
| 69 // | |
| 70 // About locking scheme: | |
|
cpu_(ooo_6.6-7.5)
2012/08/24 21:12:44
About the locking scheme:
horo
2012/08/27 03:46:49
Done.
| |
| 71 // When TSF manager manipulates the string buffer it calls RequestLock() to get | |
| 72 // the lock of the document. If TsfTextStore can grant the lock request, it | |
| 73 // callbacks ITextStoreACPSink::OnLockGranted(). | |
| 74 // RequestLock() is called from only one thread, but called recursively in | |
| 75 // OnLockGranted() or OnSelectionChange() or OnLayoutChange() or OnTextChange(). | |
| 76 // If the document is locked and the lock request is asynchronous, TsfTextStore | |
| 77 // queues the request. The queued requests will be handled after the current | |
| 78 // lock is removed. | |
| 79 // More information about document locks can be found here: | |
| 80 // http://msdn.microsoft.com/en-us/library/ms538064 | |
| 81 // | |
| 82 // More information about TSF can be found here: | |
| 83 // http://msdn.microsoft.com/en-us/library/ms629032 | |
| 84 class UI_EXPORT TsfTextStore : public ITextStoreACP, | |
| 85 public ITfContextOwnerCompositionSink, | |
| 86 public ITfTextEditSink { | |
| 20 public: | 87 public: |
| 21 TsfTextStore(); | 88 TsfTextStore(); |
| 22 ~TsfTextStore(); | 89 virtual ~TsfTextStore(); |
| 23 | 90 |
| 24 virtual ULONG STDMETHODCALLTYPE AddRef() OVERRIDE; | 91 virtual ULONG STDMETHODCALLTYPE AddRef() OVERRIDE; |
| 25 virtual ULONG STDMETHODCALLTYPE Release() OVERRIDE; | 92 virtual ULONG STDMETHODCALLTYPE Release() OVERRIDE; |
| 26 | 93 |
| 27 // Subclasses should extend this to return any interfaces they provide. | 94 // Subclasses should extend this to return any interfaces they provide. |
| 28 virtual STDMETHODIMP QueryInterface(REFIID iid, void** ppv) OVERRIDE; | 95 virtual STDMETHODIMP QueryInterface(REFIID iid, void** ppv) OVERRIDE; |
| 29 | 96 |
| 30 // ITextStoreACP overrides. | 97 // ITextStoreACP overrides. |
| 31 virtual STDMETHODIMP AdviseSink(REFIID iid, IUnknown* unknown, | 98 virtual STDMETHODIMP AdviseSink(REFIID iid, IUnknown* unknown, |
| 32 DWORD mask) OVERRIDE; | 99 DWORD mask) OVERRIDE; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 virtual STDMETHODIMP OnUpdateComposition(ITfCompositionView* composition_view, | 204 virtual STDMETHODIMP OnUpdateComposition(ITfCompositionView* composition_view, |
| 138 ITfRange* range) OVERRIDE; | 205 ITfRange* range) OVERRIDE; |
| 139 virtual STDMETHODIMP OnEndComposition( | 206 virtual STDMETHODIMP OnEndComposition( |
| 140 ITfCompositionView* composition_view) OVERRIDE; | 207 ITfCompositionView* composition_view) OVERRIDE; |
| 141 | 208 |
| 142 // ITfTextEditSink overrides. | 209 // ITfTextEditSink overrides. |
| 143 virtual STDMETHODIMP OnEndEdit(ITfContext* context, | 210 virtual STDMETHODIMP OnEndEdit(ITfContext* context, |
| 144 TfEditCookie read_only_edit_cookie, | 211 TfEditCookie read_only_edit_cookie, |
| 145 ITfEditRecord* edit_record) OVERRIDE; | 212 ITfEditRecord* edit_record) OVERRIDE; |
| 146 | 213 |
| 214 // Sets currently focused TextInputClient. | |
| 215 void SetFocusedTextInputClient(HWND focused_window, | |
| 216 TextInputClient* text_input_client); | |
| 217 // Removes currently focused TextInputClient. | |
| 218 void RemoveFocusedTextInputClient(TextInputClient* text_input_client); | |
| 219 | |
| 220 // Sends OnLayoutChange() via |text_store_acp_sink_|. | |
| 221 void SendOnLayoutChange(); | |
| 222 | |
| 147 private: | 223 private: |
| 224 friend class TsfTextStoreTest; | |
| 225 friend class TsfTextStoreTestCallback; | |
| 226 | |
| 227 // Checks if the document has a read-only lock. | |
| 228 bool HasReadLock() const; | |
| 229 | |
| 230 // Checks if the document has a read and write lock. | |
| 231 bool HasReadWriteLock() const; | |
| 232 | |
| 233 // Gets the display attribute structure. | |
| 234 bool GetDisplayAttribute(TfGuidAtom guid_atom, | |
| 235 TF_DISPLAYATTRIBUTE* attribute); | |
| 236 | |
| 237 // Gets the committed string size and underline information of the context. | |
| 238 bool GetCompositionStatus(ITfContext* context, | |
| 239 const TfEditCookie read_only_edit_cookie, | |
| 240 size_t* committed_size, | |
| 241 CompositionUnderlines* undelines); | |
| 242 | |
| 148 // The refrence count of this instance. | 243 // The refrence count of this instance. |
| 149 volatile LONG ref_count_; | 244 volatile LONG ref_count_; |
| 150 | 245 |
| 151 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. | 246 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. |
| 152 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; | 247 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; |
| 153 | 248 |
| 154 // The current mask of |text_store_acp_sink_|. | 249 // The current mask of |text_store_acp_sink_|. |
| 155 DWORD text_store_acp_sink_mask_; | 250 DWORD text_store_acp_sink_mask_; |
| 156 | 251 |
| 252 // HWND of the current view window which is set in SetFocusedTextInputClient. | |
| 253 HWND window_handle_; | |
| 254 | |
| 255 // Current TextInputClient which is set in SetFocusedTextInputClient. | |
| 256 TextInputClient* text_input_client_; | |
| 257 | |
| 258 // |string_buffer_| contains committed string and composition string. | |
| 259 // Example: "aoi" is committed, and "umi" is under composition. | |
| 260 // |string_buffer_|: "aoiumi" | |
| 261 // |committed_size_|: 3 | |
| 262 string16 string_buffer_; | |
| 263 size_t committed_size_; | |
| 264 | |
| 265 // |selection_start_| and |selection_end_| indicates the selection range. | |
| 266 // Example: "iue" is selected | |
| 267 // |string_buffer_|: "aiueo" | |
| 268 // |selection_.start()|: 1 | |
| 269 // |selection_.end()|: 4 | |
| 270 Range selection_; | |
| 271 | |
| 272 // |start_offset| and |end_offset| of |composition_undelines_| indicates | |
| 273 // the offsets in |string_buffer_|. | |
| 274 // Example: "aoi" is committed. There are two underlines in "umi" and "no". | |
| 275 // |string_buffer_|: "aoiumino" | |
| 276 // |committed_size_|: 3 | |
| 277 // composition_undelines_.underlines[0].start_offset: 3 | |
| 278 // composition_undelines_.underlines[0].end_offset: 6 | |
| 279 // composition_undelines_.underlines[1].start_offset: 6 | |
| 280 // composition_undelines_.underlines[1].end_offset: 8 | |
| 281 CompositionUnderlines composition_undelines_; | |
| 282 | |
| 283 // |edit_flag_| indicates that the status is edited during | |
| 284 // ITextStoreACPSink::OnLockGranted(). | |
| 285 bool edit_flag_; | |
| 286 | |
| 287 // The type of current lock. | |
| 288 // 0: No lock. | |
| 289 // TS_LF_READ: read-only lock. | |
| 290 // TS_LF_READWRITE: read/write lock. | |
| 291 DWORD current_lock_type_; | |
| 292 | |
| 293 // Queue of the lock request used in RequestLock(). | |
| 294 std::deque<DWORD> lock_queue_; | |
| 295 | |
| 296 // Category manager and Display attribute manager are used to obtain the | |
| 297 // attributes of the composition string. | |
| 298 base::win::ScopedComPtr<ITfCategoryMgr> category_manager_; | |
| 299 base::win::ScopedComPtr<ITfDisplayAttributeMgr> display_attribute_manager_; | |
| 300 | |
| 157 DISALLOW_COPY_AND_ASSIGN(TsfTextStore); | 301 DISALLOW_COPY_AND_ASSIGN(TsfTextStore); |
| 158 }; | 302 }; |
| 159 | 303 |
| 160 } // namespace ui | 304 } // namespace ui |
| 161 | 305 |
| 162 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_ | 306 #endif // UI_BASE_WIN_TSF_TEXT_STORE_H_ |
| OLD | NEW |