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

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

Issue 21183002: Adding key press detection in the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_BASE_USER_INPUT_MONITOR_H_
6 #define MEDIA_BASE_USER_INPUT_MONITOR_H_
7
8 #include <set>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "ui/base/events/event_constants.h"
15 #include "ui/base/keycodes/keyboard_codes.h"
16
17 struct SkIPoint;
18
19 namespace base {
20 class SingleThreadTaskRunner;
21 } // namespace base
22
23 namespace media {
24
25 class MouseEventListener {
DaleCurtis 2013/08/10 00:13:12 Should this be RawMouseEventListener then?
jiayl 2013/08/10 00:37:56 I don't feel strong about it, but there is no un-r
Sergey Ulanov 2013/08/10 00:48:19 please add comments for this interface and the one
26 public:
27 virtual void OnMouseMoved(const SkIPoint& position) = 0;
28
29 protected:
30 virtual ~MouseEventListener() {}
31 };
32
33 class RawKeyboardEventListener {
34 public:
35 virtual void OnKeyboardEvent(ui::EventType event,
36 ui::KeyboardCode key_code) = 0;
37
38 protected:
39 virtual ~RawKeyboardEventListener() {}
40 };
41
42 class KeyPressListener {
Sergey Ulanov 2013/08/10 00:48:19 Why do we need this given that there is RawKeyboar
43 public:
44 virtual void OnKeyPressed() = 0;
45
46 protected:
47 virtual ~KeyPressListener() {}
48 };
49
50 // Monitors and notifies about mouse movements and keyboard events.
51 // Not thread safe. Can be created/destroyed on any thread, but all public
52 // methods except Create must be called on one thread and the listeners are
53 // called back on the same thread.
54 class UserInputMonitor {
55 public:
56 virtual ~UserInputMonitor();
57
58 // Creates a platform-specific instance of UserInputMonitor.
59 // |input_task_runner| is the task runner for an IO thread.
DaleCurtis 2013/08/10 00:13:12 io_task_runner ?
60 // |ui_task_runner| is the task runner for a UI thread.
61 // |observer_task_runner| is the task runner to run callbacks to the
62 // |observer|.
63 static scoped_ptr<UserInputMonitor> Create(
64 const scoped_refptr<base::SingleThreadTaskRunner>& input_task_runner,
65 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
66
67 // These methods must be called on the thread on which the listeners are
68 // expected to be called.
69 void AddMouseListener(MouseEventListener* listener);
70 void RemoveMouseListener(MouseEventListener* listener);
71 void AddRawKeyboardListener(RawKeyboardEventListener* listener);
72 void RemoveRawKeyboardListener(RawKeyboardEventListener* listener);
73 void AddKeyPressListener(KeyPressListener* listener);
74 void RemoveKeyPressListener(KeyPressListener* listener);
75
76 protected:
77 UserInputMonitor();
78
79 // Called by the platform-specific sub-classes on the same thread on which
80 // the StartMonitor methods are called.
81 void OnMouseEvent(const SkIPoint& position);
82 void OnKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code);
83
84 private:
85 virtual void StartMonitorMouse() = 0;
DaleCurtis 2013/08/10 00:13:12 StartMouseMonitoring, StopMouseMonitoring, etc for
86 virtual void StopMonitorMouse() = 0;
87 virtual void StartMonitorKeyboard() = 0;
88 virtual void StopMonitorKeyboard() = 0;
89
90 ObserverList<MouseEventListener, true> mouse_listeners_;
91 ObserverList<RawKeyboardEventListener, true> keyboard_listeners_;
92 ObserverList<KeyPressListener, true> key_press_listeners_;
93 // The set of keys currently held down.
94 std::set<ui::KeyboardCode> pressed_keys_;
95
96 DISALLOW_COPY_AND_ASSIGN(UserInputMonitor);
97 };
98
99 } // namespace media
100
101 #endif // MEDIA_BASE_USER_INPUT_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698