Chromium Code Reviews| 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 <set> | |
| 9 | |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/containers/hash_tables.h" | |
| 10 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 11 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 12 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 13 #include "ui/events/ozone/device/device_event_observer.h" | 16 #include "ui/events/ozone/device/device_event_observer.h" |
| 14 #include "ui/events/ozone/evdev/event_converter_evdev.h" | 17 #include "ui/events/ozone/evdev/event_converter_evdev.h" |
| 15 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" | 18 #include "ui/events/ozone/evdev/event_modifiers_evdev.h" |
| 16 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" | 19 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h" |
| 17 #include "ui/events/platform/platform_event_source.h" | 20 #include "ui/events/platform/platform_event_source.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
| 19 | 22 |
| 20 namespace gfx { | 23 namespace gfx { |
| 21 class PointF; | 24 class PointF; |
| 22 } // namespace gfx | 25 } // namespace gfx |
| 23 | 26 |
| 24 namespace ui { | 27 namespace ui { |
| 25 | 28 |
| 26 class CursorDelegateEvdev; | 29 class CursorDelegateEvdev; |
| 27 class DeviceManager; | 30 class DeviceManager; |
| 28 | 31 |
| 32 #if defined(USE_EVDEV_GESTURES) | |
| 33 class GesturePropertyProvider; | |
| 34 #endif | |
| 35 | |
| 29 // Ozone events implementation for the Linux input subsystem ("evdev"). | 36 // Ozone events implementation for the Linux input subsystem ("evdev"). |
| 30 class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver, | 37 class EVENTS_OZONE_EVDEV_EXPORT EventFactoryEvdev : public DeviceEventObserver, |
| 31 public PlatformEventSource { | 38 public PlatformEventSource { |
| 32 public: | 39 public: |
| 33 EventFactoryEvdev(CursorDelegateEvdev* cursor, | 40 EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 34 DeviceManager* device_manager); | 41 DeviceManager* device_manager); |
| 35 virtual ~EventFactoryEvdev(); | 42 virtual ~EventFactoryEvdev(); |
| 36 | 43 |
| 37 void DispatchUiEvent(Event* event); | 44 void DispatchUiEvent(Event* event); |
| 38 | 45 |
| 39 void WarpCursorTo(gfx::AcceleratedWidget widget, | 46 void WarpCursorTo(gfx::AcceleratedWidget widget, |
| 40 const gfx::PointF& location); | 47 const gfx::PointF& location); |
| 41 | 48 |
| 42 private: | 49 private: |
| 50 // Mapping table from a device path to its device id. | |
| 51 typedef base::hash_map<base::FilePath, int> DeviceIdMap; | |
| 52 | |
| 43 // Open device at path & starting processing events (on UI thread). | 53 // Open device at path & starting processing events (on UI thread). |
| 44 void AttachInputDevice(scoped_ptr<EventConverterEvdev> converter); | 54 void AttachInputDevice(scoped_ptr<EventConverterEvdev> converter); |
| 45 | 55 |
| 46 // Close device at path (on UI thread). | 56 // Close device at path (on UI thread). |
| 47 void DetachInputDevice(const base::FilePath& file_path); | 57 void DetachInputDevice(const base::FilePath& file_path); |
| 48 | 58 |
| 49 void NotifyHotplugEventObserver(const EventConverterEvdev& converter); | 59 void NotifyHotplugEventObserver(const EventConverterEvdev& converter); |
| 50 | 60 |
| 51 int NextDeviceId(); | 61 int GenerateDeviceId(const base::FilePath& file_path); |
| 62 | |
| 63 void RevokeDeviceId(const base::FilePath& file_path); | |
| 52 | 64 |
| 53 // DeviceEventObserver overrides: | 65 // DeviceEventObserver overrides: |
| 54 // | 66 // |
| 55 // Callback for device add (on UI thread). | 67 // Callback for device add (on UI thread). |
| 56 virtual void OnDeviceEvent(const DeviceEvent& event) override; | 68 virtual void OnDeviceEvent(const DeviceEvent& event) override; |
| 57 | 69 |
| 58 // PlatformEventSource: | 70 // PlatformEventSource: |
| 59 virtual void OnDispatcherListChanged() override; | 71 virtual void OnDispatcherListChanged() override; |
| 60 | 72 |
| 61 // Owned per-device event converters (by path). | 73 // Owned per-device event converters (by path). |
| 62 std::map<base::FilePath, EventConverterEvdev*> converters_; | 74 std::map<base::FilePath, EventConverterEvdev*> converters_; |
| 63 | 75 |
| 64 // Used to uniquely identify input devices. | 76 // An incremental counter of the next device id to be used for mapping. Used |
| 65 int last_device_id_; | 77 // to uniquely identify input devices. |
| 78 int device_id_counter_; | |
| 79 | |
| 80 // A set of all currently used device ids. | |
| 81 std::set<int> used_device_ids_; | |
| 82 | |
| 83 // Map from device paths to device ids. | |
| 84 DeviceIdMap device_ids_map_; | |
|
spang
2014/10/15 11:36:41
What is this for? I don't think you need it.
Shecky Lin
2014/10/16 04:53:53
Done.
| |
| 66 | 85 |
| 67 // Interface for scanning & monitoring input devices. | 86 // Interface for scanning & monitoring input devices. |
| 68 DeviceManager* device_manager_; // Not owned. | 87 DeviceManager* device_manager_; // Not owned. |
| 69 | 88 |
| 70 // Task runner for event dispatch. | 89 // Task runner for event dispatch. |
| 71 scoped_refptr<base::TaskRunner> ui_task_runner_; | 90 scoped_refptr<base::TaskRunner> ui_task_runner_; |
| 72 | 91 |
| 73 // Modifier key state (shift, ctrl, etc). | 92 // Modifier key state (shift, ctrl, etc). |
| 74 EventModifiersEvdev modifiers_; | 93 EventModifiersEvdev modifiers_; |
| 75 | 94 |
| 76 // Cursor movement. | 95 // Cursor movement. |
| 77 CursorDelegateEvdev* cursor_; | 96 CursorDelegateEvdev* cursor_; |
| 78 | 97 |
| 98 #if defined(USE_EVDEV_GESTURES) | |
| 99 // Gesture library property provider (used by touchpads/mice). | |
| 100 scoped_ptr<GesturePropertyProvider> gesture_property_provider_; | |
| 101 #endif | |
| 102 | |
| 79 // Dispatch callback for events. | 103 // Dispatch callback for events. |
| 80 EventDispatchCallback dispatch_callback_; | 104 EventDispatchCallback dispatch_callback_; |
| 81 | 105 |
| 82 // Support weak pointers for attach & detach callbacks. | 106 // Support weak pointers for attach & detach callbacks. |
| 83 base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_; | 107 base::WeakPtrFactory<EventFactoryEvdev> weak_ptr_factory_; |
| 84 | 108 |
| 85 DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev); | 109 DISALLOW_COPY_AND_ASSIGN(EventFactoryEvdev); |
| 86 }; | 110 }; |
| 87 | 111 |
| 88 } // namespace ui | 112 } // namespace ui |
| 89 | 113 |
| 90 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ | 114 #endif // UI_EVENTS_OZONE_EVDEV_EVENT_FACTORY_EVDEV_H_ |
| OLD | NEW |