Chromium Code Reviews| 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 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 | 10 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 root_location_ = location_; | 450 root_location_ = location_; |
| 451 } | 451 } |
| 452 | 452 |
| 453 //////////////////////////////////////////////////////////////////////////////// | 453 //////////////////////////////////////////////////////////////////////////////// |
| 454 // MouseEvent | 454 // MouseEvent |
| 455 | 455 |
| 456 MouseEvent::MouseEvent(const base::NativeEvent& native_event) | 456 MouseEvent::MouseEvent(const base::NativeEvent& native_event) |
| 457 : LocatedEvent(native_event), | 457 : LocatedEvent(native_event), |
| 458 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), | 458 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), |
| 459 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { | 459 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { |
| 460 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 460 latency()->AddLatencyNumberWithTimestamp( | 461 latency()->AddLatencyNumberWithTimestamp( |
| 461 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, | 462 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, |
| 462 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); | 463 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); |
| 463 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 464 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 464 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED) | 465 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED) |
| 465 SetClickCount(GetRepeatCount(*this)); | 466 SetClickCount(GetRepeatCount(*this)); |
| 466 } | 467 } |
| 467 | 468 |
| 468 MouseEvent::MouseEvent(const PointerEvent& pointer_event) | 469 MouseEvent::MouseEvent(const PointerEvent& pointer_event) |
| 469 : LocatedEvent(pointer_event), | 470 : LocatedEvent(pointer_event), |
| 470 changed_button_flags_(pointer_event.changed_button_flags()), | 471 changed_button_flags_(pointer_event.changed_button_flags()), |
| 471 pointer_details_(pointer_event.pointer_details()) { | 472 pointer_details_(pointer_event.pointer_details()) { |
| 473 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 472 DCHECK(pointer_event.IsMousePointerEvent()); | 474 DCHECK(pointer_event.IsMousePointerEvent()); |
| 473 switch (pointer_event.type()) { | 475 switch (pointer_event.type()) { |
| 474 case ET_POINTER_DOWN: | 476 case ET_POINTER_DOWN: |
| 475 SetType(ET_MOUSE_PRESSED); | 477 SetType(ET_MOUSE_PRESSED); |
| 476 break; | 478 break; |
| 477 | 479 |
| 478 case ET_POINTER_MOVED: | 480 case ET_POINTER_MOVED: |
| 479 if (pointer_event.flags() & | 481 if (pointer_event.flags() & |
| 480 (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | | 482 (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | |
| 481 EF_RIGHT_MOUSE_BUTTON)) { | 483 EF_RIGHT_MOUSE_BUTTON)) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 int flags, | 520 int flags, |
| 519 int changed_button_flags) | 521 int changed_button_flags) |
| 520 : LocatedEvent(type, | 522 : LocatedEvent(type, |
| 521 gfx::PointF(location), | 523 gfx::PointF(location), |
| 522 gfx::PointF(root_location), | 524 gfx::PointF(root_location), |
| 523 time_stamp, | 525 time_stamp, |
| 524 flags), | 526 flags), |
| 525 changed_button_flags_(changed_button_flags), | 527 changed_button_flags_(changed_button_flags), |
| 526 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { | 528 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { |
| 527 DCHECK_NE(ET_MOUSEWHEEL, type); | 529 DCHECK_NE(ET_MOUSEWHEEL, type); |
| 530 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 528 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 531 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 529 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) | 532 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) |
| 530 SetType(ET_MOUSE_DRAGGED); | 533 SetType(ET_MOUSE_DRAGGED); |
| 531 } | 534 } |
| 532 | 535 |
| 533 // static | 536 // static |
| 534 bool MouseEvent::IsRepeatedClickEvent( | 537 bool MouseEvent::IsRepeatedClickEvent( |
| 535 const MouseEvent& event1, | 538 const MouseEvent& event1, |
| 536 const MouseEvent& event2) { | 539 const MouseEvent& event2) { |
| 537 // These values match the Windows defaults. | 540 // These values match the Windows defaults. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 } | 650 } |
| 648 set_flags(f); | 651 set_flags(f); |
| 649 } | 652 } |
| 650 | 653 |
| 651 //////////////////////////////////////////////////////////////////////////////// | 654 //////////////////////////////////////////////////////////////////////////////// |
| 652 // MouseWheelEvent | 655 // MouseWheelEvent |
| 653 | 656 |
| 654 MouseWheelEvent::MouseWheelEvent(const base::NativeEvent& native_event) | 657 MouseWheelEvent::MouseWheelEvent(const base::NativeEvent& native_event) |
| 655 : MouseEvent(native_event), | 658 : MouseEvent(native_event), |
| 656 offset_(GetMouseWheelOffset(native_event)) { | 659 offset_(GetMouseWheelOffset(native_event)) { |
| 660 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | |
| 657 } | 661 } |
| 658 | 662 |
| 659 MouseWheelEvent::MouseWheelEvent(const ScrollEvent& scroll_event) | 663 MouseWheelEvent::MouseWheelEvent(const ScrollEvent& scroll_event) |
| 660 : MouseEvent(scroll_event), | 664 : MouseEvent(scroll_event), |
| 661 offset_(gfx::ToRoundedInt(scroll_event.x_offset()), | 665 offset_(gfx::ToRoundedInt(scroll_event.x_offset()), |
| 662 gfx::ToRoundedInt(scroll_event.y_offset())) { | 666 gfx::ToRoundedInt(scroll_event.y_offset())) { |
| 667 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | |
| 663 SetType(ET_MOUSEWHEEL); | 668 SetType(ET_MOUSEWHEEL); |
| 664 } | 669 } |
| 665 | 670 |
| 666 MouseWheelEvent::MouseWheelEvent(const PointerEvent& pointer_event) | 671 MouseWheelEvent::MouseWheelEvent(const PointerEvent& pointer_event) |
| 667 : MouseEvent(pointer_event), | 672 : MouseEvent(pointer_event), |
| 668 offset_(pointer_event.pointer_details().offset.x(), | 673 offset_(pointer_event.pointer_details().offset.x(), |
| 669 pointer_event.pointer_details().offset.y()) { | 674 pointer_event.pointer_details().offset.y()) { |
| 670 SetType(ET_MOUSEWHEEL); | 675 SetType(ET_MOUSEWHEEL); |
| 671 } | 676 } |
| 672 | 677 |
| 673 MouseWheelEvent::MouseWheelEvent(const MouseEvent& mouse_event, | 678 MouseWheelEvent::MouseWheelEvent(const MouseEvent& mouse_event, |
| 674 int x_offset, | 679 int x_offset, |
| 675 int y_offset) | 680 int y_offset) |
| 676 : MouseEvent(mouse_event), offset_(x_offset, y_offset) { | 681 : MouseEvent(mouse_event), offset_(x_offset, y_offset) { |
| 682 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | |
| 677 SetType(ET_MOUSEWHEEL); | 683 SetType(ET_MOUSEWHEEL); |
| 678 } | 684 } |
| 679 | 685 |
| 680 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event) | 686 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event) |
| 681 : MouseEvent(mouse_wheel_event), | 687 : MouseEvent(mouse_wheel_event), |
| 682 offset_(mouse_wheel_event.offset()) { | 688 offset_(mouse_wheel_event.offset()) { |
| 689 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | |
| 683 DCHECK_EQ(ET_MOUSEWHEEL, type()); | 690 DCHECK_EQ(ET_MOUSEWHEEL, type()); |
| 684 } | 691 } |
| 685 | 692 |
| 686 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, | 693 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, |
| 687 const gfx::Point& location, | 694 const gfx::Point& location, |
| 688 const gfx::Point& root_location, | 695 const gfx::Point& root_location, |
| 689 base::TimeTicks time_stamp, | 696 base::TimeTicks time_stamp, |
| 690 int flags, | 697 int flags, |
| 691 int changed_button_flags) | 698 int changed_button_flags) |
| 692 : MouseEvent(ui::ET_UNKNOWN, | 699 : MouseEvent(ui::ET_UNKNOWN, |
| 693 location, | 700 location, |
| 694 root_location, | 701 root_location, |
| 695 time_stamp, | 702 time_stamp, |
| 696 flags, | 703 flags, |
| 697 changed_button_flags), | 704 changed_button_flags), |
| 698 offset_(offset) { | 705 offset_(offset) { |
| 699 // Set event type to ET_UNKNOWN initially in MouseEvent() to pass the | 706 // Set event type to ET_UNKNOWN initially in MouseEvent() to pass the |
| 700 // DCHECK for type to enforce that we use MouseWheelEvent() to create | 707 // DCHECK for type to enforce that we use MouseWheelEvent() to create |
| 701 // a MouseWheelEvent. | 708 // a MouseWheelEvent. |
| 702 SetType(ui::ET_MOUSEWHEEL); | 709 SetType(ui::ET_MOUSEWHEEL); |
| 710 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | |
| 703 } | 711 } |
| 704 | 712 |
| 705 #if defined(OS_WIN) | 713 #if defined(OS_WIN) |
| 706 // This value matches windows WHEEL_DELTA. | 714 // This value matches windows WHEEL_DELTA. |
| 707 // static | 715 // static |
| 708 const int MouseWheelEvent::kWheelDelta = 120; | 716 const int MouseWheelEvent::kWheelDelta = 120; |
| 709 #else | 717 #else |
| 710 // This value matches GTK+ wheel scroll amount. | 718 // This value matches GTK+ wheel scroll amount. |
| 711 const int MouseWheelEvent::kWheelDelta = 53; | 719 const int MouseWheelEvent::kWheelDelta = 53; |
| 712 #endif | 720 #endif |
| 713 | 721 |
| 714 //////////////////////////////////////////////////////////////////////////////// | 722 //////////////////////////////////////////////////////////////////////////////// |
| 715 // TouchEvent | 723 // TouchEvent |
| 716 | 724 |
| 717 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 725 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
| 718 : LocatedEvent(native_event), | 726 : LocatedEvent(native_event), |
| 719 touch_id_(GetTouchId(native_event)), | 727 touch_id_(GetTouchId(native_event)), |
| 720 unique_event_id_(ui::GetNextTouchEventId()), | 728 unique_event_id_(ui::GetNextTouchEventId()), |
| 721 rotation_angle_(GetTouchAngle(native_event)), | 729 rotation_angle_(GetTouchAngle(native_event)), |
| 722 may_cause_scrolling_(false), | 730 may_cause_scrolling_(false), |
| 723 should_remove_native_touch_id_mapping_(false), | 731 should_remove_native_touch_id_mapping_(false), |
| 724 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) { | 732 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) { |
| 733 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
| 725 latency()->AddLatencyNumberWithTimestamp( | 734 latency()->AddLatencyNumberWithTimestamp( |
| 726 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, | 735 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, |
| 727 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); | 736 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); |
| 728 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 737 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 729 | 738 |
| 730 FixRotationAngle(); | 739 FixRotationAngle(); |
| 731 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) | 740 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) |
| 732 should_remove_native_touch_id_mapping_ = true; | 741 should_remove_native_touch_id_mapping_ = true; |
| 733 } | 742 } |
| 734 | 743 |
| 735 TouchEvent::TouchEvent(const PointerEvent& pointer_event) | 744 TouchEvent::TouchEvent(const PointerEvent& pointer_event) |
| 736 : LocatedEvent(pointer_event), | 745 : LocatedEvent(pointer_event), |
| 737 touch_id_(pointer_event.pointer_id()), | 746 touch_id_(pointer_event.pointer_id()), |
| 738 unique_event_id_(ui::GetNextTouchEventId()), | 747 unique_event_id_(ui::GetNextTouchEventId()), |
| 739 rotation_angle_(0.0f), | 748 rotation_angle_(0.0f), |
| 740 may_cause_scrolling_(false), | 749 may_cause_scrolling_(false), |
| 741 should_remove_native_touch_id_mapping_(false), | 750 should_remove_native_touch_id_mapping_(false), |
| 742 pointer_details_(pointer_event.pointer_details()) { | 751 pointer_details_(pointer_event.pointer_details()) { |
| 752 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
| 743 DCHECK(pointer_event.IsTouchPointerEvent()); | 753 DCHECK(pointer_event.IsTouchPointerEvent()); |
| 744 switch (pointer_event.type()) { | 754 switch (pointer_event.type()) { |
| 745 case ET_POINTER_DOWN: | 755 case ET_POINTER_DOWN: |
| 746 SetType(ET_TOUCH_PRESSED); | 756 SetType(ET_TOUCH_PRESSED); |
| 747 break; | 757 break; |
| 748 | 758 |
| 749 case ET_POINTER_MOVED: | 759 case ET_POINTER_MOVED: |
| 750 SetType(ET_TOUCH_MOVED); | 760 SetType(ET_TOUCH_MOVED); |
| 751 break; | 761 break; |
| 752 | 762 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 771 gfx::PointF(location), | 781 gfx::PointF(location), |
| 772 gfx::PointF(location), | 782 gfx::PointF(location), |
| 773 time_stamp, | 783 time_stamp, |
| 774 0), | 784 0), |
| 775 touch_id_(touch_id), | 785 touch_id_(touch_id), |
| 776 unique_event_id_(ui::GetNextTouchEventId()), | 786 unique_event_id_(ui::GetNextTouchEventId()), |
| 777 rotation_angle_(0.0f), | 787 rotation_angle_(0.0f), |
| 778 may_cause_scrolling_(false), | 788 may_cause_scrolling_(false), |
| 779 should_remove_native_touch_id_mapping_(false), | 789 should_remove_native_touch_id_mapping_(false), |
| 780 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { | 790 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { |
| 791 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
| 781 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 792 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 782 } | 793 } |
| 783 | 794 |
| 784 TouchEvent::TouchEvent(EventType type, | 795 TouchEvent::TouchEvent(EventType type, |
| 785 const gfx::Point& location, | 796 const gfx::Point& location, |
| 786 int flags, | 797 int flags, |
| 787 int touch_id, | 798 int touch_id, |
| 788 base::TimeTicks time_stamp, | 799 base::TimeTicks time_stamp, |
| 789 float radius_x, | 800 float radius_x, |
| 790 float radius_y, | 801 float radius_y, |
| 791 float angle, | 802 float angle, |
| 792 float force) | 803 float force) |
| 793 : LocatedEvent(type, | 804 : LocatedEvent(type, |
| 794 gfx::PointF(location), | 805 gfx::PointF(location), |
| 795 gfx::PointF(location), | 806 gfx::PointF(location), |
| 796 time_stamp, | 807 time_stamp, |
| 797 flags), | 808 flags), |
| 798 touch_id_(touch_id), | 809 touch_id_(touch_id), |
| 799 unique_event_id_(ui::GetNextTouchEventId()), | 810 unique_event_id_(ui::GetNextTouchEventId()), |
| 800 rotation_angle_(angle), | 811 rotation_angle_(angle), |
| 801 may_cause_scrolling_(false), | 812 may_cause_scrolling_(false), |
| 802 should_remove_native_touch_id_mapping_(false), | 813 should_remove_native_touch_id_mapping_(false), |
| 803 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, | 814 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, |
| 804 radius_x, | 815 radius_x, |
| 805 radius_y, | 816 radius_y, |
| 806 force, | 817 force, |
| 807 /* tilt_x */ 0.0f, | 818 /* tilt_x */ 0.0f, |
| 808 /* tilt_y */ 0.0f)) { | 819 /* tilt_y */ 0.0f)) { |
| 820 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
| 809 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 821 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 810 FixRotationAngle(); | 822 FixRotationAngle(); |
| 811 } | 823 } |
| 812 | 824 |
| 813 TouchEvent::TouchEvent(const TouchEvent& copy) | 825 TouchEvent::TouchEvent(const TouchEvent& copy) |
| 814 : LocatedEvent(copy), | 826 : LocatedEvent(copy), |
| 815 touch_id_(copy.touch_id_), | 827 touch_id_(copy.touch_id_), |
| 816 unique_event_id_(copy.unique_event_id_), | 828 unique_event_id_(copy.unique_event_id_), |
| 817 rotation_angle_(copy.rotation_angle_), | 829 rotation_angle_(copy.rotation_angle_), |
| 818 may_cause_scrolling_(copy.may_cause_scrolling_), | 830 may_cause_scrolling_(copy.may_cause_scrolling_), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 return true; | 891 return true; |
| 880 default: | 892 default: |
| 881 return false; | 893 return false; |
| 882 } | 894 } |
| 883 } | 895 } |
| 884 | 896 |
| 885 PointerEvent::PointerEvent(const PointerEvent& pointer_event) | 897 PointerEvent::PointerEvent(const PointerEvent& pointer_event) |
| 886 : LocatedEvent(pointer_event), | 898 : LocatedEvent(pointer_event), |
| 887 pointer_id_(pointer_event.pointer_id()), | 899 pointer_id_(pointer_event.pointer_id()), |
| 888 changed_button_flags_(pointer_event.changed_button_flags()), | 900 changed_button_flags_(pointer_event.changed_button_flags()), |
| 889 details_(pointer_event.pointer_details()) {} | 901 details_(pointer_event.pointer_details()) { |
| 902 if (IsTouchPointerEvent()) | |
| 903 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
|
tdresser
2016/09/12 14:23:08
Should it be set to "OTHER" if it isn't touch?
sahel
2016/09/12 17:02:26
We decided to check the source and set it only in
tdresser
2016/09/12 18:03:44
Don't we only make pointer events for mouse and to
| |
| 904 } | |
| 890 | 905 |
| 891 PointerEvent::PointerEvent(const MouseEvent& mouse_event) | 906 PointerEvent::PointerEvent(const MouseEvent& mouse_event) |
| 892 : LocatedEvent(mouse_event), | 907 : LocatedEvent(mouse_event), |
| 893 pointer_id_(kMousePointerId), | 908 pointer_id_(kMousePointerId), |
| 894 changed_button_flags_(mouse_event.changed_button_flags()), | 909 changed_button_flags_(mouse_event.changed_button_flags()), |
| 895 details_(mouse_event.pointer_details()) { | 910 details_(mouse_event.pointer_details()) { |
| 896 DCHECK(CanConvertFrom(mouse_event)); | 911 DCHECK(CanConvertFrom(mouse_event)); |
| 897 switch (mouse_event.type()) { | 912 switch (mouse_event.type()) { |
| 898 case ET_MOUSE_PRESSED: | 913 case ET_MOUSE_PRESSED: |
| 899 SetType(ET_POINTER_DOWN); | 914 SetType(ET_POINTER_DOWN); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 SetType(ET_POINTER_UP); | 965 SetType(ET_POINTER_UP); |
| 951 break; | 966 break; |
| 952 | 967 |
| 953 case ET_TOUCH_CANCELLED: | 968 case ET_TOUCH_CANCELLED: |
| 954 SetType(ET_POINTER_CANCELLED); | 969 SetType(ET_POINTER_CANCELLED); |
| 955 break; | 970 break; |
| 956 | 971 |
| 957 default: | 972 default: |
| 958 NOTREACHED(); | 973 NOTREACHED(); |
| 959 } | 974 } |
| 975 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
| 960 } | 976 } |
| 961 | 977 |
| 962 PointerEvent::PointerEvent(EventType type, | 978 PointerEvent::PointerEvent(EventType type, |
| 963 const gfx::Point& location, | 979 const gfx::Point& location, |
| 964 const gfx::Point& root_location, | 980 const gfx::Point& root_location, |
| 965 int flags, | 981 int flags, |
| 966 int pointer_id, | 982 int pointer_id, |
| 967 int changed_button_flags, | 983 int changed_button_flags, |
| 968 const PointerDetails& pointer_details, | 984 const PointerDetails& pointer_details, |
| 969 base::TimeTicks time_stamp) | 985 base::TimeTicks time_stamp) |
| 970 : LocatedEvent(type, | 986 : LocatedEvent(type, |
| 971 gfx::PointF(location), | 987 gfx::PointF(location), |
| 972 gfx::PointF(root_location), | 988 gfx::PointF(root_location), |
| 973 time_stamp, | 989 time_stamp, |
| 974 flags), | 990 flags), |
| 975 pointer_id_(pointer_id), | 991 pointer_id_(pointer_id), |
| 976 changed_button_flags_(changed_button_flags), | 992 changed_button_flags_(changed_button_flags), |
| 977 details_(pointer_details) {} | 993 details_(pointer_details) { |
| 994 if (IsTouchPointerEvent()) | |
| 995 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
| 996 } | |
| 978 | 997 |
| 979 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); | 998 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); |
| 980 | 999 |
| 981 //////////////////////////////////////////////////////////////////////////////// | 1000 //////////////////////////////////////////////////////////////////////////////// |
| 982 // KeyEvent | 1001 // KeyEvent |
| 983 | 1002 |
| 984 // static | 1003 // static |
| 985 KeyEvent* KeyEvent::last_key_event_ = NULL; | 1004 KeyEvent* KeyEvent::last_key_event_ = NULL; |
| 986 | 1005 |
| 987 // static | 1006 // static |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1016 last_key_event_->set_time_stamp(event.time_stamp()); | 1035 last_key_event_->set_time_stamp(event.time_stamp()); |
| 1017 last_key_event_->set_flags(last_key_event_->flags() | ui::EF_IS_REPEAT); | 1036 last_key_event_->set_flags(last_key_event_->flags() | ui::EF_IS_REPEAT); |
| 1018 return true; | 1037 return true; |
| 1019 } | 1038 } |
| 1020 delete last_key_event_; | 1039 delete last_key_event_; |
| 1021 last_key_event_ = new KeyEvent(event); | 1040 last_key_event_ = new KeyEvent(event); |
| 1022 return false; | 1041 return false; |
| 1023 } | 1042 } |
| 1024 | 1043 |
| 1025 KeyEvent::KeyEvent(const base::NativeEvent& native_event) | 1044 KeyEvent::KeyEvent(const base::NativeEvent& native_event) |
| 1026 : KeyEvent(native_event, EventFlagsFromNative(native_event)) {} | 1045 : KeyEvent(native_event, EventFlagsFromNative(native_event)) { |
| 1046 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1047 } | |
| 1027 | 1048 |
| 1028 KeyEvent::KeyEvent(const base::NativeEvent& native_event, int event_flags) | 1049 KeyEvent::KeyEvent(const base::NativeEvent& native_event, int event_flags) |
| 1029 : Event(native_event, EventTypeFromNative(native_event), event_flags), | 1050 : Event(native_event, EventTypeFromNative(native_event), event_flags), |
| 1030 key_code_(KeyboardCodeFromNative(native_event)), | 1051 key_code_(KeyboardCodeFromNative(native_event)), |
| 1031 code_(CodeFromNative(native_event)), | 1052 code_(CodeFromNative(native_event)), |
| 1032 is_char_(IsCharFromNative(native_event)) { | 1053 is_char_(IsCharFromNative(native_event)) { |
| 1054 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1033 if (IsRepeated(*this)) | 1055 if (IsRepeated(*this)) |
| 1034 set_flags(flags() | ui::EF_IS_REPEAT); | 1056 set_flags(flags() | ui::EF_IS_REPEAT); |
| 1035 | 1057 |
| 1036 #if defined(USE_X11) | 1058 #if defined(USE_X11) |
| 1037 NormalizeFlags(); | 1059 NormalizeFlags(); |
| 1038 #endif | 1060 #endif |
| 1039 #if defined(OS_WIN) | 1061 #if defined(OS_WIN) |
| 1040 // Only Windows has native character events. | 1062 // Only Windows has native character events. |
| 1041 if (is_char_) | 1063 if (is_char_) |
| 1042 key_ = DomKey::FromCharacter(native_event.wParam); | 1064 key_ = DomKey::FromCharacter(native_event.wParam); |
| 1043 else | 1065 else |
| 1044 key_ = PlatformKeyMap::DomKeyFromKeyboardCode(key_code(), flags()); | 1066 key_ = PlatformKeyMap::DomKeyFromKeyboardCode(key_code(), flags()); |
| 1045 #endif | 1067 #endif |
| 1046 } | 1068 } |
| 1047 | 1069 |
| 1048 KeyEvent::KeyEvent(EventType type, | 1070 KeyEvent::KeyEvent(EventType type, |
| 1049 KeyboardCode key_code, | 1071 KeyboardCode key_code, |
| 1050 int flags) | 1072 int flags) |
| 1051 : Event(type, EventTimeForNow(), flags), | 1073 : Event(type, EventTimeForNow(), flags), |
| 1052 key_code_(key_code), | 1074 key_code_(key_code), |
| 1053 code_(UsLayoutKeyboardCodeToDomCode(key_code)) { | 1075 code_(UsLayoutKeyboardCodeToDomCode(key_code)) { |
| 1076 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1054 } | 1077 } |
| 1055 | 1078 |
| 1056 KeyEvent::KeyEvent(EventType type, | 1079 KeyEvent::KeyEvent(EventType type, |
| 1057 KeyboardCode key_code, | 1080 KeyboardCode key_code, |
| 1058 DomCode code, | 1081 DomCode code, |
| 1059 int flags) | 1082 int flags) |
| 1060 : Event(type, EventTimeForNow(), flags), | 1083 : Event(type, EventTimeForNow(), flags), |
| 1061 key_code_(key_code), | 1084 key_code_(key_code), |
| 1062 code_(code) { | 1085 code_(code) { |
| 1086 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1063 } | 1087 } |
| 1064 | 1088 |
| 1065 KeyEvent::KeyEvent(EventType type, | 1089 KeyEvent::KeyEvent(EventType type, |
| 1066 KeyboardCode key_code, | 1090 KeyboardCode key_code, |
| 1067 DomCode code, | 1091 DomCode code, |
| 1068 int flags, | 1092 int flags, |
| 1069 DomKey key, | 1093 DomKey key, |
| 1070 base::TimeTicks time_stamp) | 1094 base::TimeTicks time_stamp) |
| 1071 : Event(type, time_stamp, flags), | 1095 : Event(type, time_stamp, flags), |
| 1072 key_code_(key_code), | 1096 key_code_(key_code), |
| 1073 code_(code), | 1097 code_(code), |
| 1074 key_(key) {} | 1098 key_(key) { |
| 1099 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1100 } | |
| 1075 | 1101 |
| 1076 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags) | 1102 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags) |
| 1077 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags), | 1103 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags), |
| 1078 key_code_(key_code), | 1104 key_code_(key_code), |
| 1079 code_(DomCode::NONE), | 1105 code_(DomCode::NONE), |
| 1080 is_char_(true), | 1106 is_char_(true), |
| 1081 key_(DomKey::FromCharacter(character)) { | 1107 key_(DomKey::FromCharacter(character)) { |
| 1108 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1082 } | 1109 } |
| 1083 | 1110 |
| 1084 KeyEvent::KeyEvent(const KeyEvent& rhs) | 1111 KeyEvent::KeyEvent(const KeyEvent& rhs) |
| 1085 : Event(rhs), | 1112 : Event(rhs), |
| 1086 key_code_(rhs.key_code_), | 1113 key_code_(rhs.key_code_), |
| 1087 code_(rhs.code_), | 1114 code_(rhs.code_), |
| 1088 is_char_(rhs.is_char_), | 1115 is_char_(rhs.is_char_), |
| 1089 key_(rhs.key_) { | 1116 key_(rhs.key_) { |
| 1117 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1090 } | 1118 } |
| 1091 | 1119 |
| 1092 KeyEvent& KeyEvent::operator=(const KeyEvent& rhs) { | 1120 KeyEvent& KeyEvent::operator=(const KeyEvent& rhs) { |
| 1093 if (this != &rhs) { | 1121 if (this != &rhs) { |
| 1094 Event::operator=(rhs); | 1122 Event::operator=(rhs); |
| 1095 key_code_ = rhs.key_code_; | 1123 key_code_ = rhs.key_code_; |
| 1096 code_ = rhs.code_; | 1124 code_ = rhs.code_; |
| 1097 key_ = rhs.key_; | 1125 key_ = rhs.key_; |
| 1098 is_char_ = rhs.is_char_; | 1126 is_char_ = rhs.is_char_; |
| 1099 } | 1127 } |
| 1128 latency()->set_source_event_type(ui::SourceEventType::OTHER); | |
| 1100 return *this; | 1129 return *this; |
| 1101 } | 1130 } |
| 1102 | 1131 |
| 1103 KeyEvent::~KeyEvent() {} | 1132 KeyEvent::~KeyEvent() {} |
| 1104 | 1133 |
| 1105 void KeyEvent::ApplyLayout() const { | 1134 void KeyEvent::ApplyLayout() const { |
| 1106 ui::DomCode code = code_; | 1135 ui::DomCode code = code_; |
| 1107 if (code == DomCode::NONE) { | 1136 if (code == DomCode::NONE) { |
| 1108 // Catch old code that tries to do layout without a physical key, and try | 1137 // Catch old code that tries to do layout without a physical key, and try |
| 1109 // to recover using the KeyboardCode. Once key events are fully defined | 1138 // to recover using the KeyboardCode. Once key events are fully defined |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1266 } else if (type() == ET_SCROLL_FLING_START || | 1295 } else if (type() == ET_SCROLL_FLING_START || |
| 1267 type() == ET_SCROLL_FLING_CANCEL) { | 1296 type() == ET_SCROLL_FLING_CANCEL) { |
| 1268 GetFlingData(native_event, | 1297 GetFlingData(native_event, |
| 1269 &x_offset_, &y_offset_, | 1298 &x_offset_, &y_offset_, |
| 1270 &x_offset_ordinal_, &y_offset_ordinal_, | 1299 &x_offset_ordinal_, &y_offset_ordinal_, |
| 1271 NULL); | 1300 NULL); |
| 1272 } else { | 1301 } else { |
| 1273 NOTREACHED() << "Unexpected event type " << type() | 1302 NOTREACHED() << "Unexpected event type " << type() |
| 1274 << " when constructing a ScrollEvent."; | 1303 << " when constructing a ScrollEvent."; |
| 1275 } | 1304 } |
| 1305 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | |
| 1276 } | 1306 } |
| 1277 | 1307 |
| 1278 ScrollEvent::ScrollEvent(EventType type, | 1308 ScrollEvent::ScrollEvent(EventType type, |
| 1279 const gfx::Point& location, | 1309 const gfx::Point& location, |
| 1280 base::TimeTicks time_stamp, | 1310 base::TimeTicks time_stamp, |
| 1281 int flags, | 1311 int flags, |
| 1282 float x_offset, | 1312 float x_offset, |
| 1283 float y_offset, | 1313 float y_offset, |
| 1284 float x_offset_ordinal, | 1314 float x_offset_ordinal, |
| 1285 float y_offset_ordinal, | 1315 float y_offset_ordinal, |
| 1286 int finger_count) | 1316 int finger_count) |
| 1287 : MouseEvent(type, location, location, time_stamp, flags, 0), | 1317 : MouseEvent(type, location, location, time_stamp, flags, 0), |
| 1288 x_offset_(x_offset), | 1318 x_offset_(x_offset), |
| 1289 y_offset_(y_offset), | 1319 y_offset_(y_offset), |
| 1290 x_offset_ordinal_(x_offset_ordinal), | 1320 x_offset_ordinal_(x_offset_ordinal), |
| 1291 y_offset_ordinal_(y_offset_ordinal), | 1321 y_offset_ordinal_(y_offset_ordinal), |
| 1292 finger_count_(finger_count) { | 1322 finger_count_(finger_count) { |
| 1293 CHECK(IsScrollEvent()); | 1323 CHECK(IsScrollEvent()); |
| 1324 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | |
| 1294 } | 1325 } |
| 1295 | 1326 |
| 1296 void ScrollEvent::Scale(const float factor) { | 1327 void ScrollEvent::Scale(const float factor) { |
| 1297 x_offset_ *= factor; | 1328 x_offset_ *= factor; |
| 1298 y_offset_ *= factor; | 1329 y_offset_ *= factor; |
| 1299 x_offset_ordinal_ *= factor; | 1330 x_offset_ordinal_ *= factor; |
| 1300 y_offset_ordinal_ *= factor; | 1331 y_offset_ordinal_ *= factor; |
| 1301 } | 1332 } |
| 1302 | 1333 |
| 1303 //////////////////////////////////////////////////////////////////////////////// | 1334 //////////////////////////////////////////////////////////////////////////////// |
| 1304 // GestureEvent | 1335 // GestureEvent |
| 1305 | 1336 |
| 1306 GestureEvent::GestureEvent(float x, | 1337 GestureEvent::GestureEvent(float x, |
| 1307 float y, | 1338 float y, |
| 1308 int flags, | 1339 int flags, |
| 1309 base::TimeTicks time_stamp, | 1340 base::TimeTicks time_stamp, |
| 1310 const GestureEventDetails& details, | 1341 const GestureEventDetails& details, |
| 1311 uint32_t unique_touch_event_id) | 1342 uint32_t unique_touch_event_id) |
| 1312 : LocatedEvent(details.type(), | 1343 : LocatedEvent(details.type(), |
| 1313 gfx::PointF(x, y), | 1344 gfx::PointF(x, y), |
| 1314 gfx::PointF(x, y), | 1345 gfx::PointF(x, y), |
| 1315 time_stamp, | 1346 time_stamp, |
| 1316 flags | EF_FROM_TOUCH), | 1347 flags | EF_FROM_TOUCH), |
| 1317 details_(details), | 1348 details_(details), |
| 1318 unique_touch_event_id_(unique_touch_event_id) {} | 1349 unique_touch_event_id_(unique_touch_event_id) { |
| 1350 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | |
| 1351 } | |
| 1319 | 1352 |
| 1320 GestureEvent::~GestureEvent() { | 1353 GestureEvent::~GestureEvent() { |
| 1321 } | 1354 } |
| 1322 | 1355 |
| 1323 } // namespace ui | 1356 } // namespace ui |
| OLD | NEW |