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 : pointer_type(pointer_type), | |
510 force(std::numeric_limits<float>::quiet_NaN()), | |
511 id(pointer_id) { | |
512 if (pointer_id == -1) { | |
513 id = pointer_type == EventPointerType::POINTER_TYPE_TOUCH | |
514 ? 0 | |
515 : PointerEvent::kMousePointerId; | |
516 } | |
517 } | |
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 == -1) { | |
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& offset, | |
548 int pointer_id) | |
549 : pointer_type(pointer_type), | |
550 force(std::numeric_limits<float>::quiet_NaN()), | |
551 id(pointer_id), | |
552 offset(offset) { | |
553 if (pointer_id == -1) { | |
sadrul
2017/02/13 16:47:42
Instead of -1, use some const, e.g. PointerDetails
lanwei
2017/02/13 21:50:28
Done.
| |
554 id = pointer_type == EventPointerType::POINTER_TYPE_TOUCH | |
555 ? 0 | |
556 : PointerEvent::kMousePointerId; | |
557 } | |
sadrul
2017/02/13 16:47:42
Use a delegated constructor, instead of repeating
lanwei
2017/02/13 21:50:29
Done.
| |
558 } | |
559 | |
560 PointerDetails::PointerDetails(const PointerDetails& other) | |
561 : pointer_type(other.pointer_type), | |
562 radius_x(other.radius_x), | |
563 radius_y(other.radius_y), | |
564 force(other.force), | |
565 tilt_x(other.tilt_x), | |
566 tilt_y(other.tilt_y), | |
567 tangential_pressure(other.tangential_pressure), | |
568 twist(other.twist), | |
569 id(other.id), | |
570 offset(other.offset) {} | |
571 | |
572 //////////////////////////////////////////////////////////////////////////////// | |
504 // MouseEvent | 573 // MouseEvent |
505 | 574 |
506 MouseEvent::MouseEvent(const base::NativeEvent& native_event) | 575 MouseEvent::MouseEvent(const base::NativeEvent& native_event) |
507 : LocatedEvent(native_event), | 576 : LocatedEvent(native_event), |
508 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), | 577 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), |
509 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { | 578 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { |
510 latency()->AddLatencyNumberWithTimestamp( | 579 latency()->AddLatencyNumberWithTimestamp( |
511 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, | 580 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, |
512 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); | 581 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); |
513 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 582 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 #else | 828 #else |
760 // This value matches GTK+ wheel scroll amount. | 829 // This value matches GTK+ wheel scroll amount. |
761 const int MouseWheelEvent::kWheelDelta = 53; | 830 const int MouseWheelEvent::kWheelDelta = 53; |
762 #endif | 831 #endif |
763 | 832 |
764 //////////////////////////////////////////////////////////////////////////////// | 833 //////////////////////////////////////////////////////////////////////////////// |
765 // TouchEvent | 834 // TouchEvent |
766 | 835 |
767 TouchEvent::TouchEvent(const base::NativeEvent& native_event) | 836 TouchEvent::TouchEvent(const base::NativeEvent& native_event) |
768 : LocatedEvent(native_event), | 837 : LocatedEvent(native_event), |
769 touch_id_(GetTouchId(native_event)), | |
770 unique_event_id_(ui::GetNextTouchEventId()), | 838 unique_event_id_(ui::GetNextTouchEventId()), |
771 rotation_angle_(GetTouchAngle(native_event)), | 839 rotation_angle_(GetTouchAngle(native_event)), |
772 may_cause_scrolling_(false), | 840 may_cause_scrolling_(false), |
773 should_remove_native_touch_id_mapping_(false), | 841 should_remove_native_touch_id_mapping_(false), |
774 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) { | 842 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) { |
775 latency()->AddLatencyNumberWithTimestamp( | 843 latency()->AddLatencyNumberWithTimestamp( |
776 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, | 844 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, |
777 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); | 845 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); |
778 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 846 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
779 | 847 |
780 FixRotationAngle(); | 848 FixRotationAngle(); |
781 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) | 849 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) |
782 should_remove_native_touch_id_mapping_ = true; | 850 should_remove_native_touch_id_mapping_ = true; |
783 } | 851 } |
784 | 852 |
785 TouchEvent::TouchEvent(const PointerEvent& pointer_event) | 853 TouchEvent::TouchEvent(const PointerEvent& pointer_event) |
786 : LocatedEvent(pointer_event), | 854 : LocatedEvent(pointer_event), |
787 touch_id_(pointer_event.pointer_id()), | |
788 unique_event_id_(ui::GetNextTouchEventId()), | 855 unique_event_id_(ui::GetNextTouchEventId()), |
789 rotation_angle_(0.0f), | 856 rotation_angle_(0.0f), |
790 may_cause_scrolling_(false), | 857 may_cause_scrolling_(false), |
791 should_remove_native_touch_id_mapping_(false), | 858 should_remove_native_touch_id_mapping_(false), |
792 pointer_details_(pointer_event.pointer_details()) { | 859 pointer_details_(pointer_event.pointer_details()) { |
793 DCHECK(pointer_event.IsTouchPointerEvent()); | 860 DCHECK(pointer_event.IsTouchPointerEvent()); |
794 switch (pointer_event.type()) { | 861 switch (pointer_event.type()) { |
795 case ET_POINTER_DOWN: | 862 case ET_POINTER_DOWN: |
796 SetType(ET_TOUCH_PRESSED); | 863 SetType(ET_TOUCH_PRESSED); |
797 break; | 864 break; |
(...skipping 17 matching lines...) Expand all Loading... | |
815 | 882 |
816 TouchEvent::TouchEvent(EventType type, | 883 TouchEvent::TouchEvent(EventType type, |
817 const gfx::Point& location, | 884 const gfx::Point& location, |
818 int touch_id, | 885 int touch_id, |
819 base::TimeTicks time_stamp) | 886 base::TimeTicks time_stamp) |
820 : LocatedEvent(type, | 887 : LocatedEvent(type, |
821 gfx::PointF(location), | 888 gfx::PointF(location), |
822 gfx::PointF(location), | 889 gfx::PointF(location), |
823 time_stamp, | 890 time_stamp, |
824 0), | 891 0), |
825 touch_id_(touch_id), | |
826 unique_event_id_(ui::GetNextTouchEventId()), | 892 unique_event_id_(ui::GetNextTouchEventId()), |
827 rotation_angle_(0.0f), | 893 rotation_angle_(0.0f), |
828 may_cause_scrolling_(false), | 894 may_cause_scrolling_(false), |
829 should_remove_native_touch_id_mapping_(false), | 895 should_remove_native_touch_id_mapping_(false), |
830 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { | 896 pointer_details_( |
897 PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, touch_id)) { | |
831 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 898 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
832 } | 899 } |
833 | 900 |
834 TouchEvent::TouchEvent(EventType type, | 901 TouchEvent::TouchEvent(EventType type, |
835 const gfx::Point& location, | 902 const gfx::Point& location, |
836 int flags, | 903 int flags, |
837 int touch_id, | 904 int touch_id, |
838 base::TimeTicks time_stamp, | 905 base::TimeTicks time_stamp, |
839 float radius_x, | 906 float radius_x, |
840 float radius_y, | 907 float radius_y, |
841 float angle, | 908 float angle, |
842 float force) | 909 float force) |
843 : LocatedEvent(type, | 910 : LocatedEvent(type, |
844 gfx::PointF(location), | 911 gfx::PointF(location), |
845 gfx::PointF(location), | 912 gfx::PointF(location), |
846 time_stamp, | 913 time_stamp, |
847 flags), | 914 flags), |
848 touch_id_(touch_id), | |
849 unique_event_id_(ui::GetNextTouchEventId()), | 915 unique_event_id_(ui::GetNextTouchEventId()), |
850 rotation_angle_(angle), | 916 rotation_angle_(angle), |
851 may_cause_scrolling_(false), | 917 may_cause_scrolling_(false), |
852 should_remove_native_touch_id_mapping_(false), | 918 should_remove_native_touch_id_mapping_(false), |
853 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, | 919 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, |
854 radius_x, | 920 radius_x, |
855 radius_y, | 921 radius_y, |
856 force, | 922 force, |
857 /* tilt_x */ 0.0f, | 923 /* tilt_x */ 0.0f, |
858 /* tilt_y */ 0.0f)) { | 924 /* tilt_y */ 0.0f, |
925 /* tangential_pressure */ 0.0f, | |
926 /* twist */ 0, | |
927 touch_id)) { | |
859 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 928 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
860 FixRotationAngle(); | 929 FixRotationAngle(); |
861 } | 930 } |
862 | 931 |
863 TouchEvent::TouchEvent(const TouchEvent& copy) | 932 TouchEvent::TouchEvent(const TouchEvent& copy) |
864 : LocatedEvent(copy), | 933 : LocatedEvent(copy), |
865 touch_id_(copy.touch_id_), | |
866 unique_event_id_(copy.unique_event_id_), | 934 unique_event_id_(copy.unique_event_id_), |
867 rotation_angle_(copy.rotation_angle_), | 935 rotation_angle_(copy.rotation_angle_), |
868 may_cause_scrolling_(copy.may_cause_scrolling_), | 936 may_cause_scrolling_(copy.may_cause_scrolling_), |
869 should_remove_native_touch_id_mapping_(false), | 937 should_remove_native_touch_id_mapping_(false), |
870 pointer_details_(copy.pointer_details_) { | 938 pointer_details_(copy.pointer_details_) { |
871 // Copied events should not remove touch id mapping, as this either causes the | 939 // 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 | 940 // 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_|. | 941 // the copy to attempt to remove the mapping from a null |native_event_|. |
874 } | 942 } |
875 | 943 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 case ET_TOUCH_RELEASED: | 995 case ET_TOUCH_RELEASED: |
928 case ET_TOUCH_CANCELLED: | 996 case ET_TOUCH_CANCELLED: |
929 return true; | 997 return true; |
930 default: | 998 default: |
931 return false; | 999 return false; |
932 } | 1000 } |
933 } | 1001 } |
934 | 1002 |
935 PointerEvent::PointerEvent(const PointerEvent& pointer_event) | 1003 PointerEvent::PointerEvent(const PointerEvent& pointer_event) |
936 : LocatedEvent(pointer_event), | 1004 : LocatedEvent(pointer_event), |
937 pointer_id_(pointer_event.pointer_id()), | |
938 changed_button_flags_(pointer_event.changed_button_flags()), | 1005 changed_button_flags_(pointer_event.changed_button_flags()), |
939 details_(pointer_event.pointer_details()) { | 1006 details_(pointer_event.pointer_details()) { |
940 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) | 1007 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) |
941 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | 1008 latency()->set_source_event_type(ui::SourceEventType::TOUCH); |
942 else if (pointer_event.type() == ET_POINTER_WHEEL_CHANGED) | 1009 else if (pointer_event.type() == ET_POINTER_WHEEL_CHANGED) |
943 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | 1010 latency()->set_source_event_type(ui::SourceEventType::WHEEL); |
944 else | 1011 else |
945 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1012 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
946 } | 1013 } |
947 | 1014 |
948 PointerEvent::PointerEvent(const MouseEvent& mouse_event) | 1015 PointerEvent::PointerEvent(const MouseEvent& mouse_event) |
949 : LocatedEvent(mouse_event), | 1016 : LocatedEvent(mouse_event), |
950 pointer_id_(kMousePointerId), | |
951 changed_button_flags_(mouse_event.changed_button_flags()), | 1017 changed_button_flags_(mouse_event.changed_button_flags()), |
952 details_(mouse_event.pointer_details()) { | 1018 details_(mouse_event.pointer_details()) { |
953 DCHECK(CanConvertFrom(mouse_event)); | 1019 DCHECK(CanConvertFrom(mouse_event)); |
954 switch (mouse_event.type()) { | 1020 switch (mouse_event.type()) { |
955 case ET_MOUSE_PRESSED: | 1021 case ET_MOUSE_PRESSED: |
956 SetType(ET_POINTER_DOWN); | 1022 SetType(ET_POINTER_DOWN); |
957 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1023 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
958 break; | 1024 break; |
959 | 1025 |
960 case ET_MOUSE_DRAGGED: | 1026 case ET_MOUSE_DRAGGED: |
(...skipping 13 matching lines...) Expand all Loading... | |
974 break; | 1040 break; |
975 | 1041 |
976 case ET_MOUSE_RELEASED: | 1042 case ET_MOUSE_RELEASED: |
977 SetType(ET_POINTER_UP); | 1043 SetType(ET_POINTER_UP); |
978 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1044 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
979 break; | 1045 break; |
980 | 1046 |
981 case ET_MOUSEWHEEL: | 1047 case ET_MOUSEWHEEL: |
982 SetType(ET_POINTER_WHEEL_CHANGED); | 1048 SetType(ET_POINTER_WHEEL_CHANGED); |
983 details_ = PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, | 1049 details_ = PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, |
984 mouse_event.AsMouseWheelEvent()->offset()); | 1050 mouse_event.AsMouseWheelEvent()->offset(), |
1051 mouse_event.pointer_details().id); | |
985 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | 1052 latency()->set_source_event_type(ui::SourceEventType::WHEEL); |
986 break; | 1053 break; |
987 | 1054 |
988 case ET_MOUSE_CAPTURE_CHANGED: | 1055 case ET_MOUSE_CAPTURE_CHANGED: |
989 SetType(ET_POINTER_CAPTURE_CHANGED); | 1056 SetType(ET_POINTER_CAPTURE_CHANGED); |
990 break; | 1057 break; |
991 | 1058 |
992 default: | 1059 default: |
993 NOTREACHED(); | 1060 NOTREACHED(); |
994 } | 1061 } |
995 } | 1062 } |
996 | 1063 |
997 PointerEvent::PointerEvent(const TouchEvent& touch_event) | 1064 PointerEvent::PointerEvent(const TouchEvent& touch_event) |
998 : LocatedEvent(touch_event), | 1065 : LocatedEvent(touch_event), |
999 pointer_id_(touch_event.touch_id()), | |
1000 changed_button_flags_(0), | 1066 changed_button_flags_(0), |
1001 details_(touch_event.pointer_details()) { | 1067 details_(touch_event.pointer_details()) { |
1002 DCHECK(CanConvertFrom(touch_event)); | 1068 DCHECK(CanConvertFrom(touch_event)); |
1003 switch (touch_event.type()) { | 1069 switch (touch_event.type()) { |
1004 case ET_TOUCH_PRESSED: | 1070 case ET_TOUCH_PRESSED: |
1005 SetType(ET_POINTER_DOWN); | 1071 SetType(ET_POINTER_DOWN); |
1006 break; | 1072 break; |
1007 | 1073 |
1008 case ET_TOUCH_MOVED: | 1074 case ET_TOUCH_MOVED: |
1009 SetType(ET_POINTER_MOVED); | 1075 SetType(ET_POINTER_MOVED); |
(...skipping 19 matching lines...) Expand all Loading... | |
1029 int flags, | 1095 int flags, |
1030 int pointer_id, | 1096 int pointer_id, |
1031 int changed_button_flags, | 1097 int changed_button_flags, |
1032 const PointerDetails& pointer_details, | 1098 const PointerDetails& pointer_details, |
1033 base::TimeTicks time_stamp) | 1099 base::TimeTicks time_stamp) |
1034 : LocatedEvent(type, | 1100 : LocatedEvent(type, |
1035 gfx::PointF(location), | 1101 gfx::PointF(location), |
1036 gfx::PointF(root_location), | 1102 gfx::PointF(root_location), |
1037 time_stamp, | 1103 time_stamp, |
1038 flags), | 1104 flags), |
1039 pointer_id_(pointer_id), | |
1040 changed_button_flags_(changed_button_flags), | 1105 changed_button_flags_(changed_button_flags), |
1041 details_(pointer_details) { | 1106 details_(pointer_details) { |
1107 details_.id = pointer_id; | |
1042 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) | 1108 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) |
1043 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | 1109 latency()->set_source_event_type(ui::SourceEventType::TOUCH); |
1044 else if (type == ET_POINTER_WHEEL_CHANGED) | 1110 else if (type == ET_POINTER_WHEEL_CHANGED) |
1045 latency()->set_source_event_type(ui::SourceEventType::WHEEL); | 1111 latency()->set_source_event_type(ui::SourceEventType::WHEEL); |
1046 else | 1112 else |
1047 latency()->set_source_event_type(ui::SourceEventType::OTHER); | 1113 latency()->set_source_event_type(ui::SourceEventType::OTHER); |
1048 } | 1114 } |
1049 | 1115 |
1050 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); | 1116 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); |
1051 | 1117 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1390 flags | EF_FROM_TOUCH), | 1456 flags | EF_FROM_TOUCH), |
1391 details_(details), | 1457 details_(details), |
1392 unique_touch_event_id_(unique_touch_event_id) { | 1458 unique_touch_event_id_(unique_touch_event_id) { |
1393 latency()->set_source_event_type(ui::SourceEventType::TOUCH); | 1459 latency()->set_source_event_type(ui::SourceEventType::TOUCH); |
1394 } | 1460 } |
1395 | 1461 |
1396 GestureEvent::~GestureEvent() { | 1462 GestureEvent::~GestureEvent() { |
1397 } | 1463 } |
1398 | 1464 |
1399 } // namespace ui | 1465 } // namespace ui |
OLD | NEW |