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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 int id; | 41 int id; |
42 | 42 |
43 // Device path to open. | 43 // Device path to open. |
44 base::FilePath path; | 44 base::FilePath path; |
45 | 45 |
46 // Callback for dispatching events. Call on UI thread only. | 46 // Callback for dispatching events. Call on UI thread only. |
47 EventDispatchCallback dispatch_callback; | 47 EventDispatchCallback dispatch_callback; |
48 | 48 |
49 // State shared between devices. Must not be dereferenced on worker thread. | 49 // State shared between devices. Must not be dereferenced on worker thread. |
50 EventModifiersEvdev* modifiers; | 50 EventModifiersEvdev* modifiers; |
| 51 KeyboardEvdev* keyboard; |
51 CursorDelegateEvdev* cursor; | 52 CursorDelegateEvdev* cursor; |
52 }; | 53 }; |
53 | 54 |
54 #if defined(USE_EVDEV_GESTURES) | 55 #if defined(USE_EVDEV_GESTURES) |
55 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { | 56 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { |
56 if (devinfo.HasAbsXY() && !devinfo.IsMappedToScreen()) | 57 if (devinfo.HasAbsXY() && !devinfo.IsMappedToScreen()) |
57 return true; // touchpad | 58 return true; // touchpad |
58 | 59 |
59 if (devinfo.HasRelXY()) | 60 if (devinfo.HasRelXY()) |
60 return true; // mouse | 61 return true; // mouse |
(...skipping 23 matching lines...) Expand all Loading... |
84 } | 85 } |
85 #endif | 86 #endif |
86 | 87 |
87 // Touchscreen: use TouchEventConverterEvdev. | 88 // Touchscreen: use TouchEventConverterEvdev. |
88 scoped_ptr<EventConverterEvdev> converter; | 89 scoped_ptr<EventConverterEvdev> converter; |
89 if (devinfo.HasAbsXY()) | 90 if (devinfo.HasAbsXY()) |
90 return make_scoped_ptr<EventConverterEvdev>(new TouchEventConverterEvdev( | 91 return make_scoped_ptr<EventConverterEvdev>(new TouchEventConverterEvdev( |
91 fd, params.path, params.id, devinfo, params.dispatch_callback)); | 92 fd, params.path, params.id, devinfo, params.dispatch_callback)); |
92 | 93 |
93 // Everything else: use KeyEventConverterEvdev. | 94 // Everything else: use KeyEventConverterEvdev. |
94 return make_scoped_ptr<EventConverterEvdev>(new KeyEventConverterEvdev( | 95 return make_scoped_ptr<EventConverterEvdev>( |
95 fd, params.path, params.id, params.modifiers, params.dispatch_callback)); | 96 new KeyEventConverterEvdev(fd, params.path, params.id, params.keyboard)); |
96 } | 97 } |
97 | 98 |
98 // Open an input device. Opening may put the calling thread to sleep, and | 99 // Open an input device. Opening may put the calling thread to sleep, and |
99 // therefore should be run on a thread where latency is not critical. We | 100 // therefore should be run on a thread where latency is not critical. We |
100 // run it on a thread from the worker pool. | 101 // run it on a thread from the worker pool. |
101 // | 102 // |
102 // This takes a TaskRunner and runs the reply on that thread, so that we | 103 // This takes a TaskRunner and runs the reply on that thread, so that we |
103 // can hop threads if necessary (back to the UI thread). | 104 // can hop threads if necessary (back to the UI thread). |
104 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, | 105 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, |
105 scoped_refptr<base::TaskRunner> reply_runner, | 106 scoped_refptr<base::TaskRunner> reply_runner, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); | 145 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); |
145 converter.reset(); | 146 converter.reset(); |
146 } | 147 } |
147 | 148 |
148 } // namespace | 149 } // namespace |
149 | 150 |
150 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, | 151 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
151 DeviceManager* device_manager) | 152 DeviceManager* device_manager) |
152 : last_device_id_(0), | 153 : last_device_id_(0), |
153 device_manager_(device_manager), | 154 device_manager_(device_manager), |
154 cursor_(cursor), | |
155 dispatch_callback_( | 155 dispatch_callback_( |
156 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), | 156 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), |
157 base::Unretained(this))), | 157 base::Unretained(this))), |
| 158 keyboard_(&modifiers_, dispatch_callback_), |
| 159 cursor_(cursor), |
158 weak_ptr_factory_(this) { | 160 weak_ptr_factory_(this) { |
159 DCHECK(device_manager_); | 161 DCHECK(device_manager_); |
160 } | 162 } |
161 | 163 |
162 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 164 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
163 | 165 |
164 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 166 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
165 DispatchEvent(event); | 167 DispatchEvent(event); |
166 } | 168 } |
167 | 169 |
(...skipping 23 matching lines...) Expand all Loading... |
191 switch (event.action_type()) { | 193 switch (event.action_type()) { |
192 case DeviceEvent::ADD: | 194 case DeviceEvent::ADD: |
193 case DeviceEvent::CHANGE: { | 195 case DeviceEvent::CHANGE: { |
194 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); | 196 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); |
195 | 197 |
196 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); | 198 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); |
197 params->id = NextDeviceId(); | 199 params->id = NextDeviceId(); |
198 params->path = event.path(); | 200 params->path = event.path(); |
199 params->dispatch_callback = dispatch_callback_; | 201 params->dispatch_callback = dispatch_callback_; |
200 params->modifiers = &modifiers_; | 202 params->modifiers = &modifiers_; |
| 203 params->keyboard = &keyboard_; |
201 params->cursor = cursor_; | 204 params->cursor = cursor_; |
202 | 205 |
203 OpenInputDeviceReplyCallback reply_callback = | 206 OpenInputDeviceReplyCallback reply_callback = |
204 base::Bind(&EventFactoryEvdev::AttachInputDevice, | 207 base::Bind(&EventFactoryEvdev::AttachInputDevice, |
205 weak_ptr_factory_.GetWeakPtr()); | 208 weak_ptr_factory_.GetWeakPtr()); |
206 | 209 |
207 // Dispatch task to open from the worker pool, since open may block. | 210 // Dispatch task to open from the worker pool, since open may block. |
208 base::WorkerPool::PostTask(FROM_HERE, | 211 base::WorkerPool::PostTask(FROM_HERE, |
209 base::Bind(&OpenInputDevice, | 212 base::Bind(&OpenInputDevice, |
210 base::Passed(¶ms), | 213 base::Passed(¶ms), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 287 } |
285 | 288 |
286 observer->OnTouchscreenDevicesUpdated(touchscreens); | 289 observer->OnTouchscreenDevicesUpdated(touchscreens); |
287 } | 290 } |
288 | 291 |
289 int EventFactoryEvdev::NextDeviceId() { | 292 int EventFactoryEvdev::NextDeviceId() { |
290 return ++last_device_id_; | 293 return ++last_device_id_; |
291 } | 294 } |
292 | 295 |
293 } // namespace ui | 296 } // namespace ui |
OLD | NEW |