| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MEDIA_BASE_USER_INPUT_MONITOR_H_ | 5 #ifndef MEDIA_BASE_USER_INPUT_MONITOR_H_ |
| 6 #define MEDIA_BASE_USER_INPUT_MONITOR_H_ | 6 #define MEDIA_BASE_USER_INPUT_MONITOR_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/observer_list_threadsafe.h" | |
| 15 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 16 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 17 | 16 |
| 18 struct SkIPoint; | |
| 19 | |
| 20 namespace base { | 17 namespace base { |
| 21 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
| 22 } // namespace base | 19 } // namespace base |
| 23 | 20 |
| 24 namespace media { | 21 namespace media { |
| 25 | 22 |
| 26 // Monitors and notifies about mouse movements and keyboard events. | 23 // Monitors and notifies about keyboard events. |
| 27 // Thread safe. The listeners are called on the thread where the listeners are | 24 // Thread safe. |
| 28 // added. | |
| 29 class MEDIA_EXPORT UserInputMonitor { | 25 class MEDIA_EXPORT UserInputMonitor { |
| 30 public: | 26 public: |
| 31 // The interface to receive mouse movement events. | |
| 32 class MEDIA_EXPORT MouseEventListener { | |
| 33 public: | |
| 34 // |position| is the new mouse position. | |
| 35 virtual void OnMouseMoved(const SkIPoint& position) = 0; | |
| 36 | |
| 37 protected: | |
| 38 virtual ~MouseEventListener() {} | |
| 39 }; | |
| 40 typedef base::ObserverListThreadSafe<UserInputMonitor::MouseEventListener> | |
| 41 MouseListenerList; | |
| 42 | |
| 43 UserInputMonitor(); | 27 UserInputMonitor(); |
| 44 virtual ~UserInputMonitor(); | 28 virtual ~UserInputMonitor(); |
| 45 | 29 |
| 46 // Creates a platform-specific instance of UserInputMonitor. | 30 // Creates a platform-specific instance of UserInputMonitor. |
| 47 // |io_task_runner| is the task runner for an IO thread. | 31 // |io_task_runner| is the task runner for an IO thread. |
| 48 // |ui_task_runner| is the task runner for a UI thread. | 32 // |ui_task_runner| is the task runner for a UI thread. |
| 49 static std::unique_ptr<UserInputMonitor> Create( | 33 static std::unique_ptr<UserInputMonitor> Create( |
| 50 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 34 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); | 35 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); |
| 52 | 36 |
| 53 // The same |listener| should only be added once. | |
| 54 // The clients should make sure to call Remove*Listener before |listener| is | |
| 55 // destroyed. | |
| 56 void AddMouseListener(MouseEventListener* listener); | |
| 57 void RemoveMouseListener(MouseEventListener* listener); | |
| 58 | |
| 59 // A caller must call EnableKeyPressMonitoring and | 37 // A caller must call EnableKeyPressMonitoring and |
| 60 // DisableKeyPressMonitoring in pair. | 38 // DisableKeyPressMonitoring in pair. |
| 61 void EnableKeyPressMonitoring(); | 39 void EnableKeyPressMonitoring(); |
| 62 void DisableKeyPressMonitoring(); | 40 void DisableKeyPressMonitoring(); |
| 63 | 41 |
| 64 // Returns the number of keypresses. The starting point from when it is | 42 // Returns the number of keypresses. The starting point from when it is |
| 65 // counted is not guaranteed, but consistent within the pair of calls of | 43 // counted is not guaranteed, but consistent within the pair of calls of |
| 66 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can | 44 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can |
| 67 // use the difference between the values returned at two times to get the | 45 // use the difference between the values returned at two times to get the |
| 68 // number of keypresses happened within that time period, but should not make | 46 // number of keypresses happened within that time period, but should not make |
| 69 // any assumption on the initial value. | 47 // any assumption on the initial value. |
| 70 virtual size_t GetKeyPressCount() const = 0; | 48 virtual size_t GetKeyPressCount() const = 0; |
| 71 | 49 |
| 72 protected: | |
| 73 scoped_refptr<MouseListenerList> mouse_listeners() { | |
| 74 return mouse_listeners_; | |
| 75 } | |
| 76 | |
| 77 private: | 50 private: |
| 78 virtual void StartKeyboardMonitoring() = 0; | 51 virtual void StartKeyboardMonitoring() = 0; |
| 79 virtual void StopKeyboardMonitoring() = 0; | 52 virtual void StopKeyboardMonitoring() = 0; |
| 80 virtual void StartMouseMonitoring() = 0; | |
| 81 virtual void StopMouseMonitoring() = 0; | |
| 82 | 53 |
| 83 base::Lock lock_; | 54 base::Lock lock_; |
| 84 size_t key_press_counter_references_; | 55 size_t key_press_counter_references_; |
| 85 size_t mouse_listeners_count_; | |
| 86 scoped_refptr<MouseListenerList> mouse_listeners_; | |
| 87 | 56 |
| 88 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); | 57 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); |
| 89 }; | 58 }; |
| 90 | 59 |
| 91 } // namespace media | 60 } // namespace media |
| 92 | 61 |
| 93 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ | 62 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ |
| OLD | NEW |