Index: media/base/user_input_monitor.h |
diff --git a/media/base/user_input_monitor.h b/media/base/user_input_monitor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9890ef0f1749fd8f779f01305b76f618d191cda3 |
--- /dev/null |
+++ b/media/base/user_input_monitor.h |
@@ -0,0 +1,101 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BASE_USER_INPUT_MONITOR_H_ |
+#define MEDIA_BASE_USER_INPUT_MONITOR_H_ |
+ |
+#include <set> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/observer_list.h" |
+#include "ui/base/events/event_constants.h" |
+#include "ui/base/keycodes/keyboard_codes.h" |
+ |
+struct SkIPoint; |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
+} // namespace base |
+ |
+namespace media { |
+ |
+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
|
+ public: |
+ virtual void OnMouseMoved(const SkIPoint& position) = 0; |
+ |
+ protected: |
+ virtual ~MouseEventListener() {} |
+}; |
+ |
+class RawKeyboardEventListener { |
+ public: |
+ virtual void OnKeyboardEvent(ui::EventType event, |
+ ui::KeyboardCode key_code) = 0; |
+ |
+ protected: |
+ virtual ~RawKeyboardEventListener() {} |
+}; |
+ |
+class KeyPressListener { |
Sergey Ulanov
2013/08/10 00:48:19
Why do we need this given that there is RawKeyboar
|
+ public: |
+ virtual void OnKeyPressed() = 0; |
+ |
+ protected: |
+ virtual ~KeyPressListener() {} |
+}; |
+ |
+// Monitors and notifies about mouse movements and keyboard events. |
+// Not thread safe. Can be created/destroyed on any thread, but all public |
+// methods except Create must be called on one thread and the listeners are |
+// called back on the same thread. |
+class UserInputMonitor { |
+ public: |
+ virtual ~UserInputMonitor(); |
+ |
+ // Creates a platform-specific instance of UserInputMonitor. |
+ // |input_task_runner| is the task runner for an IO thread. |
DaleCurtis
2013/08/10 00:13:12
io_task_runner ?
|
+ // |ui_task_runner| is the task runner for a UI thread. |
+ // |observer_task_runner| is the task runner to run callbacks to the |
+ // |observer|. |
+ static scoped_ptr<UserInputMonitor> Create( |
+ const scoped_refptr<base::SingleThreadTaskRunner>& input_task_runner, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); |
+ |
+ // These methods must be called on the thread on which the listeners are |
+ // expected to be called. |
+ void AddMouseListener(MouseEventListener* listener); |
+ void RemoveMouseListener(MouseEventListener* listener); |
+ void AddRawKeyboardListener(RawKeyboardEventListener* listener); |
+ void RemoveRawKeyboardListener(RawKeyboardEventListener* listener); |
+ void AddKeyPressListener(KeyPressListener* listener); |
+ void RemoveKeyPressListener(KeyPressListener* listener); |
+ |
+ protected: |
+ UserInputMonitor(); |
+ |
+ // Called by the platform-specific sub-classes on the same thread on which |
+ // the StartMonitor methods are called. |
+ void OnMouseEvent(const SkIPoint& position); |
+ void OnKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code); |
+ |
+ private: |
+ virtual void StartMonitorMouse() = 0; |
DaleCurtis
2013/08/10 00:13:12
StartMouseMonitoring, StopMouseMonitoring, etc for
|
+ virtual void StopMonitorMouse() = 0; |
+ virtual void StartMonitorKeyboard() = 0; |
+ virtual void StopMonitorKeyboard() = 0; |
+ |
+ ObserverList<MouseEventListener, true> mouse_listeners_; |
+ ObserverList<RawKeyboardEventListener, true> keyboard_listeners_; |
+ ObserverList<KeyPressListener, true> key_press_listeners_; |
+ // The set of keys currently held down. |
+ std::set<ui::KeyboardCode> pressed_keys_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(UserInputMonitor); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_USER_INPUT_MONITOR_H_ |