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/bind.h" | |
10 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
14 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
16 #include "base/time/time.h" | |
15 #include "ui/events/devices/device_data_manager.h" | 17 #include "ui/events/devices/device_data_manager.h" |
16 #include "ui/events/devices/device_util_linux.h" | 18 #include "ui/events/devices/device_util_linux.h" |
17 #include "ui/events/devices/input_device.h" | 19 #include "ui/events/devices/input_device.h" |
18 #include "ui/events/ozone/device/device_event.h" | 20 #include "ui/events/ozone/device/device_event.h" |
19 #include "ui/events/ozone/device/device_manager.h" | 21 #include "ui/events/ozone/device/device_manager.h" |
20 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 22 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
21 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 23 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
22 #include "ui/events/ozone/evdev/input_injector_evdev.h" | 24 #include "ui/events/ozone/evdev/input_injector_evdev.h" |
23 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 25 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
24 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 26 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
42 | 44 |
43 struct OpenInputDeviceParams { | 45 struct OpenInputDeviceParams { |
44 // Unique identifier for the new device. | 46 // Unique identifier for the new device. |
45 int id; | 47 int id; |
46 | 48 |
47 // Device path to open. | 49 // Device path to open. |
48 base::FilePath path; | 50 base::FilePath path; |
49 | 51 |
50 // Callback for dispatching events. Call on UI thread only. | 52 // Callback for dispatching events. Call on UI thread only. |
51 EventDispatchCallback dispatch_callback; | 53 EventDispatchCallback dispatch_callback; |
54 TouchEventDispatchCallback touch_callback; | |
52 | 55 |
53 // State shared between devices. Must not be dereferenced on worker thread. | 56 // State shared between devices. Must not be dereferenced on worker thread. |
54 EventModifiersEvdev* modifiers; | 57 EventModifiersEvdev* modifiers; |
55 MouseButtonMapEvdev* button_map; | 58 MouseButtonMapEvdev* button_map; |
56 KeyboardEvdev* keyboard; | 59 KeyboardEvdev* keyboard; |
57 CursorDelegateEvdev* cursor; | 60 CursorDelegateEvdev* cursor; |
58 #if defined(USE_EVDEV_GESTURES) | 61 #if defined(USE_EVDEV_GESTURES) |
59 GesturePropertyProvider* gesture_property_provider; | 62 GesturePropertyProvider* gesture_property_provider; |
60 #endif | 63 #endif |
61 }; | 64 }; |
(...skipping 25 matching lines...) Expand all Loading... | |
87 params.keyboard, params.gesture_property_provider, | 90 params.keyboard, params.gesture_property_provider, |
88 params.dispatch_callback)); | 91 params.dispatch_callback)); |
89 return make_scoped_ptr(new EventReaderLibevdevCros( | 92 return make_scoped_ptr(new EventReaderLibevdevCros( |
90 fd, params.path, params.id, type, devinfo, gesture_interp.Pass())); | 93 fd, params.path, params.id, type, devinfo, gesture_interp.Pass())); |
91 } | 94 } |
92 #endif | 95 #endif |
93 | 96 |
94 // Touchscreen: use TouchEventConverterEvdev. | 97 // Touchscreen: use TouchEventConverterEvdev. |
95 if (devinfo.HasMTAbsXY()) { | 98 if (devinfo.HasMTAbsXY()) { |
96 scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( | 99 scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( |
97 fd, params.path, params.id, type, params.dispatch_callback)); | 100 fd, params.path, params.id, type, params.touch_callback)); |
98 converter->Initialize(devinfo); | 101 converter->Initialize(devinfo); |
99 return converter.Pass(); | 102 return converter.Pass(); |
100 } | 103 } |
101 | 104 |
102 // Graphics tablet | 105 // Graphics tablet |
103 if (devinfo.HasAbsXY()) | 106 if (devinfo.HasAbsXY()) |
104 return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev( | 107 return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev( |
105 fd, params.path, params.id, type, params.modifiers, params.cursor, | 108 fd, params.path, params.id, type, params.modifiers, params.cursor, |
106 devinfo, params.dispatch_callback)); | 109 devinfo, params.dispatch_callback)); |
107 | 110 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 DCHECK(device_manager_); | 193 DCHECK(device_manager_); |
191 } | 194 } |
192 | 195 |
193 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 196 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
194 | 197 |
195 scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { | 198 scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { |
196 return make_scoped_ptr(new InputInjectorEvdev( | 199 return make_scoped_ptr(new InputInjectorEvdev( |
197 &modifiers_, cursor_, &keyboard_, dispatch_callback_)); | 200 &modifiers_, cursor_, &keyboard_, dispatch_callback_)); |
198 } | 201 } |
199 | 202 |
203 void EventFactoryEvdev::PostTouchEvent(const TouchEventParams& params) { | |
204 float x = params.location.x(); | |
205 float y = params.location.y(); | |
206 double radius_x = params.radii.x(); | |
207 double radius_y = params.radii.y(); | |
208 | |
209 // Transform the event according (this is used to align touches | |
alexst (slow to review)
2015/01/26 18:20:13
accordingly?
spang
2015/01/26 23:43:35
Done.
| |
210 // to the image based on display mode). | |
211 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x, | |
212 &y); | |
213 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, | |
214 &radius_x); | |
215 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, | |
216 &radius_y); | |
217 | |
218 scoped_ptr<TouchEvent> touch_event(new TouchEvent( | |
219 params.type, gfx::PointF(x, y), | |
220 /* flags */ 0, params.touch_id, params.timestamp, radius_x, radius_y, | |
221 /* angle */ 0., params.pressure)); | |
222 touch_event->set_source_device_id(params.device_id); | |
223 PostUiEvent(touch_event.Pass()); | |
alexst (slow to review)
2015/01/26 18:20:13
You can skip the post task and the scoped_ptr here
spang
2015/01/26 23:43:35
Yep but will need to wait until patch #9 ("Add a d
| |
224 } | |
225 | |
200 void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { | 226 void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { |
201 base::ThreadTaskRunnerHandle::Get()->PostTask( | 227 base::ThreadTaskRunnerHandle::Get()->PostTask( |
202 FROM_HERE, | 228 FROM_HERE, |
203 base::Bind(&EventFactoryEvdev::DispatchUiEventTask, | 229 base::Bind(&EventFactoryEvdev::DispatchUiEventTask, |
204 weak_ptr_factory_.GetWeakPtr(), | 230 weak_ptr_factory_.GetWeakPtr(), |
205 base::Passed(&event))); | 231 base::Passed(&event))); |
206 } | 232 } |
207 | 233 |
208 void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) { | 234 void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) { |
209 DispatchEvent(event.get()); | 235 DispatchEvent(event.get()); |
(...skipping 28 matching lines...) Expand all Loading... | |
238 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); | 264 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
239 | 265 |
240 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 266 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
241 params->id = NextDeviceId(); | 267 params->id = NextDeviceId(); |
242 params->path = event.path(); | 268 params->path = event.path(); |
243 params->dispatch_callback = dispatch_callback_; | 269 params->dispatch_callback = dispatch_callback_; |
244 params->modifiers = &modifiers_; | 270 params->modifiers = &modifiers_; |
245 params->button_map = &button_map_; | 271 params->button_map = &button_map_; |
246 params->keyboard = &keyboard_; | 272 params->keyboard = &keyboard_; |
247 params->cursor = cursor_; | 273 params->cursor = cursor_; |
274 | |
275 params->touch_callback = base::Bind(&EventFactoryEvdev::PostTouchEvent, | |
276 weak_ptr_factory_.GetWeakPtr()); | |
277 | |
248 #if defined(USE_EVDEV_GESTURES) | 278 #if defined(USE_EVDEV_GESTURES) |
249 params->gesture_property_provider = gesture_property_provider_.get(); | 279 params->gesture_property_provider = gesture_property_provider_.get(); |
250 #endif | 280 #endif |
251 | 281 |
252 OpenInputDeviceReplyCallback reply_callback = | 282 OpenInputDeviceReplyCallback reply_callback = |
253 base::Bind(&EventFactoryEvdev::AttachInputDevice, | 283 base::Bind(&EventFactoryEvdev::AttachInputDevice, |
254 weak_ptr_factory_.GetWeakPtr()); | 284 weak_ptr_factory_.GetWeakPtr()); |
255 | 285 |
256 // Dispatch task to open from the worker pool, since open may block. | 286 // Dispatch task to open from the worker pool, since open may block. |
257 base::WorkerPool::PostTask(FROM_HERE, | 287 base::WorkerPool::PostTask(FROM_HERE, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 441 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
412 #endif | 442 #endif |
413 // In the future we can add other device matching logics here. | 443 // In the future we can add other device matching logics here. |
414 | 444 |
415 if (device_ids) | 445 if (device_ids) |
416 device_ids->assign(ids.begin(), ids.end()); | 446 device_ids->assign(ids.begin(), ids.end()); |
417 return !ids.empty(); | 447 return !ids.empty(); |
418 } | 448 } |
419 | 449 |
420 } // namespace ui | 450 } // namespace ui |
OLD | NEW |