OLD | NEW |
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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 GetChangedMouseButtonFlagsFromNative(native_event)) { | 323 GetChangedMouseButtonFlagsFromNative(native_event)) { |
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 const PointerEventDetails& details) |
334 : LocatedEvent(type, location, root_location, time_stamp, flags), | 335 : LocatedEvent(type, location, root_location, time_stamp, flags), |
335 changed_button_flags_(changed_button_flags) { | 336 changed_button_flags_(changed_button_flags), |
| 337 pointer_details_(details) { |
336 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) | 338 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) |
337 SetType(ET_MOUSE_DRAGGED); | 339 SetType(ET_MOUSE_DRAGGED); |
338 } | 340 } |
339 | 341 |
340 // static | 342 // static |
341 bool MouseEvent::IsRepeatedClickEvent( | 343 bool MouseEvent::IsRepeatedClickEvent( |
342 const MouseEvent& event1, | 344 const MouseEvent& event1, |
343 const MouseEvent& event2) { | 345 const MouseEvent& event2) { |
344 // These values match the Windows defaults. | 346 // These values match the Windows defaults. |
345 static const int kDoubleClickTimeMS = 500; | 347 static const int kDoubleClickTimeMS = 500; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 const gfx::PointF& location, | 489 const gfx::PointF& location, |
488 const gfx::PointF& root_location, | 490 const gfx::PointF& root_location, |
489 base::TimeDelta time_stamp, | 491 base::TimeDelta time_stamp, |
490 int flags, | 492 int flags, |
491 int changed_button_flags) | 493 int changed_button_flags) |
492 : MouseEvent(ui::ET_MOUSEWHEEL, | 494 : MouseEvent(ui::ET_MOUSEWHEEL, |
493 location, | 495 location, |
494 root_location, | 496 root_location, |
495 time_stamp, | 497 time_stamp, |
496 flags, | 498 flags, |
497 changed_button_flags), | 499 changed_button_flags, |
498 offset_(offset) { | 500 PointerEventDetails(EventPointerType::POINTER_TYPE_MOUSE)), |
499 } | 501 offset_(offset) {} |
500 | 502 |
501 #if defined(OS_WIN) | 503 #if defined(OS_WIN) |
502 // This value matches windows WHEEL_DELTA. | 504 // This value matches windows WHEEL_DELTA. |
503 // static | 505 // static |
504 const int MouseWheelEvent::kWheelDelta = 120; | 506 const int MouseWheelEvent::kWheelDelta = 120; |
505 #else | 507 #else |
506 // This value matches GTK+ wheel scroll amount. | 508 // This value matches GTK+ wheel scroll amount. |
507 const int MouseWheelEvent::kWheelDelta = 53; | 509 const int MouseWheelEvent::kWheelDelta = 53; |
508 #endif | 510 #endif |
509 | 511 |
510 //////////////////////////////////////////////////////////////////////////////// | 512 //////////////////////////////////////////////////////////////////////////////// |
511 // TouchEvent | 513 // TouchEvent |
512 | 514 |
513 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 515 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
514 : LocatedEvent(native_event), | 516 : LocatedEvent(native_event), |
515 touch_id_(GetTouchId(native_event)), | 517 touch_id_(GetTouchId(native_event)), |
516 unique_event_id_(ui::GetNextTouchEventId()), | 518 unique_event_id_(ui::GetNextTouchEventId()), |
517 radius_x_(GetTouchRadiusX(native_event)), | |
518 radius_y_(GetTouchRadiusY(native_event)), | |
519 rotation_angle_(GetTouchAngle(native_event)), | 519 rotation_angle_(GetTouchAngle(native_event)), |
520 force_(GetTouchForce(native_event)), | |
521 may_cause_scrolling_(false), | 520 may_cause_scrolling_(false), |
522 should_remove_native_touch_id_mapping_(false) { | 521 should_remove_native_touch_id_mapping_(false), |
| 522 pointer_details_(PointerEventDetails(EventPointerType::POINTER_TYPE_TOUCH, |
| 523 GetTouchRadiusX(native_event), |
| 524 GetTouchRadiusY(native_event), |
| 525 GetTouchForce(native_event), |
| 526 /* tilt_x */ 0.0f, |
| 527 /* tilt_y */ 0.0f)) { |
523 latency()->AddLatencyNumberWithTimestamp( | 528 latency()->AddLatencyNumberWithTimestamp( |
524 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, | 529 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, |
525 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); | 530 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); |
526 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 531 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
527 | 532 |
528 FixRotationAngle(); | 533 FixRotationAngle(); |
529 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) | 534 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) |
530 should_remove_native_touch_id_mapping_ = true; | 535 should_remove_native_touch_id_mapping_ = true; |
531 } | 536 } |
532 | 537 |
533 TouchEvent::TouchEvent(EventType type, | 538 TouchEvent::TouchEvent(EventType type, |
534 const gfx::PointF& location, | 539 const gfx::PointF& location, |
535 int touch_id, | 540 int touch_id, |
536 base::TimeDelta time_stamp) | 541 base::TimeDelta time_stamp) |
537 : LocatedEvent(type, location, location, time_stamp, 0), | 542 : LocatedEvent(type, location, location, time_stamp, 0), |
538 touch_id_(touch_id), | 543 touch_id_(touch_id), |
539 unique_event_id_(ui::GetNextTouchEventId()), | 544 unique_event_id_(ui::GetNextTouchEventId()), |
540 radius_x_(0.0f), | |
541 radius_y_(0.0f), | |
542 rotation_angle_(0.0f), | 545 rotation_angle_(0.0f), |
543 force_(0.0f), | |
544 may_cause_scrolling_(false), | 546 may_cause_scrolling_(false), |
545 should_remove_native_touch_id_mapping_(false) { | 547 should_remove_native_touch_id_mapping_(false), |
| 548 pointer_details_( |
| 549 PointerEventDetails(EventPointerType::POINTER_TYPE_TOUCH)) { |
546 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 550 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
547 } | 551 } |
548 | 552 |
549 TouchEvent::TouchEvent(EventType type, | 553 TouchEvent::TouchEvent(EventType type, |
550 const gfx::PointF& location, | 554 const gfx::PointF& location, |
551 int flags, | 555 int flags, |
552 int touch_id, | 556 int touch_id, |
553 base::TimeDelta time_stamp, | 557 base::TimeDelta time_stamp, |
554 float radius_x, | |
555 float radius_y, | |
556 float angle, | 558 float angle, |
557 float force) | 559 const PointerEventDetails& details) |
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_(details) { |
567 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 567 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
568 FixRotationAngle(); | 568 FixRotationAngle(); |
569 } | 569 } |
570 | 570 |
571 TouchEvent::TouchEvent(const TouchEvent& copy) | 571 TouchEvent::TouchEvent(const TouchEvent& copy) |
572 : LocatedEvent(copy), | 572 : LocatedEvent(copy), |
573 touch_id_(copy.touch_id_), | 573 touch_id_(copy.touch_id_), |
574 unique_event_id_(copy.unique_event_id_), | 574 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_), | 575 rotation_angle_(copy.rotation_angle_), |
578 force_(copy.force_), | |
579 may_cause_scrolling_(copy.may_cause_scrolling_), | 576 may_cause_scrolling_(copy.may_cause_scrolling_), |
580 should_remove_native_touch_id_mapping_(false) { | 577 should_remove_native_touch_id_mapping_(false), |
| 578 pointer_details_(copy.pointer_details_) { |
581 // Copied events should not remove touch id mapping, as this either causes the | 579 // 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 | 580 // 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_|. | 581 // the copy to attempt to remove the mapping from a null |native_event_|. |
584 } | 582 } |
585 | 583 |
586 TouchEvent::~TouchEvent() { | 584 TouchEvent::~TouchEvent() { |
587 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 | 585 // In ctor TouchEvent(native_event) we call GetTouchId() which in X11 |
588 // platform setups the tracking_id to slot mapping. So in dtor here, | 586 // 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. | 587 // if this touch event is a release event, we clear the mapping accordingly. |
590 if (should_remove_native_touch_id_mapping_) { | 588 if (should_remove_native_touch_id_mapping_) { |
591 DCHECK(type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED); | 589 DCHECK(type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED); |
592 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) | 590 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) |
593 ClearTouchIdIfReleased(native_event()); | 591 ClearTouchIdIfReleased(native_event()); |
594 } | 592 } |
595 } | 593 } |
596 | 594 |
597 void TouchEvent::UpdateForRootTransform( | 595 void TouchEvent::UpdateForRootTransform( |
598 const gfx::Transform& inverted_root_transform) { | 596 const gfx::Transform& inverted_root_transform) { |
599 LocatedEvent::UpdateForRootTransform(inverted_root_transform); | 597 LocatedEvent::UpdateForRootTransform(inverted_root_transform); |
600 gfx::DecomposedTransform decomp; | 598 gfx::DecomposedTransform decomp; |
601 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform); | 599 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform); |
602 DCHECK(success); | 600 DCHECK(success); |
603 if (decomp.scale[0]) | 601 if (decomp.scale[0]) |
604 radius_x_ *= decomp.scale[0]; | 602 pointer_details_.radius_x_ *= decomp.scale[0]; |
605 if (decomp.scale[1]) | 603 if (decomp.scale[1]) |
606 radius_y_ *= decomp.scale[1]; | 604 pointer_details_.radius_y_ *= decomp.scale[1]; |
607 } | 605 } |
608 | 606 |
609 void TouchEvent::DisableSynchronousHandling() { | 607 void TouchEvent::DisableSynchronousHandling() { |
610 DispatcherApi dispatcher_api(this); | 608 DispatcherApi dispatcher_api(this); |
611 dispatcher_api.set_result( | 609 dispatcher_api.set_result( |
612 static_cast<EventResult>(result() | ER_DISABLE_SYNC_HANDLING)); | 610 static_cast<EventResult>(result() | ER_DISABLE_SYNC_HANDLING)); |
613 } | 611 } |
614 | 612 |
615 void TouchEvent::FixRotationAngle() { | 613 void TouchEvent::FixRotationAngle() { |
616 while (rotation_angle_ < 0) | 614 while (rotation_angle_ < 0) |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 | 935 |
938 ScrollEvent::ScrollEvent(EventType type, | 936 ScrollEvent::ScrollEvent(EventType type, |
939 const gfx::PointF& location, | 937 const gfx::PointF& location, |
940 base::TimeDelta time_stamp, | 938 base::TimeDelta time_stamp, |
941 int flags, | 939 int flags, |
942 float x_offset, | 940 float x_offset, |
943 float y_offset, | 941 float y_offset, |
944 float x_offset_ordinal, | 942 float x_offset_ordinal, |
945 float y_offset_ordinal, | 943 float y_offset_ordinal, |
946 int finger_count) | 944 int finger_count) |
947 : MouseEvent(type, location, location, time_stamp, flags, 0), | 945 : MouseEvent(type, |
| 946 location, |
| 947 location, |
| 948 time_stamp, |
| 949 flags, |
| 950 0, |
| 951 PointerEventDetails(EventPointerType::POINTER_TYPE_MOUSE)), |
948 x_offset_(x_offset), | 952 x_offset_(x_offset), |
949 y_offset_(y_offset), | 953 y_offset_(y_offset), |
950 x_offset_ordinal_(x_offset_ordinal), | 954 x_offset_ordinal_(x_offset_ordinal), |
951 y_offset_ordinal_(y_offset_ordinal), | 955 y_offset_ordinal_(y_offset_ordinal), |
952 finger_count_(finger_count) { | 956 finger_count_(finger_count) { |
953 CHECK(IsScrollEvent()); | 957 CHECK(IsScrollEvent()); |
954 } | 958 } |
955 | 959 |
956 void ScrollEvent::Scale(const float factor) { | 960 void ScrollEvent::Scale(const float factor) { |
957 x_offset_ *= factor; | 961 x_offset_ *= factor; |
(...skipping 15 matching lines...) Expand all Loading... |
973 gfx::PointF(x, y), | 977 gfx::PointF(x, y), |
974 time_stamp, | 978 time_stamp, |
975 flags | EF_FROM_TOUCH), | 979 flags | EF_FROM_TOUCH), |
976 details_(details) { | 980 details_(details) { |
977 } | 981 } |
978 | 982 |
979 GestureEvent::~GestureEvent() { | 983 GestureEvent::~GestureEvent() { |
980 } | 984 } |
981 | 985 |
982 } // namespace ui | 986 } // namespace ui |
OLD | NEW |