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/bind.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 struct OpenInputDeviceParams { | 45 struct OpenInputDeviceParams { |
46 // Unique identifier for the new device. | 46 // Unique identifier for the new device. |
47 int id; | 47 int id; |
48 | 48 |
49 // Device path to open. | 49 // Device path to open. |
50 base::FilePath path; | 50 base::FilePath path; |
51 | 51 |
52 // Callback for dispatching events. Call on UI thread only. | 52 // Callback for dispatching events. Call on UI thread only. |
53 EventDispatchCallback dispatch_callback; | 53 EventDispatchCallback dispatch_callback; |
| 54 KeyEventDispatchCallback key_callback; |
54 TouchEventDispatchCallback touch_callback; | 55 TouchEventDispatchCallback touch_callback; |
55 | 56 |
56 // State shared between devices. Must not be dereferenced on worker thread. | 57 // State shared between devices. Must not be dereferenced on worker thread. |
57 EventModifiersEvdev* modifiers; | 58 EventModifiersEvdev* modifiers; |
58 MouseButtonMapEvdev* button_map; | 59 MouseButtonMapEvdev* button_map; |
59 KeyboardEvdev* keyboard; | |
60 CursorDelegateEvdev* cursor; | 60 CursorDelegateEvdev* cursor; |
61 #if defined(USE_EVDEV_GESTURES) | 61 #if defined(USE_EVDEV_GESTURES) |
62 GesturePropertyProvider* gesture_property_provider; | 62 GesturePropertyProvider* gesture_property_provider; |
63 #endif | 63 #endif |
64 }; | 64 }; |
65 | 65 |
66 #if defined(USE_EVDEV_GESTURES) | 66 #if defined(USE_EVDEV_GESTURES) |
67 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { | 67 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { |
68 if (devinfo.HasTouchpad()) | 68 if (devinfo.HasTouchpad()) |
69 return true; | 69 return true; |
(...skipping 10 matching lines...) Expand all Loading... |
80 int fd, | 80 int fd, |
81 InputDeviceType type, | 81 InputDeviceType type, |
82 const EventDeviceInfo& devinfo) { | 82 const EventDeviceInfo& devinfo) { |
83 #if defined(USE_EVDEV_GESTURES) | 83 #if defined(USE_EVDEV_GESTURES) |
84 // Touchpad or mouse: use gestures library. | 84 // Touchpad or mouse: use gestures library. |
85 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent | 85 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
86 if (UseGesturesLibraryForDevice(devinfo)) { | 86 if (UseGesturesLibraryForDevice(devinfo)) { |
87 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = | 87 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = |
88 make_scoped_ptr(new GestureInterpreterLibevdevCros( | 88 make_scoped_ptr(new GestureInterpreterLibevdevCros( |
89 params.id, params.modifiers, params.button_map, params.cursor, | 89 params.id, params.modifiers, params.button_map, params.cursor, |
90 params.keyboard, params.gesture_property_provider, | 90 params.gesture_property_provider, params.key_callback, |
91 params.dispatch_callback)); | 91 params.dispatch_callback)); |
92 return make_scoped_ptr(new EventReaderLibevdevCros( | 92 return make_scoped_ptr(new EventReaderLibevdevCros( |
93 fd, params.path, params.id, type, devinfo, gesture_interp.Pass())); | 93 fd, params.path, params.id, type, devinfo, gesture_interp.Pass())); |
94 } | 94 } |
95 #endif | 95 #endif |
96 | 96 |
97 // Touchscreen: use TouchEventConverterEvdev. | 97 // Touchscreen: use TouchEventConverterEvdev. |
98 if (devinfo.HasMTAbsXY()) { | 98 if (devinfo.HasMTAbsXY()) { |
99 scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( | 99 scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( |
100 fd, params.path, params.id, type, params.touch_callback)); | 100 fd, params.path, params.id, type, params.touch_callback)); |
101 converter->Initialize(devinfo); | 101 converter->Initialize(devinfo); |
102 return converter.Pass(); | 102 return converter.Pass(); |
103 } | 103 } |
104 | 104 |
105 // Graphics tablet | 105 // Graphics tablet |
106 if (devinfo.HasAbsXY()) | 106 if (devinfo.HasAbsXY()) |
107 return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev( | 107 return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev( |
108 fd, params.path, params.id, type, params.modifiers, params.cursor, | 108 fd, params.path, params.id, type, params.modifiers, params.cursor, |
109 devinfo, params.dispatch_callback)); | 109 devinfo, params.dispatch_callback)); |
110 | 110 |
111 // Everything else: use EventConverterEvdevImpl. | 111 // Everything else: use EventConverterEvdevImpl. |
112 return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl( | 112 return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl( |
113 fd, params.path, params.id, type, devinfo, params.modifiers, | 113 fd, params.path, params.id, type, devinfo, params.modifiers, |
114 params.button_map, params.cursor, params.keyboard, | 114 params.button_map, params.cursor, params.key_callback, |
115 params.dispatch_callback)); | 115 params.dispatch_callback)); |
116 } | 116 } |
117 | 117 |
118 // Open an input device. Opening may put the calling thread to sleep, and | 118 // Open an input device. Opening may put the calling thread to sleep, and |
119 // therefore should be run on a thread where latency is not critical. We | 119 // therefore should be run on a thread where latency is not critical. We |
120 // run it on a thread from the worker pool. | 120 // run it on a thread from the worker pool. |
121 // | 121 // |
122 // This takes a TaskRunner and runs the reply on that thread, so that we | 122 // This takes a TaskRunner and runs the reply on that thread, so that we |
123 // can hop threads if necessary (back to the UI thread). | 123 // can hop threads if necessary (back to the UI thread). |
124 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, | 124 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 DCHECK(device_manager_); | 193 DCHECK(device_manager_); |
194 } | 194 } |
195 | 195 |
196 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 196 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
197 | 197 |
198 scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { | 198 scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { |
199 return make_scoped_ptr(new InputInjectorEvdev( | 199 return make_scoped_ptr(new InputInjectorEvdev( |
200 &modifiers_, cursor_, &keyboard_, dispatch_callback_)); | 200 &modifiers_, cursor_, &keyboard_, dispatch_callback_)); |
201 } | 201 } |
202 | 202 |
| 203 void EventFactoryEvdev::PostKeyEvent(int device_id, |
| 204 unsigned int code, |
| 205 bool down) { |
| 206 keyboard_.OnKeyChange(code, down); |
| 207 } |
| 208 |
203 void EventFactoryEvdev::PostTouchEvent(const TouchEventParams& params) { | 209 void EventFactoryEvdev::PostTouchEvent(const TouchEventParams& params) { |
204 float x = params.location.x(); | 210 float x = params.location.x(); |
205 float y = params.location.y(); | 211 float y = params.location.y(); |
206 double radius_x = params.radii.x(); | 212 double radius_x = params.radii.x(); |
207 double radius_y = params.radii.y(); | 213 double radius_y = params.radii.y(); |
208 | 214 |
209 // Transform the event according (this is used to align touches | 215 // Transform the event according (this is used to align touches |
210 // to the image based on display mode). | 216 // to the image based on display mode). |
211 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x, | 217 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x, |
212 &y); | 218 &y); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 case DeviceEvent::ADD: | 268 case DeviceEvent::ADD: |
263 case DeviceEvent::CHANGE: { | 269 case DeviceEvent::CHANGE: { |
264 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); | 270 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
265 | 271 |
266 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 272 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
267 params->id = NextDeviceId(); | 273 params->id = NextDeviceId(); |
268 params->path = event.path(); | 274 params->path = event.path(); |
269 params->dispatch_callback = dispatch_callback_; | 275 params->dispatch_callback = dispatch_callback_; |
270 params->modifiers = &modifiers_; | 276 params->modifiers = &modifiers_; |
271 params->button_map = &button_map_; | 277 params->button_map = &button_map_; |
272 params->keyboard = &keyboard_; | |
273 params->cursor = cursor_; | 278 params->cursor = cursor_; |
274 | 279 params->key_callback = base::Bind(&EventFactoryEvdev::PostKeyEvent, |
| 280 weak_ptr_factory_.GetWeakPtr()); |
275 params->touch_callback = base::Bind(&EventFactoryEvdev::PostTouchEvent, | 281 params->touch_callback = base::Bind(&EventFactoryEvdev::PostTouchEvent, |
276 weak_ptr_factory_.GetWeakPtr()); | 282 weak_ptr_factory_.GetWeakPtr()); |
277 | 283 |
278 #if defined(USE_EVDEV_GESTURES) | 284 #if defined(USE_EVDEV_GESTURES) |
279 params->gesture_property_provider = gesture_property_provider_.get(); | 285 params->gesture_property_provider = gesture_property_provider_.get(); |
280 #endif | 286 #endif |
281 | 287 |
282 OpenInputDeviceReplyCallback reply_callback = | 288 OpenInputDeviceReplyCallback reply_callback = |
283 base::Bind(&EventFactoryEvdev::AttachInputDevice, | 289 base::Bind(&EventFactoryEvdev::AttachInputDevice, |
284 weak_ptr_factory_.GetWeakPtr()); | 290 weak_ptr_factory_.GetWeakPtr()); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 447 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
442 #endif | 448 #endif |
443 // In the future we can add other device matching logics here. | 449 // In the future we can add other device matching logics here. |
444 | 450 |
445 if (device_ids) | 451 if (device_ids) |
446 device_ids->assign(ids.begin(), ids.end()); | 452 device_ids->assign(ids.begin(), ids.end()); |
447 return !ids.empty(); | 453 return !ids.empty(); |
448 } | 454 } |
449 | 455 |
450 } // namespace ui | 456 } // namespace ui |
OLD | NEW |