| 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 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 5 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <linux/input.h> | 8 #include <linux/input.h> |
| 9 | 9 |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
| 15 #include "ui/events/device_data_manager.h" | 15 #include "ui/events/device_data_manager.h" |
| 16 #include "ui/events/ozone/device/device_event.h" | 16 #include "ui/events/ozone/device/device_event.h" |
| 17 #include "ui/events/ozone/device/device_manager.h" | 17 #include "ui/events/ozone/device/device_manager.h" |
| 18 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 18 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 19 #include "ui/events/ozone/evdev/event_device_info.h" | 19 #include "ui/events/ozone/evdev/event_device_info.h" |
| 20 #include "ui/events/ozone/evdev/key_event_converter_evdev.h" | 20 #include "ui/events/ozone/evdev/key_event_converter_evdev.h" |
| 21 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 21 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| 22 | 22 |
| 23 #if defined(USE_EVDEV_GESTURES) | 23 #if defined(USE_EVDEV_GESTURES) |
| 24 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" | 24 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
| 25 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" | 25 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr
os.h" |
| 26 #include "ui/events/ozone/evdev/libgestures_glue/gesture_property_provider.h" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 #ifndef EVIOCSCLOCKID | 29 #ifndef EVIOCSCLOCKID |
| 29 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) | 30 #define EVIOCSCLOCKID _IOW('E', 0xa0, int) |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 namespace ui { | 33 namespace ui { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 typedef base::Callback<void(scoped_ptr<EventConverterEvdev>)> | 37 typedef base::Callback<void(scoped_ptr<EventConverterEvdev>)> |
| 37 OpenInputDeviceReplyCallback; | 38 OpenInputDeviceReplyCallback; |
| 38 | 39 |
| 39 struct OpenInputDeviceParams { | 40 struct OpenInputDeviceParams { |
| 40 // Unique identifier for the new device. | 41 // Unique identifier for the new device. |
| 41 int id; | 42 int id; |
| 42 | 43 |
| 43 // Device path to open. | 44 // Device path to open. |
| 44 base::FilePath path; | 45 base::FilePath path; |
| 45 | 46 |
| 46 // Callback for dispatching events. Call on UI thread only. | 47 // Callback for dispatching events. Call on UI thread only. |
| 47 EventDispatchCallback dispatch_callback; | 48 EventDispatchCallback dispatch_callback; |
| 48 | 49 |
| 49 // State shared between devices. Must not be dereferenced on worker thread. | 50 // State shared between devices. Must not be dereferenced on worker thread. |
| 50 EventModifiersEvdev* modifiers; | 51 EventModifiersEvdev* modifiers; |
| 51 CursorDelegateEvdev* cursor; | 52 CursorDelegateEvdev* cursor; |
| 53 GesturePropertyProvider* gesture_property_provider; |
| 52 }; | 54 }; |
| 53 | 55 |
| 54 #if defined(USE_EVDEV_GESTURES) | 56 #if defined(USE_EVDEV_GESTURES) |
| 55 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { | 57 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { |
| 56 if (devinfo.HasAbsXY() && !devinfo.IsMappedToScreen()) | 58 if (devinfo.HasAbsXY() && !devinfo.IsMappedToScreen()) |
| 57 return true; // touchpad | 59 return true; // touchpad |
| 58 | 60 |
| 59 if (devinfo.HasRelXY()) | 61 if (devinfo.HasRelXY()) |
| 60 return true; // mouse | 62 return true; // mouse |
| 61 | 63 |
| 62 return false; | 64 return false; |
| 63 } | 65 } |
| 64 #endif | 66 #endif |
| 65 | 67 |
| 66 scoped_ptr<EventConverterEvdev> CreateConverter( | 68 scoped_ptr<EventConverterEvdev> CreateConverter( |
| 67 const OpenInputDeviceParams& params, | 69 const OpenInputDeviceParams& params, |
| 68 int fd, | 70 int fd, |
| 69 const EventDeviceInfo& devinfo) { | 71 const EventDeviceInfo& devinfo) { |
| 70 #if defined(USE_EVDEV_GESTURES) | 72 #if defined(USE_EVDEV_GESTURES) |
| 71 // Touchpad or mouse: use gestures library. | 73 // Touchpad or mouse: use gestures library. |
| 72 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent | 74 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
| 73 if (UseGesturesLibraryForDevice(devinfo)) { | 75 if (UseGesturesLibraryForDevice(devinfo)) { |
| 74 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = | 76 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = make_scoped_ptr( |
| 75 make_scoped_ptr(new GestureInterpreterLibevdevCros( | 77 new GestureInterpreterLibevdevCros(params.id, |
| 76 params.modifiers, params.cursor, params.dispatch_callback)); | 78 params.modifiers, |
| 79 params.cursor, |
| 80 params.gesture_property_provider, |
| 81 params.dispatch_callback)); |
| 77 return make_scoped_ptr(new EventReaderLibevdevCros( | 82 return make_scoped_ptr(new EventReaderLibevdevCros( |
| 78 fd, params.path, params.id, gesture_interp.Pass())); | 83 fd, params.path, params.id, gesture_interp.Pass())); |
| 79 } | 84 } |
| 80 #endif | 85 #endif |
| 81 | 86 |
| 82 // Touchscreen: use TouchEventConverterEvdev. | 87 // Touchscreen: use TouchEventConverterEvdev. |
| 83 scoped_ptr<EventConverterEvdev> converter; | 88 scoped_ptr<EventConverterEvdev> converter; |
| 84 if (devinfo.HasAbsXY()) | 89 if (devinfo.HasAbsXY()) |
| 85 return make_scoped_ptr<EventConverterEvdev>(new TouchEventConverterEvdev( | 90 return make_scoped_ptr<EventConverterEvdev>(new TouchEventConverterEvdev( |
| 86 fd, params.path, params.id, devinfo, params.dispatch_callback)); | 91 fd, params.path, params.id, devinfo, params.dispatch_callback)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 converter.reset(); | 145 converter.reset(); |
| 141 } | 146 } |
| 142 | 147 |
| 143 } // namespace | 148 } // namespace |
| 144 | 149 |
| 145 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, | 150 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 146 DeviceManager* device_manager) | 151 DeviceManager* device_manager) |
| 147 : last_device_id_(0), | 152 : last_device_id_(0), |
| 148 device_manager_(device_manager), | 153 device_manager_(device_manager), |
| 149 cursor_(cursor), | 154 cursor_(cursor), |
| 155 #if defined(USE_EVDEV_GESTURES) |
| 156 gesture_property_provider_(new GesturePropertyProvider), |
| 157 #endif |
| 150 dispatch_callback_( | 158 dispatch_callback_( |
| 151 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), | 159 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), |
| 152 base::Unretained(this))), | 160 base::Unretained(this))), |
| 153 weak_ptr_factory_(this) { | 161 weak_ptr_factory_(this) { |
| 154 DCHECK(device_manager_); | 162 DCHECK(device_manager_); |
| 155 } | 163 } |
| 156 | 164 |
| 157 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 165 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
| 158 | 166 |
| 159 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 167 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 187 case DeviceEvent::ADD: | 195 case DeviceEvent::ADD: |
| 188 case DeviceEvent::CHANGE: { | 196 case DeviceEvent::CHANGE: { |
| 189 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); | 197 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
| 190 | 198 |
| 191 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 199 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
| 192 params->id = NextDeviceId(); | 200 params->id = NextDeviceId(); |
| 193 params->path = event.path(); | 201 params->path = event.path(); |
| 194 params->dispatch_callback = dispatch_callback_; | 202 params->dispatch_callback = dispatch_callback_; |
| 195 params->modifiers = &modifiers_; | 203 params->modifiers = &modifiers_; |
| 196 params->cursor = cursor_; | 204 params->cursor = cursor_; |
| 205 params->gesture_property_provider = gesture_property_provider_.get(); |
| 197 | 206 |
| 198 OpenInputDeviceReplyCallback reply_callback = | 207 OpenInputDeviceReplyCallback reply_callback = |
| 199 base::Bind(&EventFactoryEvdev::AttachInputDevice, | 208 base::Bind(&EventFactoryEvdev::AttachInputDevice, |
| 200 weak_ptr_factory_.GetWeakPtr()); | 209 weak_ptr_factory_.GetWeakPtr()); |
| 201 | 210 |
| 202 // Dispatch task to open from the worker pool, since open may block. | 211 // Dispatch task to open from the worker pool, since open may block. |
| 203 base::WorkerPool::PostTask(FROM_HERE, | 212 base::WorkerPool::PostTask(FROM_HERE, |
| 204 base::Bind(&OpenInputDevice, | 213 base::Bind(&OpenInputDevice, |
| 205 base::Passed(¶ms), | 214 base::Passed(¶ms), |
| 206 ui_task_runner_, | 215 ui_task_runner_, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 } | 288 } |
| 280 | 289 |
| 281 observer->OnTouchscreenDevicesUpdated(touchscreens); | 290 observer->OnTouchscreenDevicesUpdated(touchscreens); |
| 282 } | 291 } |
| 283 | 292 |
| 284 int EventFactoryEvdev::NextDeviceId() { | 293 int EventFactoryEvdev::NextDeviceId() { |
| 285 return ++last_device_id_; | 294 return ++last_device_id_; |
| 286 } | 295 } |
| 287 | 296 |
| 288 } // namespace ui | 297 } // namespace ui |
| OLD | NEW |