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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 void LocatedEvent::UpdateForRootTransform( | 494 void LocatedEvent::UpdateForRootTransform( |
495 const gfx::Transform& reversed_root_transform) { | 495 const gfx::Transform& reversed_root_transform) { |
496 // Transform has to be done at root level. | 496 // Transform has to be done at root level. |
497 gfx::Point3F p(location_); | 497 gfx::Point3F p(location_); |
498 reversed_root_transform.TransformPoint(&p); | 498 reversed_root_transform.TransformPoint(&p); |
499 location_ = p.AsPointF(); | 499 location_ = p.AsPointF(); |
500 root_location_ = location_; | 500 root_location_ = location_; |
501 } | 501 } |
502 | 502 |
503 //////////////////////////////////////////////////////////////////////////////// | 503 //////////////////////////////////////////////////////////////////////////////// |
504 // PointerDetails | |
505 | |
506 PointerDetails::PointerDetails() {} | |
507 | |
508 PointerDetails::PointerDetails(EventPointerType pointer_type, int pointer_id) | |
509 : PointerDetails(pointer_type, | |
510 0.0f, | |
511 0.0f, | |
512 std::numeric_limits<float>::quiet_NaN(), | |
513 0.0f, | |
514 0.0f, | |
515 0.0f, | |
516 0, | |
517 pointer_id) {} | |
518 | |
519 PointerDetails::PointerDetails(EventPointerType pointer_type, | |
520 float radius_x, | |
521 float radius_y, | |
522 float force, | |
523 float tilt_x, | |
524 float tilt_y, | |
525 float tangential_pressure, | |
526 int twist, | |
527 int pointer_id) | |
528 : pointer_type(pointer_type), | |
529 // If we aren't provided with a radius on one axis, use the | |
530 // information from the other axis. | |
531 radius_x(radius_x > 0 ? radius_x : radius_y), | |
532 radius_y(radius_y > 0 ? radius_y : radius_x), | |
533 force(force), | |
534 tilt_x(tilt_x), | |
535 tilt_y(tilt_y), | |
536 tangential_pressure(tangential_pressure), | |
537 twist(twist), | |
538 id(pointer_id) { | |
539 if (pointer_id == PointerDetails::kUnknownPointerId) { | |
540 id = pointer_type == EventPointerType::POINTER_TYPE_TOUCH | |
541 ? 0 | |
542 : PointerEvent::kMousePointerId; | |
543 } | |
544 } | |
545 | |
546 PointerDetails::PointerDetails(EventPointerType pointer_type, | |
547 const gfx::Vector2d& pointer_offset, | |
548 int pointer_id) | |
549 : PointerDetails(pointer_type, pointer_id) { | |
550 offset = pointer_offset; | |
551 } | |
552 | |
553 PointerDetails::PointerDetails(const PointerDetails& other) | |
554 : pointer_type(other.pointer_type), | |
555 radius_x(other.radius_x), | |
556 radius_y(other.radius_y), | |
557 force(other.force), | |
558 tilt_x(other.tilt_x), | |
559 tilt_y(other.tilt_y), | |
560 tangential_pressure(other.tangential_pressure), | |
561 twist(other.twist), | |
562 id(other.id), | |
563 offset(other.offset) {} | |
564 | |
565 const int PointerDetails::kUnknownPointerId = -1; | |
566 | |
567 //////////////////////////////////////////////////////////////////////////////// | |
504 // MouseEvent | 568 // MouseEvent |
505 | 569 |
506 MouseEvent::MouseEvent(const base::NativeEvent& native_event) | 570 MouseEvent::MouseEvent(const base::NativeEvent& native_event) |
507 : LocatedEvent(native_event), | 571 : LocatedEvent(native_event), |
508 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), | 572 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), |
509 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { | 573 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { |
510 latency()->AddLatencyNumberWithTimestamp( | 574 latency()->AddLatencyNumberWithTimestamp( |
511 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, | 575 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, |
512 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); | 576 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); |
513 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 577 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 const int MouseWheelEvent::kWheelDelta = 120; | 822 const int MouseWheelEvent::kWheelDelta = 120; |
759 #else | 823 #else |
760 // This value matches GTK+ wheel scroll amount. | 824 // This value matches GTK+ wheel scroll amount. |
761 const int MouseWheelEvent::kWheelDelta = 53; | 825 const int MouseWheelEvent::kWheelDelta = 53; |
762 #endif | 826 #endif |
763 | 827 |
764 //////////////////////////////////////////////////////////////////////////////// | 828 //////////////////////////////////////////////////////////////////////////////// |
765 // TouchEvent | 829 // TouchEvent |
766 | 830 |
767 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 831 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
768 : LocatedEvent(native_event), | 832 : LocatedEvent(native_event), |
mustaq
2017/02/27 16:02:26
I think the bug with pinch-zoom on CrOS (crbug.com
| |
769 touch_id_(GetTouchId(native_event)), | |
770 unique_event_id_(ui::GetNextTouchEventId()), | 833 unique_event_id_(ui::GetNextTouchEventId()), |
771 rotation_angle_(GetTouchAngle(native_event)), | 834 rotation_angle_(GetTouchAngle(native_event)), |
772 may_cause_scrolling_(false), | 835 may_cause_scrolling_(false), |
773 should_remove_native_touch_id_mapping_(false), | 836 should_remove_native_touch_id_mapping_(false), |
774 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) { | 837 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) { |
775 latency()->AddLatencyNumberWithTimestamp( | 838 latency()->AddLatencyNumberWithTimestamp( |
776 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, | 839 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, |
777 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); | 840 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); |
778 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 841 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
779 | 842 |
780 FixRotationAngle(); | 843 FixRotationAngle(); |
781 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) | 844 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) |
782 should_remove_native_touch_id_mapping_ = true; | 845 should_remove_native_touch_id_mapping_ = true; |
783 } | 846 } |
784 | 847 |
785 TouchEvent::TouchEvent(const PointerEvent& pointer_event) | 848 TouchEvent::TouchEvent(const PointerEvent& pointer_event) |
786 : LocatedEvent(pointer_event), | 849 : LocatedEvent(pointer_event), |
787 touch_id_(pointer_event.pointer_id()), | |
788 unique_event_id_(ui::GetNextTouchEventId()), | 850 unique_event_id_(ui::GetNextTouchEventId()), |
789 rotation_angle_(0.0f), | 851 rotation_angle_(0.0f), |
790 may_cause_scrolling_(false), | 852 may_cause_scrolling_(false), |
791 should_remove_native_touch_id_mapping_(false), | 853 should_remove_native_touch_id_mapping_(false), |
792 pointer_details_(pointer_event.pointer_details()) { | 854 pointer_details_(pointer_event.pointer_details()) { |
793 DCHECK(pointer_event.IsTouchPointerEvent()); | 855 DCHECK(pointer_event.IsTouchPointerEvent()); |
794 switch (pointer_event.type()) { | 856 switch (pointer_event.type()) { |
795 case ET_POINTER_DOWN: | 857 case ET_POINTER_DOWN: |
796 SetType(ET_TOUCH_PRESSED); | 858 SetType(ET_TOUCH_PRESSED); |
797 break; | 859 break; |
(...skipping 17 matching lines...) Expand all Loading... | |
815 | 877 |
816 TouchEvent::TouchEvent(EventType type, | 878 TouchEvent::TouchEvent(EventType type, |
817 const gfx::Point& location, | 879 const gfx::Point& location, |
818 int touch_id, | 880 int touch_id, |
819 base::TimeTicks time_stamp) | 881 base::TimeTicks time_stamp) |
820 : LocatedEvent(type, | 882 : LocatedEvent(type, |
821 gfx::PointF(location), | 883 gfx::PointF(location), |
822 gfx::PointF(location), | 884 gfx::PointF(location), |
823 time_stamp, | 885 time_stamp, |
824 0), | 886 0), |
825 touch_id_(touch_id), | |
826 unique_event_id_(ui::GetNextTouchEventId()), | 887 unique_event_id_(ui::GetNextTouchEventId()), |
827 rotation_angle_(0.0f), | 888 rotation_angle_(0.0f), |
828 may_cause_scrolling_(false), | 889 may_cause_scrolling_(false), |
829 should_remove_native_touch_id_mapping_(false), | 890 should_remove_native_touch_id_mapping_(false), |
830 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { | 891 pointer_details_( |
892 PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, touch_id)) { | |
831 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 893 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
832 } | 894 } |
833 | 895 |
834 TouchEvent::TouchEvent(EventType type, | 896 TouchEvent::TouchEvent(EventType type, |
835 const gfx::Point& location, | 897 const gfx::Point& location, |
836 int flags, | 898 int flags, |
837 int touch_id, | 899 int touch_id, |
838 base::TimeTicks time_stamp, | 900 base::TimeTicks time_stamp, |
839 float radius_x, | 901 float radius_x, |
840 float radius_y, | 902 float radius_y, |
841 float angle, | 903 float angle, |
842 float force) | 904 float force) |
843 : LocatedEvent(type, | 905 : LocatedEvent(type, |
844 gfx::PointF(location), | 906 gfx::PointF(location), |
845 gfx::PointF(location), | 907 gfx::PointF(location), |
846 time_stamp, | 908 time_stamp, |
847 flags), | 909 flags), |
848 touch_id_(touch_id), | |
849 unique_event_id_(ui::GetNextTouchEventId()), | 910 unique_event_id_(ui::GetNextTouchEventId()), |
850 rotation_angle_(angle), | 911 rotation_angle_(angle), |
851 may_cause_scrolling_(false), | 912 may_cause_scrolling_(false), |
852 should_remove_native_touch_id_mapping_(false), | 913 should_remove_native_touch_id_mapping_(false), |
853 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, | 914 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, |
854 radius_x, | 915 radius_x, |
855 radius_y, | 916 radius_y, |
856 force, | 917 force, |
857 /* tilt_x */ 0.0f, | 918 /* tilt_x */ 0.0f, |
858 /* tilt_y */ 0.0f)) { | 919 /* tilt_y */ 0.0f, |
920 /* tangential_pressure */ 0.0f, | |
921 /* twist */ 0, | |
922 touch_id)) { | |
859 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 923 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
860 FixRotationAngle(); | 924 FixRotationAngle(); |
861 } | 925 } |
862 | 926 |
863 TouchEvent::TouchEvent(const TouchEvent& copy) | 927 TouchEvent::TouchEvent(const TouchEvent& copy) |
864 : LocatedEvent(copy), | 928 : LocatedEvent(copy), |
865 touch_id_(copy.touch_id_), | |
866 unique_event_id_(copy.unique_event_id_), | 929 unique_event_id_(copy.unique_event_id_), |
867 rotation_angle_(copy.rotation_angle_), | 930 rotation_angle_(copy.rotation_angle_), |
868 may_cause_scrolling_(copy.may_cause_scrolling_), | 931 may_cause_scrolling_(copy.may_cause_scrolling_), |
869 should_remove_native_touch_id_mapping_(false), | 932 should_remove_native_touch_id_mapping_(false), |
870 pointer_details_(copy.pointer_details_) { | 933 pointer_details_(copy.pointer_details_) { |
871 // Copied events should not remove touch id mapping, as this either causes the | 934 // Copied events should not remove touch id mapping, as this either causes the |
872 // mapping to be lost before the initial event has finished dispatching, or | 935 // mapping to be lost before the initial event has finished dispatching, or |
873 // the copy to attempt to remove the mapping from a null |native_event_|. | 936 // the copy to attempt to remove the mapping from a null |native_event_|. |
874 } | 937 } |
875 | 938 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 case ET_TOUCH_RELEASED: | 990 case ET_TOUCH_RELEASED: |
928 case ET_TOUCH_CANCELLED: | 991 case ET_TOUCH_CANCELLED: |
929 return true; | 992 return true; |
930 default: | 993 default: |
931 return false; | 994 return false; |
932 } | 995 } |
933 } | 996 } |
934 | 997 |
935 PointerEvent::PointerEvent(const PointerEvent& pointer_event) | 998 PointerEvent::PointerEvent(const PointerEvent& pointer_event) |
936 : LocatedEvent(pointer_event), | 999 : LocatedEvent(pointer_event), |
937 pointer_id_(pointer_event.pointer_id()), | |
938 changed_button_flags_(pointer_event.changed_button_flags()), | 1000 changed_button_flags_(pointer_event.changed_button_flags()), |
939 details_(pointer_event.pointer_details()) { | 1001 details_(pointer_event.pointer_details()) { |
940 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) | 1002 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) |
941 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | 1003 latency()->set_source_event_type(ui::SourceEventType::TOUCH); |
942 else if (pointer_event.type() == ET_POINTER_WHEEL_CHANGED) | 1004 else if (pointer_event.type() == ET_POINTER_WHEEL_CHANGED) |
943 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | 1005 latency()->set_source_event_type(ui::SourceEventType::WHEEL); |
944 else | 1006 else |
945 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1007 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
946 } | 1008 } |
947 | 1009 |
948 PointerEvent::PointerEvent(const MouseEvent& mouse_event) | 1010 PointerEvent::PointerEvent(const MouseEvent& mouse_event) |
949 : LocatedEvent(mouse_event), | 1011 : LocatedEvent(mouse_event), |
950 pointer_id_(kMousePointerId), | |
951 changed_button_flags_(mouse_event.changed_button_flags()), | 1012 changed_button_flags_(mouse_event.changed_button_flags()), |
952 details_(mouse_event.pointer_details()) { | 1013 details_(mouse_event.pointer_details()) { |
953 DCHECK(CanConvertFrom(mouse_event)); | 1014 DCHECK(CanConvertFrom(mouse_event)); |
954 switch (mouse_event.type()) { | 1015 switch (mouse_event.type()) { |
955 case ET_MOUSE_PRESSED: | 1016 case ET_MOUSE_PRESSED: |
956 SetType(ET_POINTER_DOWN); | 1017 SetType(ET_POINTER_DOWN); |
957 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1018 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
958 break; | 1019 break; |
959 | 1020 |
960 case ET_MOUSE_DRAGGED: | 1021 case ET_MOUSE_DRAGGED: |
(...skipping 13 matching lines...) Expand all Loading... | |
974 break; | 1035 break; |
975 | 1036 |
976 case ET_MOUSE_RELEASED: | 1037 case ET_MOUSE_RELEASED: |
977 SetType(ET_POINTER_UP); | 1038 SetType(ET_POINTER_UP); |
978 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1039 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
979 break; | 1040 break; |
980 | 1041 |
981 case ET_MOUSEWHEEL: | 1042 case ET_MOUSEWHEEL: |
982 SetType(ET_POINTER_WHEEL_CHANGED); | 1043 SetType(ET_POINTER_WHEEL_CHANGED); |
983 details_ = PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, | 1044 details_ = PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, |
984 mouse_event.AsMouseWheelEvent()->offset()); | 1045 mouse_event.AsMouseWheelEvent()->offset(), |
1046 mouse_event.pointer_details().id); | |
985 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | 1047 latency()->set_source_event_type(ui::SourceEventType::WHEEL); |
986 break; | 1048 break; |
987 | 1049 |
988 case ET_MOUSE_CAPTURE_CHANGED: | 1050 case ET_MOUSE_CAPTURE_CHANGED: |
989 SetType(ET_POINTER_CAPTURE_CHANGED); | 1051 SetType(ET_POINTER_CAPTURE_CHANGED); |
990 break; | 1052 break; |
991 | 1053 |
992 default: | 1054 default: |
993 NOTREACHED(); | 1055 NOTREACHED(); |
994 } | 1056 } |
995 } | 1057 } |
996 | 1058 |
997 PointerEvent::PointerEvent(const TouchEvent& touch_event) | 1059 PointerEvent::PointerEvent(const TouchEvent& touch_event) |
998 : LocatedEvent(touch_event), | 1060 : LocatedEvent(touch_event), |
999 pointer_id_(touch_event.touch_id()), | |
1000 changed_button_flags_(0), | 1061 changed_button_flags_(0), |
1001 details_(touch_event.pointer_details()) { | 1062 details_(touch_event.pointer_details()) { |
1002 DCHECK(CanConvertFrom(touch_event)); | 1063 DCHECK(CanConvertFrom(touch_event)); |
1003 switch (touch_event.type()) { | 1064 switch (touch_event.type()) { |
1004 case ET_TOUCH_PRESSED: | 1065 case ET_TOUCH_PRESSED: |
1005 SetType(ET_POINTER_DOWN); | 1066 SetType(ET_POINTER_DOWN); |
1006 break; | 1067 break; |
1007 | 1068 |
1008 case ET_TOUCH_MOVED: | 1069 case ET_TOUCH_MOVED: |
1009 SetType(ET_POINTER_MOVED); | 1070 SetType(ET_POINTER_MOVED); |
(...skipping 19 matching lines...) Expand all Loading... | |
1029 int flags, | 1090 int flags, |
1030 int pointer_id, | 1091 int pointer_id, |
1031 int changed_button_flags, | 1092 int changed_button_flags, |
1032 const PointerDetails& pointer_details, | 1093 const PointerDetails& pointer_details, |
1033 base::TimeTicks time_stamp) | 1094 base::TimeTicks time_stamp) |
1034 : LocatedEvent(type, | 1095 : LocatedEvent(type, |
1035 gfx::PointF(location), | 1096 gfx::PointF(location), |
1036 gfx::PointF(root_location), | 1097 gfx::PointF(root_location), |
1037 time_stamp, | 1098 time_stamp, |
1038 flags), | 1099 flags), |
1039 pointer_id_(pointer_id), | |
1040 changed_button_flags_(changed_button_flags), | 1100 changed_button_flags_(changed_button_flags), |
1041 details_(pointer_details) { | 1101 details_(pointer_details) { |
1102 details_.id = pointer_id; | |
1042 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) | 1103 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) |
1043 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | 1104 latency()->set_source_event_type(ui::SourceEventType::TOUCH); |
1044 else if (type == ET_POINTER_WHEEL_CHANGED) | 1105 else if (type == ET_POINTER_WHEEL_CHANGED) |
1045 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | 1106 latency()->set_source_event_type(ui::SourceEventType::WHEEL); |
1046 else | 1107 else |
1047 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1108 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
1048 } | 1109 } |
1049 | 1110 |
1050 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); | 1111 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); |
1051 | 1112 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1390 flags | EF_FROM_TOUCH), | 1451 flags | EF_FROM_TOUCH), |
1391 details_(details), | 1452 details_(details), |
1392 unique_touch_event_id_(unique_touch_event_id) { | 1453 unique_touch_event_id_(unique_touch_event_id) { |
1393 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | 1454 latency()->set_source_event_type(ui::SourceEventType::TOUCH); |
1394 } | 1455 } |
1395 | 1456 |
1396 GestureEvent::~GestureEvent() { | 1457 GestureEvent::~GestureEvent() { |
1397 } | 1458 } |
1398 | 1459 |
1399 } // namespace ui | 1460 } // namespace ui |
OLD | NEW |