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

Side by Side Diff: ui/events/ozone/evdev/touch_event_converter_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/touch_event_converter_evdev.h" 5 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/input.h> 9 #include <linux/input.h>
10 #include <poll.h> 10 #include <poll.h>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return ABS_MT_POSITION_Y; 71 return ABS_MT_POSITION_Y;
72 case ABS_PRESSURE: 72 case ABS_PRESSURE:
73 return ABS_MT_PRESSURE; 73 return ABS_MT_PRESSURE;
74 case ABS_DISTANCE: 74 case ABS_DISTANCE:
75 return ABS_MT_DISTANCE; 75 return ABS_MT_DISTANCE;
76 default: 76 default:
77 return -1; 77 return -1;
78 } 78 }
79 } 79 }
80 80
81 ui::EventPointerType GetPointerTypeFromEvent( 81 ui::PointerDetails GetEventPointerDetails(
82 const ui::InProgressTouchEvdev& event) { 82 const ui::InProgressTouchEvdev& event) {
83 return (event.tool_code == BTN_TOOL_PEN) 83 ui::EventPointerType type;
84 ? ui::EventPointerType::POINTER_TYPE_PEN 84 switch (event.tool_code) {
85 : ui::EventPointerType::POINTER_TYPE_TOUCH; 85 case BTN_TOOL_PEN:
86 type = ui::EventPointerType::POINTER_TYPE_PEN;
87 break;
88 default:
89 type = ui::EventPointerType::POINTER_TYPE_TOUCH;
90 }
91 return ui::PointerDetails(type, event.radius_x, event.radius_y,
92 event.pressure,
93 /* tilt_x */ 0.0f,
94 /* tilt_y */ 0.0f);
86 } 95 }
87 96
88 const int kTrackingIdForUnusedSlot = -1; 97 const int kTrackingIdForUnusedSlot = -1;
89 98
90 } // namespace 99 } // namespace
91 100
92 namespace ui { 101 namespace ui {
93 102
94 TouchEventConverterEvdev::TouchEventConverterEvdev( 103 TouchEventConverterEvdev::TouchEventConverterEvdev(
95 int fd, 104 int fd,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 event.value ? NextTrackingId() : kTrackingIdForUnusedSlot; 319 event.value ? NextTrackingId() : kTrackingIdForUnusedSlot;
311 ProcessMultitouchEvent(emulated_event); 320 ProcessMultitouchEvent(emulated_event);
312 } 321 }
313 } 322 }
314 } 323 }
315 324
316 void TouchEventConverterEvdev::ProcessKey(const input_event& input) { 325 void TouchEventConverterEvdev::ProcessKey(const input_event& input) {
317 switch (input.code) { 326 switch (input.code) {
318 case BTN_TOUCH: 327 case BTN_TOUCH:
319 case BTN_LEFT: 328 case BTN_LEFT:
329 ProcessButton(BTN_LEFT, input);
330 break;
331 case BTN_STYLUS:
332 ProcessButton(BTN_RIGHT, input);
333 break;
334 case BTN_STYLUS2:
335 ProcessButton(BTN_MIDDLE, input);
320 break; 336 break;
321 case BTN_TOOL_PEN: 337 case BTN_TOOL_PEN:
338 // Do not change tool types while touching to prevent inconsistencies
339 // from switching between Mouse and TouchEvents.
340 if (events_[current_slot_].was_touching)
spang 2016/08/16 21:36:21 Does this actually happen?
denniskempin 2016/08/17 21:47:17 I think a kernel driver shouldn't be allowed to do
341 break;
342
322 if (input.value > 0) { 343 if (input.value > 0) {
323 events_[current_slot_].tool_code = input.code; 344 events_[current_slot_].tool_code = input.code;
324 } else { 345 } else {
325 events_[current_slot_].tool_code = 0; 346 events_[current_slot_].tool_code = 0;
326 } 347 }
327 break; 348 break;
328 default: 349 default:
329 NOTIMPLEMENTED() << "invalid code for EV_KEY: " << input.code; 350 NOTIMPLEMENTED() << "invalid code for EV_KEY: " << input.code;
330 } 351 }
331 } 352 }
332 353
354 void TouchEventConverterEvdev::ProcessButton(unsigned int button,
355 const input_event& input) {
356 const InProgressTouchEvdev& event = events_[current_slot_];
357
358 // Don't handle buttons for touch slots
359 if (event.tool_code == 0)
360 return;
361
362 bool down = input.value;
363 dispatcher_->DispatchMouseButtonEvent(MouseButtonEventParams(
364 input_device_.id, EF_DIRECT_INPUT, gfx::PointF(event.x, event.y), button,
spang 2016/08/16 21:36:21 There's no guarantee the X/Y position is updated b
denniskempin 2016/08/17 21:47:17 Done.
365 down, false /* allow_remap */, GetEventPointerDetails(event),
366 TimeTicksFromInputEvent(input)));
367 }
368
333 void TouchEventConverterEvdev::ProcessAbs(const input_event& input) { 369 void TouchEventConverterEvdev::ProcessAbs(const input_event& input) {
334 switch (input.code) { 370 switch (input.code) {
335 case ABS_MT_TOUCH_MAJOR: 371 case ABS_MT_TOUCH_MAJOR:
336 // TODO(spang): If we have all of major, minor, and orientation, 372 // TODO(spang): If we have all of major, minor, and orientation,
337 // we can scale the ellipse correctly. However on the Pixel we get 373 // we can scale the ellipse correctly. However on the Pixel we get
338 // neither minor nor orientation, so this is all we can do. 374 // neither minor nor orientation, so this is all we can do.
339 events_[current_slot_].radius_x = input.value / 2.0f; 375 events_[current_slot_].radius_x = input.value / 2.0f;
340 break; 376 break;
341 case ABS_MT_TOUCH_MINOR: 377 case ABS_MT_TOUCH_MINOR:
342 events_[current_slot_].radius_y = input.value / 2.0f; 378 events_[current_slot_].radius_y = input.value / 2.0f;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 if (touch.touching && !touch.was_touching) 429 if (touch.touching && !touch.was_touching)
394 return ET_UNKNOWN; 430 return ET_UNKNOWN;
395 return ET_TOUCH_CANCELLED; 431 return ET_TOUCH_CANCELLED;
396 } 432 }
397 433
398 if (touch.touching) 434 if (touch.touching)
399 return touch.was_touching ? ET_TOUCH_MOVED : ET_TOUCH_PRESSED; 435 return touch.was_touching ? ET_TOUCH_MOVED : ET_TOUCH_PRESSED;
400 return touch.was_touching ? ET_TOUCH_RELEASED : ET_UNKNOWN; 436 return touch.was_touching ? ET_TOUCH_RELEASED : ET_UNKNOWN;
401 } 437 }
402 438
403 void TouchEventConverterEvdev::ReportEvent(const InProgressTouchEvdev& event, 439 void TouchEventConverterEvdev::ReportTouchEvent(
404 EventType event_type, 440 const InProgressTouchEvdev& event,
405 base::TimeTicks timestamp) { 441 EventType event_type,
406 PointerDetails details(GetPointerTypeFromEvent(event), event.radius_x, 442 base::TimeTicks timestamp) {
407 event.radius_y, event.pressure, 443 dispatcher_->DispatchTouchEvent(TouchEventParams(
408 /* tilt_x */ 0.0f, 444 input_device_.id, event.slot, event_type, gfx::PointF(event.x, event.y),
409 /* tilt_y */ 0.0f); 445 GetEventPointerDetails(event), timestamp));
410 dispatcher_->DispatchTouchEvent( 446 }
411 TouchEventParams(input_device_.id, event.slot, event_type, 447
412 gfx::PointF(event.x, event.y), details, timestamp)); 448 void TouchEventConverterEvdev::ReportStylusEvent(
449 const InProgressTouchEvdev& event,
450 base::TimeTicks timestamp) {
451 dispatcher_->DispatchMouseMoveEvent(MouseMoveEventParams(
452 input_device_.id, EF_DIRECT_INPUT, gfx::PointF(event.x, event.y),
453 GetEventPointerDetails(event), timestamp));
413 } 454 }
414 455
415 void TouchEventConverterEvdev::ReportEvents(base::TimeTicks timestamp) { 456 void TouchEventConverterEvdev::ReportEvents(base::TimeTicks timestamp) {
416 if (dropped_events_) { 457 if (dropped_events_) {
417 Reinitialize(); 458 Reinitialize();
418 dropped_events_ = false; 459 dropped_events_ = false;
419 } 460 }
420 461
421 if (touch_noise_finder_) 462 if (touch_noise_finder_)
422 touch_noise_finder_->HandleTouches(events_, timestamp); 463 touch_noise_finder_->HandleTouches(events_, timestamp);
423 464
424 for (size_t i = 0; i < events_.size(); i++) { 465 for (size_t i = 0; i < events_.size(); i++) {
425 InProgressTouchEvdev* event = &events_[i]; 466 InProgressTouchEvdev* event = &events_[i];
426 if (!event->altered) 467 if (!event->altered)
427 continue; 468 continue;
428 469
429 EventType event_type = GetEventTypeForTouch(*event); 470 if (event->tool_code > 0) {
430 if (event_type == ET_UNKNOWN || event_type == ET_TOUCH_CANCELLED) 471 ReportStylusEvent(*event, timestamp);
431 event->cancelled = true; 472 } else {
473 EventType event_type = GetEventTypeForTouch(*event);
474 if (event_type == ET_UNKNOWN || event_type == ET_TOUCH_CANCELLED)
475 event->cancelled = true;
432 476
433 if (event_type != ET_UNKNOWN) 477 if (event_type != ET_UNKNOWN)
434 ReportEvent(*event, event_type, timestamp); 478 ReportTouchEvent(*event, event_type, timestamp);
479 }
435 480
436 event->was_touching = event->touching; 481 event->was_touching = event->touching;
437 event->altered = false; 482 event->altered = false;
438 } 483 }
439 } 484 }
440 485
441 void TouchEventConverterEvdev::UpdateTrackingId(int slot, int tracking_id) { 486 void TouchEventConverterEvdev::UpdateTrackingId(int slot, int tracking_id) {
442 InProgressTouchEvdev* event = &events_[slot]; 487 InProgressTouchEvdev* event = &events_[slot];
443 488
444 if (event->tracking_id == tracking_id) 489 if (event->tracking_id == tracking_id)
(...skipping 19 matching lines...) Expand all
464 if (pressure_max_ - pressure_min_) 509 if (pressure_max_ - pressure_min_)
465 pressure /= pressure_max_ - pressure_min_; 510 pressure /= pressure_max_ - pressure_min_;
466 return pressure; 511 return pressure;
467 } 512 }
468 513
469 int TouchEventConverterEvdev::NextTrackingId() { 514 int TouchEventConverterEvdev::NextTrackingId() {
470 return next_tracking_id_++ & kMaxTrackingId; 515 return next_tracking_id_++ & kMaxTrackingId;
471 } 516 }
472 517
473 } // namespace ui 518 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/touch_event_converter_evdev.h ('k') | ui/wm/core/compound_event_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698