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

Side by Side Diff: ui/events/event.cc

Issue 1260453006: ui: events: Add a class to hold common touch and stylus properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move mutators to MouseEvent/TouchEvent Created 5 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
« no previous file with comments | « ui/events/event.h ('k') | ui/events/event_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/event.h" 5 #include "ui/events/event.h"
6 6
7 #if defined(USE_X11) 7 #if defined(USE_X11)
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/keysym.h> 9 #include <X11/keysym.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 reversed_root_transform.TransformPoint(&p); 312 reversed_root_transform.TransformPoint(&p);
313 location_ = p.AsPointF(); 313 location_ = p.AsPointF();
314 root_location_ = location_; 314 root_location_ = location_;
315 } 315 }
316 316
317 //////////////////////////////////////////////////////////////////////////////// 317 ////////////////////////////////////////////////////////////////////////////////
318 // MouseEvent 318 // MouseEvent
319 319
320 MouseEvent::MouseEvent(const base::NativeEvent& native_event) 320 MouseEvent::MouseEvent(const base::NativeEvent& native_event)
321 : LocatedEvent(native_event), 321 : LocatedEvent(native_event),
322 changed_button_flags_( 322 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)),
323 GetChangedMouseButtonFlagsFromNative(native_event)) { 323 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) {
324 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED) 324 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED)
325 SetClickCount(GetRepeatCount(*this)); 325 SetClickCount(GetRepeatCount(*this));
326 } 326 }
327 327
328 MouseEvent::MouseEvent(EventType type, 328 MouseEvent::MouseEvent(EventType type,
329 const gfx::PointF& location, 329 const gfx::PointF& location,
330 const gfx::PointF& root_location, 330 const gfx::PointF& root_location,
331 base::TimeDelta time_stamp, 331 base::TimeDelta time_stamp,
332 int flags, 332 int flags,
333 int changed_button_flags) 333 int changed_button_flags)
334 : LocatedEvent(type, location, root_location, time_stamp, flags), 334 : LocatedEvent(type, location, root_location, time_stamp, flags),
335 changed_button_flags_(changed_button_flags) { 335 changed_button_flags_(changed_button_flags),
336 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) {
336 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) 337 if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
337 SetType(ET_MOUSE_DRAGGED); 338 SetType(ET_MOUSE_DRAGGED);
338 } 339 }
339 340
340 // static 341 // static
341 bool MouseEvent::IsRepeatedClickEvent( 342 bool MouseEvent::IsRepeatedClickEvent(
342 const MouseEvent& event1, 343 const MouseEvent& event1,
343 const MouseEvent& event2) { 344 const MouseEvent& event2) {
344 // These values match the Windows defaults. 345 // These values match the Windows defaults.
345 static const int kDoubleClickTimeMS = 500; 346 static const int kDoubleClickTimeMS = 500;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 const int MouseWheelEvent::kWheelDelta = 53; 508 const int MouseWheelEvent::kWheelDelta = 53;
508 #endif 509 #endif
509 510
510 //////////////////////////////////////////////////////////////////////////////// 511 ////////////////////////////////////////////////////////////////////////////////
511 // TouchEvent 512 // TouchEvent
512 513
513 TouchEvent::TouchEvent(const base::NativeEvent& native_event) 514 TouchEvent::TouchEvent(const base::NativeEvent& native_event)
514 : LocatedEvent(native_event), 515 : LocatedEvent(native_event),
515 touch_id_(GetTouchId(native_event)), 516 touch_id_(GetTouchId(native_event)),
516 unique_event_id_(ui::GetNextTouchEventId()), 517 unique_event_id_(ui::GetNextTouchEventId()),
517 radius_x_(GetTouchRadiusX(native_event)),
518 radius_y_(GetTouchRadiusY(native_event)),
519 rotation_angle_(GetTouchAngle(native_event)), 518 rotation_angle_(GetTouchAngle(native_event)),
520 force_(GetTouchForce(native_event)),
521 may_cause_scrolling_(false), 519 may_cause_scrolling_(false),
522 should_remove_native_touch_id_mapping_(false) { 520 should_remove_native_touch_id_mapping_(false),
521 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH,
522 GetTouchRadiusX(native_event),
523 GetTouchRadiusY(native_event),
524 GetTouchForce(native_event),
525 /* tilt_x */ 0.0f,
526 /* tilt_y */ 0.0f)) {
523 latency()->AddLatencyNumberWithTimestamp( 527 latency()->AddLatencyNumberWithTimestamp(
524 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, 528 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0,
525 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); 529 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1);
526 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 530 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
527 531
528 FixRotationAngle(); 532 FixRotationAngle();
529 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) 533 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED)
530 should_remove_native_touch_id_mapping_ = true; 534 should_remove_native_touch_id_mapping_ = true;
531 } 535 }
532 536
533 TouchEvent::TouchEvent(EventType type, 537 TouchEvent::TouchEvent(EventType type,
534 const gfx::PointF& location, 538 const gfx::PointF& location,
535 int touch_id, 539 int touch_id,
536 base::TimeDelta time_stamp) 540 base::TimeDelta time_stamp)
537 : LocatedEvent(type, location, location, time_stamp, 0), 541 : LocatedEvent(type, location, location, time_stamp, 0),
538 touch_id_(touch_id), 542 touch_id_(touch_id),
539 unique_event_id_(ui::GetNextTouchEventId()), 543 unique_event_id_(ui::GetNextTouchEventId()),
540 radius_x_(0.0f),
541 radius_y_(0.0f),
542 rotation_angle_(0.0f), 544 rotation_angle_(0.0f),
543 force_(0.0f),
544 may_cause_scrolling_(false), 545 may_cause_scrolling_(false),
545 should_remove_native_touch_id_mapping_(false) { 546 should_remove_native_touch_id_mapping_(false),
547 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) {
546 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 548 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
547 } 549 }
548 550
549 TouchEvent::TouchEvent(EventType type, 551 TouchEvent::TouchEvent(EventType type,
550 const gfx::PointF& location, 552 const gfx::PointF& location,
551 int flags, 553 int flags,
552 int touch_id, 554 int touch_id,
553 base::TimeDelta time_stamp, 555 base::TimeDelta time_stamp,
554 float radius_x, 556 float radius_x,
555 float radius_y, 557 float radius_y,
556 float angle, 558 float angle,
557 float force) 559 float force)
558 : LocatedEvent(type, location, location, time_stamp, flags), 560 : LocatedEvent(type, location, location, time_stamp, flags),
559 touch_id_(touch_id), 561 touch_id_(touch_id),
560 unique_event_id_(ui::GetNextTouchEventId()), 562 unique_event_id_(ui::GetNextTouchEventId()),
561 radius_x_(radius_x),
562 radius_y_(radius_y),
563 rotation_angle_(angle), 563 rotation_angle_(angle),
564 force_(force),
565 may_cause_scrolling_(false), 564 may_cause_scrolling_(false),
566 should_remove_native_touch_id_mapping_(false) { 565 should_remove_native_touch_id_mapping_(false),
566 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH,
567 radius_x,
568 radius_y,
569 force,
570 /* tilt_x */ 0.0f,
571 /* tilt_y */ 0.0f)) {
567 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 572 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
568 FixRotationAngle(); 573 FixRotationAngle();
569 } 574 }
570 575
571 TouchEvent::TouchEvent(const TouchEvent& copy) 576 TouchEvent::TouchEvent(const TouchEvent& copy)
572 : LocatedEvent(copy), 577 : LocatedEvent(copy),
573 touch_id_(copy.touch_id_), 578 touch_id_(copy.touch_id_),
574 unique_event_id_(copy.unique_event_id_), 579 unique_event_id_(copy.unique_event_id_),
575 radius_x_(copy.radius_x_),
576 radius_y_(copy.radius_y_),
577 rotation_angle_(copy.rotation_angle_), 580 rotation_angle_(copy.rotation_angle_),
578 force_(copy.force_),
579 may_cause_scrolling_(copy.may_cause_scrolling_), 581 may_cause_scrolling_(copy.may_cause_scrolling_),
580 should_remove_native_touch_id_mapping_(false) { 582 should_remove_native_touch_id_mapping_(false),
583 pointer_details_(copy.pointer_details_) {
581 // Copied events should not remove touch id mapping, as this either causes the 584 // Copied events should not remove touch id mapping, as this either causes the
582 // mapping to be lost before the initial event has finished dispatching, or 585 // mapping to be lost before the initial event has finished dispatching, or
583 // the copy to attempt to remove the mapping from a null |native_event_|. 586 // the copy to attempt to remove the mapping from a null |native_event_|.
584 } 587 }
585 588
586 TouchEvent::~TouchEvent() { 589 TouchEvent::~TouchEvent() {
587 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 590 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11
588 // platform setups the tracking_id to slot mapping. So in dtor here, 591 // platform setups the tracking_id to slot mapping. So in dtor here,
589 // if this touch event is a release event, we clear the mapping accordingly. 592 // if this touch event is a release event, we clear the mapping accordingly.
590 if (should_remove_native_touch_id_mapping_) { 593 if (should_remove_native_touch_id_mapping_) {
591 DCHECK(type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED); 594 DCHECK(type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED);
592 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) 595 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED)
593 ClearTouchIdIfReleased(native_event()); 596 ClearTouchIdIfReleased(native_event());
594 } 597 }
595 } 598 }
596 599
597 void TouchEvent::UpdateForRootTransform( 600 void TouchEvent::UpdateForRootTransform(
598 const gfx::Transform& inverted_root_transform) { 601 const gfx::Transform& inverted_root_transform) {
599 LocatedEvent::UpdateForRootTransform(inverted_root_transform); 602 LocatedEvent::UpdateForRootTransform(inverted_root_transform);
600 gfx::DecomposedTransform decomp; 603 gfx::DecomposedTransform decomp;
601 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform); 604 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform);
602 DCHECK(success); 605 DCHECK(success);
603 if (decomp.scale[0]) 606 if (decomp.scale[0])
604 radius_x_ *= decomp.scale[0]; 607 pointer_details_.radius_x_ *= decomp.scale[0];
605 if (decomp.scale[1]) 608 if (decomp.scale[1])
606 radius_y_ *= decomp.scale[1]; 609 pointer_details_.radius_y_ *= decomp.scale[1];
607 } 610 }
608 611
609 void TouchEvent::DisableSynchronousHandling() { 612 void TouchEvent::DisableSynchronousHandling() {
610 DispatcherApi dispatcher_api(this); 613 DispatcherApi dispatcher_api(this);
611 dispatcher_api.set_result( 614 dispatcher_api.set_result(
612 static_cast<EventResult>(result() | ER_DISABLE_SYNC_HANDLING)); 615 static_cast<EventResult>(result() | ER_DISABLE_SYNC_HANDLING));
613 } 616 }
614 617
615 void TouchEvent::FixRotationAngle() { 618 void TouchEvent::FixRotationAngle() {
616 while (rotation_angle_ < 0) 619 while (rotation_angle_ < 0)
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 gfx::PointF(x, y), 976 gfx::PointF(x, y),
974 time_stamp, 977 time_stamp,
975 flags | EF_FROM_TOUCH), 978 flags | EF_FROM_TOUCH),
976 details_(details) { 979 details_(details) {
977 } 980 }
978 981
979 GestureEvent::~GestureEvent() { 982 GestureEvent::~GestureEvent() {
980 } 983 }
981 984
982 } // namespace ui 985 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event.h ('k') | ui/events/event_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698