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

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

Issue 2248933002: Support pen in TouchEventConverterEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 4 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 ui_thread_runner_->PostTask( 115 ui_thread_runner_->PostTask(
116 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchDeviceListsComplete, 116 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchDeviceListsComplete,
117 event_factory_evdev_)); 117 event_factory_evdev_));
118 } 118 }
119 119
120 private: 120 private:
121 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner_; 121 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner_;
122 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; 122 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_;
123 }; 123 };
124 124
125 template <typename T>
126 gfx::PointF GetTransformedEventLocation(const T& params) {
127 float x = params.location.x();
128 float y = params.location.y();
129
130 // Transform the event to align touches to the image based on display mode.
131 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x,
132 &y);
133 return gfx::PointF(x, y);
134 }
135
136 template <typename T>
137 PointerDetails GetTransformedEventPointerDetails(const T& params) {
138 double radius_x = params.pointer_details.radius_x;
139 double radius_y = params.pointer_details.radius_y;
140 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
141 &radius_x);
142 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
143 &radius_y);
144
145 PointerDetails details = params.pointer_details;
146 details.radius_x = radius_x;
147 details.radius_y = radius_y;
148 return details;
149 }
150
125 } // namespace 151 } // namespace
126 152
127 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, 153 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor,
128 DeviceManager* device_manager, 154 DeviceManager* device_manager,
129 KeyboardLayoutEngine* keyboard_layout) 155 KeyboardLayoutEngine* keyboard_layout)
130 : device_manager_(device_manager), 156 : device_manager_(device_manager),
131 keyboard_(&modifiers_, 157 keyboard_(&modifiers_,
132 keyboard_layout, 158 keyboard_layout,
133 base::Bind(&EventFactoryEvdev::DispatchUiEvent, 159 base::Bind(&EventFactoryEvdev::DispatchUiEvent,
134 base::Unretained(this))), 160 base::Unretained(this))),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchKeyEvent", "device", 192 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchKeyEvent", "device",
167 params.device_id); 193 params.device_id);
168 keyboard_.OnKeyChange(params.code, params.down, params.suppress_auto_repeat, 194 keyboard_.OnKeyChange(params.code, params.down, params.suppress_auto_repeat,
169 params.timestamp, params.device_id); 195 params.timestamp, params.device_id);
170 } 196 }
171 197
172 void EventFactoryEvdev::DispatchMouseMoveEvent( 198 void EventFactoryEvdev::DispatchMouseMoveEvent(
173 const MouseMoveEventParams& params) { 199 const MouseMoveEventParams& params) {
174 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseMoveEvent", "device", 200 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseMoveEvent", "device",
175 params.device_id); 201 params.device_id);
202
203 gfx::PointF location = params.location;
204 PointerDetails details = params.pointer_details;
205
206 if (params.flags & EF_DIRECT_INPUT) {
207 details = GetTransformedEventPointerDetails(params);
208 cursor_->MoveCursorTo(GetTransformedEventLocation(params));
209 location = cursor_->GetLocation();
210 }
211
176 MouseEvent event(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 212 MouseEvent event(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
177 params.timestamp, modifiers_.GetModifierFlags(), 213 params.timestamp,
214 modifiers_.GetModifierFlags() | params.flags,
178 /* changed_button_flags */ 0); 215 /* changed_button_flags */ 0);
179 event.set_location_f(params.location); 216 event.set_location_f(location);
180 event.set_root_location_f(params.location); 217 event.set_root_location_f(location);
181 event.set_source_device_id(params.device_id); 218 event.set_source_device_id(params.device_id);
182 event.set_pointer_details(params.pointer_details); 219 event.set_pointer_details(details);
183 DispatchUiEvent(&event); 220 DispatchUiEvent(&event);
184 } 221 }
185 222
186 void EventFactoryEvdev::DispatchMouseButtonEvent( 223 void EventFactoryEvdev::DispatchMouseButtonEvent(
187 const MouseButtonEventParams& params) { 224 const MouseButtonEventParams& params) {
188 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseButtonEvent", "device", 225 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseButtonEvent", "device",
189 params.device_id); 226 params.device_id);
190 227
228 gfx::PointF location = params.location;
229 PointerDetails details = params.pointer_details;
230
231 if (params.flags & EF_DIRECT_INPUT) {
232 details = GetTransformedEventPointerDetails(params);
233 cursor_->MoveCursorTo(GetTransformedEventLocation(params));
234 location = cursor_->GetLocation();
235 }
236
191 // Mouse buttons can be remapped, touchpad taps & clicks cannot. 237 // Mouse buttons can be remapped, touchpad taps & clicks cannot.
192 unsigned int button = params.button; 238 unsigned int button = params.button;
193 if (params.allow_remap) 239 if (params.allow_remap)
194 button = button_map_.GetMappedButton(button); 240 button = button_map_.GetMappedButton(button);
195 241
196 int modifier = EVDEV_MODIFIER_NONE; 242 int modifier = EVDEV_MODIFIER_NONE;
197 switch (button) { 243 switch (button) {
198 case BTN_LEFT: 244 case BTN_LEFT:
199 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; 245 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON;
200 break; 246 break;
(...skipping 18 matching lines...) Expand all
219 modifiers_.UpdateModifier(modifier, params.down); 265 modifiers_.UpdateModifier(modifier, params.down);
220 bool down = modifiers_.GetModifierFlags() & flag; 266 bool down = modifiers_.GetModifierFlags() & flag;
221 267
222 // Suppress nested clicks. EventModifiersEvdev counts presses, we only 268 // Suppress nested clicks. EventModifiersEvdev counts presses, we only
223 // dispatch an event on 0-1 (first press) and 1-0 (last release) transitions. 269 // dispatch an event on 0-1 (first press) and 1-0 (last release) transitions.
224 if (down == was_down) 270 if (down == was_down)
225 return; 271 return;
226 272
227 MouseEvent event(params.down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED, 273 MouseEvent event(params.down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED,
228 gfx::Point(), gfx::Point(), params.timestamp, 274 gfx::Point(), gfx::Point(), params.timestamp,
229 modifiers_.GetModifierFlags() | flag, 275 modifiers_.GetModifierFlags() | flag | params.flags,
230 /* changed_button_flags */ flag); 276 /* changed_button_flags */ flag);
231 event.set_location_f(params.location); 277 event.set_location_f(location);
232 event.set_root_location_f(params.location); 278 event.set_root_location_f(location);
233 event.set_source_device_id(params.device_id); 279 event.set_source_device_id(params.device_id);
234 event.set_pointer_details(params.pointer_details); 280 event.set_pointer_details(details);
235 DispatchUiEvent(&event); 281 DispatchUiEvent(&event);
236 } 282 }
237 283
238 void EventFactoryEvdev::DispatchMouseWheelEvent( 284 void EventFactoryEvdev::DispatchMouseWheelEvent(
239 const MouseWheelEventParams& params) { 285 const MouseWheelEventParams& params) {
240 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseWheelEvent", "device", 286 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseWheelEvent", "device",
241 params.device_id); 287 params.device_id);
242 MouseWheelEvent event(params.delta, gfx::Point(), gfx::Point(), 288 MouseWheelEvent event(params.delta, gfx::Point(), gfx::Point(),
243 params.timestamp, modifiers_.GetModifierFlags(), 289 params.timestamp, modifiers_.GetModifierFlags(),
244 0 /* changed_button_flags */); 290 0 /* changed_button_flags */);
(...skipping 25 matching lines...) Expand all
270 event.set_location_f(params.location); 316 event.set_location_f(params.location);
271 event.set_root_location_f(params.location); 317 event.set_root_location_f(params.location);
272 event.set_source_device_id(params.device_id); 318 event.set_source_device_id(params.device_id);
273 DispatchUiEvent(&event); 319 DispatchUiEvent(&event);
274 } 320 }
275 321
276 void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) { 322 void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) {
277 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchTouchEvent", "device", 323 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchTouchEvent", "device",
278 params.device_id); 324 params.device_id);
279 325
280 float x = params.location.x(); 326 gfx::PointF location = GetTransformedEventLocation(params);
281 float y = params.location.y(); 327 PointerDetails details = GetTransformedEventPointerDetails(params);
282 double radius_x = params.pointer_details.radius_x;
283 double radius_y = params.pointer_details.radius_y;
284
285 // Transform the event to align touches to the image based on display mode.
286 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x,
287 &y);
288 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
289 &radius_x);
290 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
291 &radius_y);
292
293 PointerDetails details = params.pointer_details;
294 details.radius_x = radius_x;
295 details.radius_y = radius_y;
296 328
297 // params.slot is guaranteed to be < kNumTouchEvdevSlots. 329 // params.slot is guaranteed to be < kNumTouchEvdevSlots.
298 int touch_id = touch_id_generator_.GetGeneratedID( 330 int touch_id = touch_id_generator_.GetGeneratedID(
299 params.device_id * kNumTouchEvdevSlots + params.slot); 331 params.device_id * kNumTouchEvdevSlots + params.slot);
300 TouchEvent touch_event( 332 TouchEvent touch_event(
301 params.type, gfx::Point(), modifiers_.GetModifierFlags(), touch_id, 333 params.type, gfx::Point(), modifiers_.GetModifierFlags(), touch_id,
302 params.timestamp, /* radius_x */ 0.f, /* radius_y */ 0.f, 334 params.timestamp, /* radius_x */ 0.f, /* radius_y */ 0.f,
303 /* angle */ 0.f, /* force */ 0.f); 335 /* angle */ 0.f, /* force */ 0.f);
304 touch_event.set_location_f(gfx::PointF(x, y)); 336 touch_event.set_location_f(location);
305 touch_event.set_root_location_f(gfx::PointF(x, y)); 337 touch_event.set_root_location_f(location);
306 touch_event.set_source_device_id(params.device_id); 338 touch_event.set_source_device_id(params.device_id);
307 touch_event.set_pointer_details(details); 339 touch_event.set_pointer_details(details);
308 DispatchUiEvent(&touch_event); 340 DispatchUiEvent(&touch_event);
309 341
310 if (params.type == ET_TOUCH_RELEASED || params.type == ET_TOUCH_CANCELLED) { 342 if (params.type == ET_TOUCH_RELEASED || params.type == ET_TOUCH_CANCELLED) {
311 touch_id_generator_.ReleaseGeneratedID(touch_event.touch_id()); 343 touch_id_generator_.ReleaseGeneratedID(touch_event.touch_id());
312 } 344 }
313 } 345 }
314 346
315 void EventFactoryEvdev::DispatchUiEvent(Event* event) { 347 void EventFactoryEvdev::DispatchUiEvent(Event* event) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (!cursor_) 421 if (!cursor_)
390 return; 422 return;
391 423
392 cursor_->MoveCursorTo(widget, location); 424 cursor_->MoveCursorTo(widget, location);
393 425
394 base::ThreadTaskRunnerHandle::Get()->PostTask( 426 base::ThreadTaskRunnerHandle::Get()->PostTask(
395 FROM_HERE, 427 FROM_HERE,
396 base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent, 428 base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent,
397 weak_ptr_factory_.GetWeakPtr(), 429 weak_ptr_factory_.GetWeakPtr(),
398 MouseMoveEventParams( 430 MouseMoveEventParams(
399 -1 /* device_id */, cursor_->GetLocation(), 431 -1 /* device_id */, EF_NONE, cursor_->GetLocation(),
400 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), 432 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE),
401 EventTimeForNow()))); 433 EventTimeForNow())));
402 } 434 }
403 435
404 int EventFactoryEvdev::NextDeviceId() { 436 int EventFactoryEvdev::NextDeviceId() {
405 return ++last_device_id_; 437 return ++last_device_id_;
406 } 438 }
407 439
408 void EventFactoryEvdev::StartThread() { 440 void EventFactoryEvdev::StartThread() {
409 // Set up device factory. 441 // Set up device factory.
(...skipping 15 matching lines...) Expand all
425 457
426 // Scan & monitor devices. 458 // Scan & monitor devices.
427 device_manager_->AddObserver(this); 459 device_manager_->AddObserver(this);
428 device_manager_->ScanDevices(this); 460 device_manager_->ScanDevices(this);
429 461
430 // Notify device thread that initial scan is done. 462 // Notify device thread that initial scan is done.
431 input_device_factory_proxy_->OnStartupScanComplete(); 463 input_device_factory_proxy_->OnStartupScanComplete();
432 } 464 }
433 465
434 } // namespace ui 466 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698