OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ | 5 #ifndef UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ |
6 #define UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ | 6 #define UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
13 #include "ui/events/events_export.h" | 13 #include "ui/events/events_export.h" |
| 14 #include "ui/events/ozone/device/device_event_observer.h" |
14 #include "ui/events/ozone/evdev/event_converter_evdev.h" | 15 #include "ui/events/ozone/evdev/event_converter_evdev.h" |
15 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" | 16 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" |
16 #include "ui/events/ozone/event_factory_ozone.h" | 17 #include "ui/events/ozone/event_factory_ozone.h" |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 | 20 |
20 class CursorDelegateEvdev; | 21 class CursorDelegateEvdev; |
21 class DeviceManagerEvdev; | 22 class DeviceManager; |
22 | 23 |
23 // Ozone events implementation for the Linux input subsystem ("evdev"). | 24 // Ozone events implementation for the Linux input subsystem ("evdev"). |
24 class EVENTS_EXPORT EventFactoryEvdev : public EventFactoryOzone { | 25 class EVENTS_EXPORT EventFactoryEvdev |
| 26 : public EventFactoryOzone, DeviceEventObserver { |
25 public: | 27 public: |
26 EventFactoryEvdev(); | 28 EventFactoryEvdev(); |
27 explicit EventFactoryEvdev(CursorDelegateEvdev* cursor); | 29 EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 30 DeviceManager* device_manager); |
28 virtual ~EventFactoryEvdev(); | 31 virtual ~EventFactoryEvdev(); |
29 | 32 |
30 void DispatchUiEvent(Event* event); | 33 void DispatchUiEvent(Event* event); |
31 | 34 |
32 // EventFactoryOzone: | 35 // EventFactoryOzone: |
33 virtual void StartProcessingEvents() OVERRIDE; | 36 virtual void StartProcessingEvents() OVERRIDE; |
34 virtual void SetFileTaskRunner(scoped_refptr<base::TaskRunner> task_runner) | 37 virtual void SetFileTaskRunner(scoped_refptr<base::TaskRunner> task_runner) |
35 OVERRIDE; | 38 OVERRIDE; |
36 virtual void WarpCursorTo(gfx::AcceleratedWidget widget, | 39 virtual void WarpCursorTo(gfx::AcceleratedWidget widget, |
37 const gfx::PointF& location) OVERRIDE; | 40 const gfx::PointF& location) OVERRIDE; |
38 | 41 |
39 private: | 42 private: |
40 // Open device at path & starting processing events (on UI thread). | 43 // Open device at path & starting processing events (on UI thread). |
41 void AttachInputDevice(const base::FilePath& file_path, | 44 void AttachInputDevice(const base::FilePath& file_path, |
42 scoped_ptr<EventConverterEvdev> converter); | 45 scoped_ptr<EventConverterEvdev> converter); |
43 | 46 |
44 // Close device at path (on UI thread). | 47 // Close device at path (on UI thread). |
45 void DetachInputDevice(const base::FilePath& file_path); | 48 void DetachInputDevice(const base::FilePath& file_path); |
46 | 49 |
| 50 // DeviceEventObserver overrides: |
| 51 // |
47 // Callback for device add (on UI thread). | 52 // Callback for device add (on UI thread). |
48 void OnDeviceAdded(const base::FilePath& path); | 53 virtual void OnDeviceEvent(const DeviceEvent& event) OVERRIDE; |
49 | |
50 // Callback for device remove (on UI thread). | |
51 void OnDeviceRemoved(const base::FilePath& path); | |
52 | 54 |
53 // Owned per-device event converters (by path). | 55 // Owned per-device event converters (by path). |
54 std::map<base::FilePath, EventConverterEvdev*> converters_; | 56 std::map<base::FilePath, EventConverterEvdev*> converters_; |
55 | 57 |
56 // Interface for scanning & monitoring input devices. | 58 // Interface for scanning & monitoring input devices. |
57 scoped_ptr<DeviceManagerEvdev> device_manager_; | 59 DeviceManager* device_manager_; // Not owned. |
| 60 |
| 61 // True if this was registered with |device_manager_|. This is needed since |
| 62 // StartProcessingEvents() is called multiple times (when a |
| 63 // WindowTreeHostOzone is created) but we shouldn't register this multiple |
| 64 // times. |
| 65 // TODO(dnicoara) Remove once event processing is refactored and we no longer |
| 66 // rely on WTH for starting event processing. |
| 67 bool has_started_processing_events_; |
58 | 68 |
59 // Task runner for event dispatch. | 69 // Task runner for event dispatch. |
60 scoped_refptr<base::TaskRunner> ui_task_runner_; | 70 scoped_refptr<base::TaskRunner> ui_task_runner_; |
61 | 71 |
62 // Task runner for file I/O. | 72 // Task runner for file I/O. |
63 scoped_refptr<base::TaskRunner> file_task_runner_; | 73 scoped_refptr<base::TaskRunner> file_task_runner_; |
64 | 74 |
65 // Modifier key state (shift, ctrl, etc). | 75 // Modifier key state (shift, ctrl, etc). |
66 EventModifiersEvdev modifiers_; | 76 EventModifiersEvdev modifiers_; |
67 | 77 |
68 // Cursor movement. | 78 // Cursor movement. |
69 CursorDelegateEvdev* cursor_; | 79 CursorDelegateEvdev* cursor_; |
70 | 80 |
71 // Dispatch callback for events. | 81 // Dispatch callback for events. |
72 EventDispatchCallback dispatch_callback_; | 82 EventDispatchCallback dispatch_callback_; |
73 | 83 |
74 // Support weak pointers for attach & detach callbacks. | 84 // Support weak pointers for attach & detach callbacks. |
75 base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_; | 85 base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_; |
76 | 86 |
77 DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev); | 87 DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev); |
78 }; | 88 }; |
79 | 89 |
80 } // namespace ui | 90 } // namespace ui |
81 | 91 |
82 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ | 92 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ |
OLD | NEW |