| 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_IME_WIN_TSF_TEXT_STORE_H_ | 5 #ifndef WIN8_METRO_DRIVER_IME_TEXT_STORE_H_ |
| 6 #define UI_BASE_IME_WIN_TSF_TEXT_STORE_H_ | 6 #define WIN8_METRO_DRIVER_IME_TEXT_STORE_H_ |
| 7 | 7 |
| 8 #include <inputscope.h> |
| 8 #include <msctf.h> | 9 #include <msctf.h> |
| 10 |
| 9 #include <deque> | 11 #include <deque> |
| 12 #include <vector> |
| 10 | 13 |
| 11 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/memory/ref_counted.h" |
| 13 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 14 #include "base/win/scoped_comptr.h" | 18 #include "base/win/scoped_comptr.h" |
| 15 #include "ui/base/ime/composition_underline.h" | 19 #include "ui/metro_viewer/ime_types.h" |
| 16 #include "ui/base/ui_export.h" | |
| 17 #include "ui/gfx/range/range.h" | |
| 18 | 20 |
| 19 namespace ui { | 21 namespace metro_driver { |
| 20 class TextInputClient; | 22 |
| 23 class TextStoreDelegate; |
| 21 | 24 |
| 22 // TSFTextStore is used to interact with the input method via TSF manager. | 25 // TSFTextStore is used to interact with the input method via TSF manager. |
| 23 // TSFTextStore have a string buffer which is manipulated by TSF manager through | 26 // TSFTextStore have a string buffer which is manipulated by TSF manager through |
| 24 // ITextStoreACP interface methods such as SetText(). | 27 // ITextStoreACP interface methods such as SetText(). |
| 25 // When the input method updates the composition, TSFTextStore calls | 28 // When the input method updates the composition, TSFTextStore calls |
| 26 // TextInputClient::SetCompositionText(). And when the input method finishes the | 29 // TextInputClient::SetCompositionText(). And when the input method finishes the |
| 27 // composition, TSFTextStore calls TextInputClient::InsertText() and clears the | 30 // composition, TSFTextStore calls TextInputClient::InsertText() and clears the |
| 28 // buffer. | 31 // buffer. |
| 29 // | 32 // |
| 30 // How TSFTextStore works: | 33 // How TSFTextStore works: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // RequestLock() is called from only one thread, but called recursively in | 77 // RequestLock() is called from only one thread, but called recursively in |
| 75 // OnLockGranted() or OnSelectionChange() or OnLayoutChange() or OnTextChange(). | 78 // OnLockGranted() or OnSelectionChange() or OnLayoutChange() or OnTextChange(). |
| 76 // If the document is locked and the lock request is asynchronous, TSFTextStore | 79 // 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 | 80 // queues the request. The queued requests will be handled after the current |
| 78 // lock is removed. | 81 // lock is removed. |
| 79 // More information about document locks can be found here: | 82 // More information about document locks can be found here: |
| 80 // http://msdn.microsoft.com/en-us/library/ms538064 | 83 // http://msdn.microsoft.com/en-us/library/ms538064 |
| 81 // | 84 // |
| 82 // More information about TSF can be found here: | 85 // More information about TSF can be found here: |
| 83 // http://msdn.microsoft.com/en-us/library/ms629032 | 86 // http://msdn.microsoft.com/en-us/library/ms629032 |
| 84 class UI_EXPORT TSFTextStore : public ITextStoreACP, | 87 // TODO(yukawa): Rename TSFTextStore to TextStore. |
| 85 public ITfContextOwnerCompositionSink, | 88 class TSFTextStore : public ITextStoreACP, |
| 86 public ITfTextEditSink { | 89 public ITfContextOwnerCompositionSink, |
| 90 public ITfTextEditSink { |
| 87 public: | 91 public: |
| 88 TSFTextStore(); | |
| 89 virtual ~TSFTextStore(); | 92 virtual ~TSFTextStore(); |
| 90 | 93 |
| 91 // ITextStoreACP: | 94 // ITextStoreACP: |
| 92 STDMETHOD_(ULONG, AddRef)() OVERRIDE; | 95 STDMETHOD_(ULONG, AddRef)() OVERRIDE; |
| 93 STDMETHOD_(ULONG, Release)() OVERRIDE; | 96 STDMETHOD_(ULONG, Release)() OVERRIDE; |
| 94 STDMETHOD(QueryInterface)(REFIID iid, void** ppv) OVERRIDE; | 97 STDMETHOD(QueryInterface)(REFIID iid, void** ppv) OVERRIDE; |
| 95 STDMETHOD(AdviseSink)(REFIID iid, IUnknown* unknown, DWORD mask) OVERRIDE; | 98 STDMETHOD(AdviseSink)(REFIID iid, IUnknown* unknown, DWORD mask) OVERRIDE; |
| 96 STDMETHOD(FindNextAttrTransition)(LONG acp_start, | 99 STDMETHOD(FindNextAttrTransition)(LONG acp_start, |
| 97 LONG acp_halt, | 100 LONG acp_halt, |
| 98 ULONG num_filter_attributes, | 101 ULONG num_filter_attributes, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 STDMETHOD(OnStartComposition)(ITfCompositionView* composition_view, | 192 STDMETHOD(OnStartComposition)(ITfCompositionView* composition_view, |
| 190 BOOL* ok) OVERRIDE; | 193 BOOL* ok) OVERRIDE; |
| 191 STDMETHOD(OnUpdateComposition)(ITfCompositionView* composition_view, | 194 STDMETHOD(OnUpdateComposition)(ITfCompositionView* composition_view, |
| 192 ITfRange* range) OVERRIDE; | 195 ITfRange* range) OVERRIDE; |
| 193 STDMETHOD(OnEndComposition)(ITfCompositionView* composition_view) OVERRIDE; | 196 STDMETHOD(OnEndComposition)(ITfCompositionView* composition_view) OVERRIDE; |
| 194 | 197 |
| 195 // ITfTextEditSink: | 198 // ITfTextEditSink: |
| 196 STDMETHOD(OnEndEdit)(ITfContext* context, TfEditCookie read_only_edit_cookie, | 199 STDMETHOD(OnEndEdit)(ITfContext* context, TfEditCookie read_only_edit_cookie, |
| 197 ITfEditRecord* edit_record) OVERRIDE; | 200 ITfEditRecord* edit_record) OVERRIDE; |
| 198 | 201 |
| 199 // Sets currently focused TextInputClient. | |
| 200 void SetFocusedTextInputClient(HWND focused_window, | |
| 201 TextInputClient* text_input_client); | |
| 202 // Removes currently focused TextInputClient. | |
| 203 void RemoveFocusedTextInputClient(TextInputClient* text_input_client); | |
| 204 | |
| 205 // Cancels the ongoing composition if exists. | 202 // Cancels the ongoing composition if exists. |
| 206 bool CancelComposition(); | 203 bool CancelComposition(); |
| 207 | 204 |
| 208 // Confirms the ongoing composition if exists. | 205 // Confirms the ongoing composition if exists. |
| 209 bool ConfirmComposition(); | 206 bool ConfirmComposition(); |
| 210 | 207 |
| 211 // Sends OnLayoutChange() via |text_store_acp_sink_|. | 208 // Sends OnLayoutChange() via |text_store_acp_sink_|. |
| 212 void SendOnLayoutChange(); | 209 void SendOnLayoutChange(); |
| 213 | 210 |
| 211 // Creates an instance of TSFTextStore. Returns NULL if fails. |
| 212 static scoped_refptr<TSFTextStore> Create( |
| 213 HWND window_handle, |
| 214 const std::vector<InputScope>& input_scopes, |
| 215 TextStoreDelegate* delegate); |
| 216 |
| 214 private: | 217 private: |
| 215 friend class TSFTextStoreTest; | 218 TSFTextStore(HWND window_handle, |
| 216 friend class TSFTextStoreTestCallback; | 219 ITfCategoryMgr* category_manager, |
| 220 ITfDisplayAttributeMgr* display_attribute_manager, |
| 221 ITfInputScope* input_scope, |
| 222 TextStoreDelegate* delegate); |
| 217 | 223 |
| 218 // Checks if the document has a read-only lock. | 224 // Checks if the document has a read-only lock. |
| 219 bool HasReadLock() const; | 225 bool HasReadLock() const; |
| 220 | 226 |
| 221 // Checks if the document has a read and write lock. | 227 // Checks if the document has a read and write lock. |
| 222 bool HasReadWriteLock() const; | 228 bool HasReadWriteLock() const; |
| 223 | 229 |
| 224 // Gets the display attribute structure. | 230 // Gets the display attribute structure. |
| 225 bool GetDisplayAttribute(TfGuidAtom guid_atom, | 231 bool GetDisplayAttribute(TfGuidAtom guid_atom, |
| 226 TF_DISPLAYATTRIBUTE* attribute); | 232 TF_DISPLAYATTRIBUTE* attribute); |
| 227 | 233 |
| 228 // Gets the committed string size and underline information of the context. | 234 // Gets the committed string size and underline information of the context. |
| 229 bool GetCompositionStatus(ITfContext* context, | 235 bool GetCompositionStatus( |
| 230 const TfEditCookie read_only_edit_cookie, | 236 ITfContext* context, |
| 231 size_t* committed_size, | 237 const TfEditCookie read_only_edit_cookie, |
| 232 CompositionUnderlines* undelines); | 238 size_t* committed_size, |
| 239 std::vector<metro_viewer::UnderlineInfo>* undelines); |
| 233 | 240 |
| 234 // The refrence count of this instance. | 241 // The refrence count of this instance. |
| 235 volatile LONG ref_count_; | 242 volatile LONG ref_count_; |
| 236 | 243 |
| 237 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. | 244 // A pointer of ITextStoreACPSink, this instance is given in AdviseSink. |
| 238 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; | 245 base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_; |
| 239 | 246 |
| 240 // The current mask of |text_store_acp_sink_|. | 247 // The current mask of |text_store_acp_sink_|. |
| 241 DWORD text_store_acp_sink_mask_; | 248 DWORD text_store_acp_sink_mask_; |
| 242 | 249 |
| 243 // HWND of the current view window which is set in SetFocusedTextInputClient. | 250 // HWND of the attached window. |
| 244 HWND window_handle_; | 251 HWND window_handle_; |
| 245 | 252 |
| 246 // Current TextInputClient which is set in SetFocusedTextInputClient. | 253 // The delegate attached to this text store. |
| 247 TextInputClient* text_input_client_; | 254 TextStoreDelegate* delegate_; |
| 248 | 255 |
| 249 // |string_buffer_| contains committed string and composition string. | 256 // |string_buffer_| contains committed string and composition string. |
| 250 // Example: "aoi" is committed, and "umi" is under composition. | 257 // Example: "aoi" is committed, and "umi" is under composition. |
| 251 // |string_buffer_|: "aoiumi" | 258 // |string_buffer_|: "aoiumi" |
| 252 // |committed_size_|: 3 | 259 // |committed_size_|: 3 |
| 253 string16 string_buffer_; | 260 string16 string_buffer_; |
| 254 size_t committed_size_; | 261 size_t committed_size_; |
| 255 | 262 |
| 256 // |selection_start_| and |selection_end_| indicates the selection range. | 263 // |selection_start_| and |selection_end_| indicates the selection range. |
| 257 // Example: "iue" is selected | 264 // Example: "iue" is selected |
| 258 // |string_buffer_|: "aiueo" | 265 // |string_buffer_|: "aiueo" |
| 259 // |selection_.start()|: 1 | 266 // |selection_start_|: 1 |
| 260 // |selection_.end()|: 4 | 267 // |selection_end_|: 4 |
| 261 gfx::Range selection_; | 268 size_t selection_start_; |
| 269 size_t selection_end_; |
| 262 | 270 |
| 263 // |start_offset| and |end_offset| of |composition_undelines_| indicates | 271 // |start_offset| and |end_offset| of |composition_undelines_| indicates |
| 264 // the offsets in |string_buffer_|. | 272 // the offsets in |string_buffer_|. |
| 265 // Example: "aoi" is committed. There are two underlines in "umi" and "no". | 273 // Example: "aoi" is committed. There are two underlines in "umi" and "no". |
| 266 // |string_buffer_|: "aoiumino" | 274 // |string_buffer_|: "aoiumino" |
| 267 // |committed_size_|: 3 | 275 // |committed_size_|: 3 |
| 268 // composition_undelines_.underlines[0].start_offset: 3 | 276 // underlines_[0].start_offset: 3 |
| 269 // composition_undelines_.underlines[0].end_offset: 6 | 277 // underlines_[0].end_offset: 6 |
| 270 // composition_undelines_.underlines[1].start_offset: 6 | 278 // underlines_[1].start_offset: 6 |
| 271 // composition_undelines_.underlines[1].end_offset: 8 | 279 // underlines_[1].end_offset: 8 |
| 272 CompositionUnderlines composition_undelines_; | 280 std::vector<metro_viewer::UnderlineInfo> underlines_; |
| 273 | 281 |
| 274 // |edit_flag_| indicates that the status is edited during | 282 // |edit_flag_| indicates that the status is edited during |
| 275 // ITextStoreACPSink::OnLockGranted(). | 283 // ITextStoreACPSink::OnLockGranted(). |
| 276 bool edit_flag_; | 284 bool edit_flag_; |
| 277 | 285 |
| 278 // The type of current lock. | 286 // The type of current lock. |
| 279 // 0: No lock. | 287 // 0: No lock. |
| 280 // TS_LF_READ: read-only lock. | 288 // TS_LF_READ: read-only lock. |
| 281 // TS_LF_READWRITE: read/write lock. | 289 // TS_LF_READWRITE: read/write lock. |
| 282 DWORD current_lock_type_; | 290 DWORD current_lock_type_; |
| 283 | 291 |
| 284 // Queue of the lock request used in RequestLock(). | 292 // Queue of the lock request used in RequestLock(). |
| 285 std::deque<DWORD> lock_queue_; | 293 std::deque<DWORD> lock_queue_; |
| 286 | 294 |
| 287 // Category manager and Display attribute manager are used to obtain the | 295 // Category manager and Display attribute manager are used to obtain the |
| 288 // attributes of the composition string. | 296 // attributes of the composition string. |
| 289 base::win::ScopedComPtr<ITfCategoryMgr> category_manager_; | 297 base::win::ScopedComPtr<ITfCategoryMgr> category_manager_; |
| 290 base::win::ScopedComPtr<ITfDisplayAttributeMgr> display_attribute_manager_; | 298 base::win::ScopedComPtr<ITfDisplayAttributeMgr> display_attribute_manager_; |
| 291 | 299 |
| 300 // Represents the context information of this text. |
| 301 base::win::ScopedComPtr<ITfInputScope> input_scope_; |
| 302 |
| 292 DISALLOW_COPY_AND_ASSIGN(TSFTextStore); | 303 DISALLOW_COPY_AND_ASSIGN(TSFTextStore); |
| 293 }; | 304 }; |
| 294 | 305 |
| 295 } // namespace ui | 306 } // namespace metro_driver |
| 296 | 307 |
| 297 #endif // UI_BASE_IME_WIN_TSF_TEXT_STORE_H_ | 308 #endif // WIN8_METRO_DRIVER_IME_TEXT_STORE_H_ |
| OLD | NEW |