| 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_EVENT_ROUTER_H_ | 5 #ifndef UI_BASE_IME_WIN_TSF_EVENT_ROUTER_H_ |
| 6 #define UI_BASE_IME_WIN_TSF_EVENT_ROUTER_H_ | 6 #define UI_BASE_IME_WIN_TSF_EVENT_ROUTER_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> |
| 9 #include <atlcom.h> |
| 8 #include <msctf.h> | 10 #include <msctf.h> |
| 9 | 11 |
| 12 #include <set> |
| 13 |
| 10 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 15 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 13 #include "ui/base/ime/text_input_type.h" | 17 #include "ui/base/ime/text_input_type.h" |
| 14 #include "ui/base/ui_export.h" | 18 #include "ui/base/ui_export.h" |
| 15 | 19 |
| 16 struct ITfDocumentMgr; | 20 struct ITfDocumentMgr; |
| 17 | 21 |
| 18 namespace ui { | 22 namespace ui { |
| 19 | 23 |
| 20 // This is an abstract interface that monitors events associated with TSF and | 24 class TsfEventRouterObserver { |
| 21 // forwards them to the observer. In order to manage the life cycle of this | |
| 22 // object by scoped_refptr and the implementation class of this interface is COM | |
| 23 // class anyway, this interface is derived from IUnknown. | |
| 24 class TsfEventRouter : public IUnknown { | |
| 25 public: | 25 public: |
| 26 class Observer { | 26 TsfEventRouterObserver() {} |
| 27 public: | |
| 28 virtual ~Observer() {} | |
| 29 | 27 |
| 30 // Called when the text contents are updated. | 28 // Called when the text contents are updated. |
| 31 virtual void OnTextUpdated() = 0; | 29 virtual void OnTextUpdated() = 0; |
| 32 | 30 |
| 33 // Called when the number of currently opened candidate windows changes. | 31 // Called when the number of currently opened candidate windows changes. |
| 34 virtual void OnCandidateWindowCountChanged(size_t window_count) = 0; | 32 virtual void OnCandidateWindowCountChanged(size_t window_count) = 0; |
| 35 }; | |
| 36 | 33 |
| 34 protected: |
| 35 virtual ~TsfEventRouterObserver() {} |
| 36 |
| 37 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(TsfEventRouterObserver); |
| 39 }; |
| 40 |
| 41 // This class monitores TSF related events and forwards them to given |
| 42 // |observer|. |
| 43 class UI_EXPORT TsfEventRouter { |
| 44 public: |
| 45 // Do not pass NULL to |observer|. |
| 46 explicit TsfEventRouter(TsfEventRouterObserver* observer); |
| 37 virtual ~TsfEventRouter(); | 47 virtual ~TsfEventRouter(); |
| 38 | 48 |
| 39 // Sets |manager| to be monitored and |observer| to be notified. |manager| and | 49 // Sets |thread_manager| to be monitored. |thread_manager| can be NULL. |
| 40 // |observer| can be NULL. | 50 void SetManager(ITfThreadMgr* thread_manager); |
| 41 virtual void SetManager(ITfThreadMgr* manager, | |
| 42 Observer* observer) = 0; | |
| 43 | 51 |
| 44 // Returns true if the IME is composing texts. | 52 // Returns true if the IME is composing text. |
| 45 virtual bool IsImeComposing() = 0; | 53 bool IsImeComposing(); |
| 46 | 54 |
| 47 // Factory function, creates a new instance which the caller owns. | 55 // Callbacks from the TsfEventRouterDelegate: |
| 48 static UI_EXPORT TsfEventRouter* Create(); | 56 void OnTextUpdated(); |
| 57 void OnCandidateWindowCountChanged(size_t window_count); |
| 49 | 58 |
| 50 protected: | 59 private: |
| 51 // Create should be used instead. | 60 class TsfEventRouterDelegate; |
| 52 TsfEventRouter(); | 61 |
| 62 CComPtr<TsfEventRouterDelegate> delegate_; |
| 63 |
| 64 TsfEventRouterObserver* observer_; |
| 53 | 65 |
| 54 DISALLOW_COPY_AND_ASSIGN(TsfEventRouter); | 66 DISALLOW_COPY_AND_ASSIGN(TsfEventRouter); |
| 55 }; | 67 }; |
| 56 | 68 |
| 57 } // namespace ui | 69 } // namespace ui |
| 58 | 70 |
| 59 #endif // UI_BASE_IME_WIN_TSF_EVENT_ROUTER_H_ | 71 #endif // UI_BASE_IME_WIN_TSF_EVENT_ROUTER_H_ |
| OLD | NEW |