Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: ui/events/ozone/evdev/event_factory_evdev.cc

Issue 874713002: [PATCH 1/11] ozone: evdev: Move touch ui::Event transformation to EventFactoryEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comment & add missing export Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 to align touches to the image based on display mode.
210 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x,
211 &y);
212 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
213 &radius_x);
214 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
215 &radius_y);
216
217 scoped_ptr<TouchEvent> touch_event(new TouchEvent(
218 params.type, gfx::PointF(x, y),
219 /* flags */ 0, params.touch_id, params.timestamp, radius_x, radius_y,
220 /* angle */ 0., params.pressure));
221 touch_event->set_source_device_id(params.device_id);
222 PostUiEvent(touch_event.Pass());
223 }
224
200 void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { 225 void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) {
201 base::ThreadTaskRunnerHandle::Get()->PostTask( 226 base::ThreadTaskRunnerHandle::Get()->PostTask(
202 FROM_HERE, 227 FROM_HERE,
203 base::Bind(&EventFactoryEvdev::DispatchUiEventTask, 228 base::Bind(&EventFactoryEvdev::DispatchUiEventTask,
204 weak_ptr_factory_.GetWeakPtr(), 229 weak_ptr_factory_.GetWeakPtr(),
205 base::Passed(&event))); 230 base::Passed(&event)));
206 } 231 }
207 232
208 void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) { 233 void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) {
209 DispatchEvent(event.get()); 234 DispatchEvent(event.get());
(...skipping 28 matching lines...) Expand all
238 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); 263 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value());
239 264
240 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams); 265 scoped_ptr<OpenInputDeviceParams> params(new OpenInputDeviceParams);
241 params->id = NextDeviceId(); 266 params->id = NextDeviceId();
242 params->path = event.path(); 267 params->path = event.path();
243 params->dispatch_callback = dispatch_callback_; 268 params->dispatch_callback = dispatch_callback_;
244 params->modifiers = &modifiers_; 269 params->modifiers = &modifiers_;
245 params->button_map = &button_map_; 270 params->button_map = &button_map_;
246 params->keyboard = &keyboard_; 271 params->keyboard = &keyboard_;
247 params->cursor = cursor_; 272 params->cursor = cursor_;
273
274 params->touch_callback = base::Bind(&EventFactoryEvdev::PostTouchEvent,
275 weak_ptr_factory_.GetWeakPtr());
276
248 #if defined(USE_EVDEV_GESTURES) 277 #if defined(USE_EVDEV_GESTURES)
249 params->gesture_property_provider = gesture_property_provider_.get(); 278 params->gesture_property_provider = gesture_property_provider_.get();
250 #endif 279 #endif
251 280
252 OpenInputDeviceReplyCallback reply_callback = 281 OpenInputDeviceReplyCallback reply_callback =
253 base::Bind(&EventFactoryEvdev::AttachInputDevice, 282 base::Bind(&EventFactoryEvdev::AttachInputDevice,
254 weak_ptr_factory_.GetWeakPtr()); 283 weak_ptr_factory_.GetWeakPtr());
255 284
256 // Dispatch task to open from the worker pool, since open may block. 285 // Dispatch task to open from the worker pool, since open may block.
257 base::WorkerPool::PostTask(FROM_HERE, 286 base::WorkerPool::PostTask(FROM_HERE,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 gesture_property_provider_->GetDeviceIdsByType(type, &ids); 440 gesture_property_provider_->GetDeviceIdsByType(type, &ids);
412 #endif 441 #endif
413 // In the future we can add other device matching logics here. 442 // In the future we can add other device matching logics here.
414 443
415 if (device_ids) 444 if (device_ids)
416 device_ids->assign(ids.begin(), ids.end()); 445 device_ids->assign(ids.begin(), ids.end());
417 return !ids.empty(); 446 return !ids.empty();
418 } 447 }
419 448
420 } // namespace ui 449 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/event_factory_evdev.h ('k') | ui/events/ozone/evdev/touch_event_converter_evdev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698