| 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 KeyboardEvdev* keyboard; | 52 KeyboardEvdev* keyboard; |
| 52 CursorDelegateEvdev* cursor; | 53 CursorDelegateEvdev* cursor; |
| 54 #if defined(USE_EVDEV_GESTURES) |
| 55 GesturePropertyProvider* gesture_property_provider; |
| 56 #endif |
| 53 }; | 57 }; |
| 54 | 58 |
| 55 #if defined(USE_EVDEV_GESTURES) | 59 #if defined(USE_EVDEV_GESTURES) |
| 56 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { | 60 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { |
| 57 if (devinfo.HasAbsXY() && !devinfo.IsMappedToScreen()) | 61 if (devinfo.HasAbsXY() && !devinfo.IsMappedToScreen()) |
| 58 return true; // touchpad | 62 return true; // touchpad |
| 59 | 63 |
| 60 if (devinfo.HasRelXY()) | 64 if (devinfo.HasRelXY()) |
| 61 return true; // mouse | 65 return true; // mouse |
| 62 | 66 |
| 63 return false; | 67 return false; |
| 64 } | 68 } |
| 65 #endif | 69 #endif |
| 66 | 70 |
| 67 scoped_ptr<EventConverterEvdev> CreateConverter( | 71 scoped_ptr<EventConverterEvdev> CreateConverter( |
| 68 const OpenInputDeviceParams& params, | 72 const OpenInputDeviceParams& params, |
| 69 int fd, | 73 int fd, |
| 70 const EventDeviceInfo& devinfo) { | 74 const EventDeviceInfo& devinfo) { |
| 71 #if defined(USE_EVDEV_GESTURES) | 75 #if defined(USE_EVDEV_GESTURES) |
| 72 // Touchpad or mouse: use gestures library. | 76 // Touchpad or mouse: use gestures library. |
| 73 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent | 77 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
| 74 if (UseGesturesLibraryForDevice(devinfo)) { | 78 if (UseGesturesLibraryForDevice(devinfo)) { |
| 75 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = make_scoped_ptr( | 79 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = make_scoped_ptr( |
| 76 new GestureInterpreterLibevdevCros(params.modifiers, | 80 new GestureInterpreterLibevdevCros(params.id, |
| 81 params.modifiers, |
| 77 params.cursor, | 82 params.cursor, |
| 78 params.keyboard, | 83 params.keyboard, |
| 84 params.gesture_property_provider, |
| 79 params.dispatch_callback)); | 85 params.dispatch_callback)); |
| 80 return make_scoped_ptr(new EventReaderLibevdevCros( | 86 return make_scoped_ptr(new EventReaderLibevdevCros( |
| 81 fd, params.path, params.id, gesture_interp.Pass())); | 87 fd, params.path, params.id, gesture_interp.Pass())); |
| 82 } | 88 } |
| 83 #endif | 89 #endif |
| 84 | 90 |
| 85 // Touchscreen: use TouchEventConverterEvdev. | 91 // Touchscreen: use TouchEventConverterEvdev. |
| 86 scoped_ptr<EventConverterEvdev> converter; | 92 scoped_ptr<EventConverterEvdev> converter; |
| 87 if (devinfo.HasAbsXY()) | 93 if (devinfo.HasAbsXY()) |
| 88 return make_scoped_ptr<EventConverterEvdev>(new TouchEventConverterEvdev( | 94 return make_scoped_ptr<EventConverterEvdev>(new TouchEventConverterEvdev( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 153 |
| 148 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, | 154 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 149 DeviceManager* device_manager) | 155 DeviceManager* device_manager) |
| 150 : last_device_id_(0), | 156 : last_device_id_(0), |
| 151 device_manager_(device_manager), | 157 device_manager_(device_manager), |
| 152 dispatch_callback_( | 158 dispatch_callback_( |
| 153 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), | 159 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), |
| 154 base::Unretained(this))), | 160 base::Unretained(this))), |
| 155 keyboard_(&modifiers_, dispatch_callback_), | 161 keyboard_(&modifiers_, dispatch_callback_), |
| 156 cursor_(cursor), | 162 cursor_(cursor), |
| 163 #if defined(USE_EVDEV_GESTURES) |
| 164 gesture_property_provider_(new GesturePropertyProvider), |
| 165 #endif |
| 157 weak_ptr_factory_(this) { | 166 weak_ptr_factory_(this) { |
| 158 DCHECK(device_manager_); | 167 DCHECK(device_manager_); |
| 159 } | 168 } |
| 160 | 169 |
| 161 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 170 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
| 162 | 171 |
| 163 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 172 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
| 164 DispatchEvent(event); | 173 DispatchEvent(event); |
| 165 } | 174 } |
| 166 | 175 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 192 case DeviceEvent::CHANGE: { | 201 case DeviceEvent::CHANGE: { |
| 193 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); | 202 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
| 194 | 203 |
| 195 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 204 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
| 196 params->id = NextDeviceId(); | 205 params->id = NextDeviceId(); |
| 197 params->path = event.path(); | 206 params->path = event.path(); |
| 198 params->dispatch_callback = dispatch_callback_; | 207 params->dispatch_callback = dispatch_callback_; |
| 199 params->modifiers = &modifiers_; | 208 params->modifiers = &modifiers_; |
| 200 params->keyboard = &keyboard_; | 209 params->keyboard = &keyboard_; |
| 201 params->cursor = cursor_; | 210 params->cursor = cursor_; |
| 211 #if defined(USE_EVDEV_GESTURES) |
| 212 params->gesture_property_provider = gesture_property_provider_.get(); |
| 213 #endif |
| 202 | 214 |
| 203 OpenInputDeviceReplyCallback reply_callback = | 215 OpenInputDeviceReplyCallback reply_callback = |
| 204 base::Bind(&EventFactoryEvdev::AttachInputDevice, | 216 base::Bind(&EventFactoryEvdev::AttachInputDevice, |
| 205 weak_ptr_factory_.GetWeakPtr()); | 217 weak_ptr_factory_.GetWeakPtr()); |
| 206 | 218 |
| 207 // Dispatch task to open from the worker pool, since open may block. | 219 // Dispatch task to open from the worker pool, since open may block. |
| 208 base::WorkerPool::PostTask(FROM_HERE, | 220 base::WorkerPool::PostTask(FROM_HERE, |
| 209 base::Bind(&OpenInputDevice, | 221 base::Bind(&OpenInputDevice, |
| 210 base::Passed(¶ms), | 222 base::Passed(¶ms), |
| 211 ui_task_runner_, | 223 ui_task_runner_, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 296 } |
| 285 | 297 |
| 286 observer->OnTouchscreenDevicesUpdated(touchscreens); | 298 observer->OnTouchscreenDevicesUpdated(touchscreens); |
| 287 } | 299 } |
| 288 | 300 |
| 289 int EventFactoryEvdev::NextDeviceId() { | 301 int EventFactoryEvdev::NextDeviceId() { |
| 290 return ++last_device_id_; | 302 return ++last_device_id_; |
| 291 } | 303 } |
| 292 | 304 |
| 293 } // namespace ui | 305 } // namespace ui |
| OLD | NEW |