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

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
« no previous file with comments | « media/base/keyboard_event_counter.h ('k') | media/base/user_input_monitor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/observer_list_threadsafe.h"
10 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
11 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
12 13
13 struct SkIPoint; 14 struct SkIPoint;
14 15
15 namespace base { 16 namespace base {
16 class SingleThreadTaskRunner; 17 class SingleThreadTaskRunner;
17 } // namespace base 18 } // namespace base
18 19
19 namespace media { 20 namespace media {
20 21
21 // Monitors and notifies about mouse movements and keyboard events. 22 // Monitors and notifies about mouse movements and keyboard events.
22 // Thread safe. The thread on which the listenters are called is not guaranteed. 23 // 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 24 // 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 { 25 class MEDIA_EXPORT UserInputMonitor {
28 public: 26 public:
29 // The interface to receive mouse movement events. 27 // The interface to receive mouse movement events.
30 class MEDIA_EXPORT MouseEventListener { 28 class MEDIA_EXPORT MouseEventListener {
31 public: 29 public:
32 // |position| is the new mouse position. 30 // |position| is the new mouse position.
33 virtual void OnMouseMoved(const SkIPoint& position) = 0; 31 virtual void OnMouseMoved(const SkIPoint& position) = 0;
34 32
35 protected: 33 protected:
36 virtual ~MouseEventListener() {} 34 virtual ~MouseEventListener() {}
37 }; 35 };
36 typedef ObserverListThreadSafe<UserInputMonitor::MouseEventListener>
37 MouseListenerList;
38 38
39 UserInputMonitor(); 39 UserInputMonitor();
40 virtual ~UserInputMonitor(); 40 virtual ~UserInputMonitor();
41 41
42 // Creates a platform-specific instance of UserInputMonitor. 42 // Creates a platform-specific instance of UserInputMonitor.
43 // |io_task_runner| is the task runner for an IO thread. 43 // |io_task_runner| is the task runner for an IO thread.
44 // |ui_task_runner| is the task runner for a UI thread. 44 // |ui_task_runner| is the task runner for a UI thread.
45 static scoped_ptr<UserInputMonitor> Create( 45 static scoped_ptr<UserInputMonitor> Create(
46 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 46 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
(...skipping 11 matching lines...) Expand all
59 59
60 // Returns the number of keypresses. The starting point from when it is 60 // 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 61 // counted is not guaranteed, but consistent within the pair of calls of
62 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can 62 // EnableKeyPressMonitoring and DisableKeyPressMonitoring. So a caller can
63 // use the difference between the values returned at two times to get the 63 // 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 64 // number of keypresses happened within that time period, but should not make
65 // any assumption on the initial value. 65 // any assumption on the initial value.
66 virtual size_t GetKeyPressCount() const = 0; 66 virtual size_t GetKeyPressCount() const = 0;
67 67
68 protected: 68 protected:
69 // Called by the platform-specific sub-classes to propagate the events to the 69 scoped_refptr<MouseListenerList> mouse_listeners() {
70 // listeners. 70 return mouse_listeners_;
71 void OnMouseEvent(const SkIPoint& position); 71 }
72 72
73 private: 73 private:
74 virtual void StartKeyboardMonitoring() = 0;
75 virtual void StopKeyboardMonitoring() = 0;
74 virtual void StartMouseMonitoring() = 0; 76 virtual void StartMouseMonitoring() = 0;
75 virtual void StopMouseMonitoring() = 0; 77 virtual void StopMouseMonitoring() = 0;
76 virtual void StartKeyboardMonitoring() = 0;
77 virtual void StopKeyboardMonitoring() = 0;
78 78
79 base::Lock lock_; 79 base::Lock lock_;
80 ObserverList<MouseEventListener, true> mouse_listeners_;
81 bool monitoring_mouse_;
82 size_t key_press_counter_references_; 80 size_t key_press_counter_references_;
81 size_t mouse_listeners_count_;
82 scoped_refptr<MouseListenerList> mouse_listeners_;
83 83
84 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); 84 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor);
85 }; 85 };
86 86
87 } // namespace media 87 } // namespace media
88 88
89 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ 89 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_
OLDNEW
« no previous file with comments | « media/base/keyboard_event_counter.h ('k') | media/base/user_input_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698