Chromium Code Reviews| 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. The listeners are called on the thread where the listeners are |
| 28 // added. | 25 // added. |
|
Wez
2017/01/03 23:59:40
nit: Remove the comment about listeners, since the
CJ
2017/01/07 00:12:35
Done.
Wez
2017/01/09 22:38:43
nit: We still need the note about being thread-saf
CJ
2017/01/09 23:35:49
Done.
| |
| 29 class MEDIA_EXPORT UserInputMonitor { | 26 class MEDIA_EXPORT UserInputMonitor { |
| 30 public: | 27 public: |
| 31 // The interface to receive mouse movement events. | 28 UserInputMonitor() : key_press_counter_references_(0) {} |
| 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(); | |
| 44 virtual ~UserInputMonitor(); | 29 virtual ~UserInputMonitor(); |
| 45 | 30 |
| 46 // Creates a platform-specific instance of UserInputMonitor. | 31 // Creates a platform-specific instance of UserInputMonitor. |
| 47 // |io_task_runner| is the task runner for an IO thread. | 32 // |io_task_runner| is the task runner for an IO thread. |
| 48 // |ui_task_runner| is the task runner for a UI thread. | 33 // |ui_task_runner| is the task runner for a UI thread. |
| 49 static std::unique_ptr<UserInputMonitor> Create( | 34 static std::unique_ptr<UserInputMonitor> Create( |
| 50 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 35 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); | 36 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); |
| 52 | 37 |
| 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 | 38 // A caller must call EnableKeyPressMonitoring and |
| 60 // DisableKeyPressMonitoring in pair. | 39 // DisableKeyPressMonitoring in pair. |
| 61 void EnableKeyPressMonitoring(); | 40 void EnableKeyPressMonitoring(); |
| 62 void DisableKeyPressMonitoring(); | 41 void DisableKeyPressMonitoring(); |
| 63 | 42 |
| 64 // Returns the number of keypresses. The starting point from when it is | 43 // 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 | 44 // counted is not guaranteed, but consistent within the pair of calls of |
| 66 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can | 45 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can |
| 67 // use the difference between the values returned at two times to get the | 46 // 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 | 47 // number of keypresses happened within that time period, but should not make |
| 69 // any assumption on the initial value. | 48 // any assumption on the initial value. |
| 70 virtual size_t GetKeyPressCount() const = 0; | 49 virtual size_t GetKeyPressCount() const = 0; |
| 71 | 50 |
| 72 protected: | |
| 73 scoped_refptr<MouseListenerList> mouse_listeners() { | |
| 74 return mouse_listeners_; | |
| 75 } | |
| 76 | |
| 77 private: | 51 private: |
| 78 virtual void StartKeyboardMonitoring() = 0; | 52 virtual void StartKeyboardMonitoring() = 0; |
| 79 virtual void StopKeyboardMonitoring() = 0; | 53 virtual void StopKeyboardMonitoring() = 0; |
| 80 virtual void StartMouseMonitoring() = 0; | |
| 81 virtual void StopMouseMonitoring() = 0; | |
| 82 | 54 |
| 83 base::Lock lock_; | 55 base::Lock lock_; |
| 84 size_t key_press_counter_references_; | 56 size_t key_press_counter_references_; |
| 85 size_t mouse_listeners_count_; | |
| 86 scoped_refptr<MouseListenerList> mouse_listeners_; | |
| 87 | 57 |
| 88 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); | 58 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); |
| 89 }; | 59 }; |
| 90 | 60 |
| 91 } // namespace media | 61 } // namespace media |
| 92 | 62 |
| 93 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ | 63 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ |
| OLD | NEW |