Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: media/base/user_input_monitor.h

Issue 23702008: Adds the UserInputMonitor implementation for Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/observer_list.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "media/base/media_export.h" 11 #include "media/base/media_export.h"
12 12
13 struct SkIPoint; 13 struct SkIPoint;
14 14
15 namespace base { 15 namespace base {
16 class SingleThreadTaskRunner; 16 class SingleThreadTaskRunner;
17 } // namespace base 17 } // namespace base
18 18
19 namespace media { 19 namespace media {
20 20
21 // Monitors and notifies about mouse movements and keyboard events. 21 // Monitors and notifies about mouse movements and keyboard events.
22 // Thread safe. The thread on which the listenters are called is not guaranteed. 22 // Thread safe. The listeners are called on the thread where the listeners are
23 // The callers should not perform expensive/blocking tasks in the callback since 23 // added.
24 // it might be called on the browser UI/IO threads.
25 // The object must outlive the browser UI/IO threads to make sure the callbacks
26 // will not access a deleted object.
27 class MEDIA_EXPORT UserInputMonitor { 24 class MEDIA_EXPORT UserInputMonitor {
28 public: 25 public:
29 // The interface to receive mouse movement events. 26 // The interface to receive mouse movement events.
30 class MEDIA_EXPORT MouseEventListener { 27 class MEDIA_EXPORT MouseEventListener {
31 public: 28 public:
32 // |position| is the new mouse position. 29 // |position| is the new mouse position.
33 virtual void OnMouseMoved(const SkIPoint& position) = 0; 30 virtual void OnMouseMoved(const SkIPoint& position) = 0;
34 31
35 protected: 32 protected:
36 virtual ~MouseEventListener() {} 33 virtual ~MouseEventListener() {}
37 }; 34 };
38 35
39 UserInputMonitor(); 36 UserInputMonitor();
40 virtual ~UserInputMonitor(); 37 virtual ~UserInputMonitor();
41 38
42 // Creates a platform-specific instance of UserInputMonitor. 39 // Creates a platform-specific instance of UserInputMonitor.
43 // |io_task_runner| is the task runner for an IO thread. 40 // |io_task_runner| is the task runner for an IO thread.
44 // |ui_task_runner| is the task runner for a UI thread. 41 // |ui_task_runner| is the task runner for a UI thread.
45 static scoped_ptr<UserInputMonitor> Create( 42 static scoped_ptr<UserInputMonitor> Create(
46 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 43 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 44 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
48 45
49 // The same |listener| should only be added once. 46 // The same |listener| should only be added once.
50 // The clients should make sure to call Remove*Listener before |listener| is 47 // The clients should make sure to call Remove*Listener before |listener| is
51 // destroyed. 48 // destroyed.
52 void AddMouseListener(MouseEventListener* listener); 49 virtual void AddMouseListener(MouseEventListener* listener) = 0;
53 void RemoveMouseListener(MouseEventListener* listener); 50 virtual void RemoveMouseListener(MouseEventListener* listener) = 0;
54 51
55 // A caller must call EnableKeyPressMonitoring and 52 // A caller must call EnableKeyPressMonitoring and
56 // DisableKeyPressMonitoring in pair. 53 // DisableKeyPressMonitoring in pair.
57 void EnableKeyPressMonitoring(); 54 void EnableKeyPressMonitoring();
58 void DisableKeyPressMonitoring(); 55 void DisableKeyPressMonitoring();
59 56
60 // Returns the number of keypresses. The starting point from when it is 57 // Returns the number of keypresses. The starting point from when it is
61 // counted is not guaranteed, but consistent within the pair of calls of 58 // counted is not guaranteed, but consistent within the pair of calls of
62 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can 59 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can
63 // use the difference between the values returned at two times to get the 60 // use the difference between the values returned at two times to get the
64 // number of keypresses happened within that time period, but should not make 61 // number of keypresses happened within that time period, but should not make
65 // any assumption on the initial value. 62 // any assumption on the initial value.
66 virtual size_t GetKeyPressCount() const = 0; 63 virtual size_t GetKeyPressCount() const = 0;
67 64
68 protected:
69 // Called by the platform-specific sub-classes to propagate the events to the
70 // listeners.
71 void OnMouseEvent(const SkIPoint& position);
72
73 private: 65 private:
74 virtual void StartMouseMonitoring() = 0;
75 virtual void StopMouseMonitoring() = 0;
76 virtual void StartKeyboardMonitoring() = 0; 66 virtual void StartKeyboardMonitoring() = 0;
77 virtual void StopKeyboardMonitoring() = 0; 67 virtual void StopKeyboardMonitoring() = 0;
78 68
79 base::Lock lock_; 69 base::Lock lock_;
80 ObserverList<MouseEventListener, true> mouse_listeners_;
81 bool monitoring_mouse_;
82 size_t key_press_counter_references_; 70 size_t key_press_counter_references_;
83 71
84 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); 72 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor);
85 }; 73 };
86 74
87 } // namespace media 75 } // namespace media
88 76
89 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ 77 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698