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

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

Issue 2655303004: Add id properties to PointerEvent (Closed)
Patch Set: pointer id Created 3 years, 10 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
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 #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
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, uint32_t id)
509 : pointer_type(pointer_type),
510 force(std::numeric_limits<float>::quiet_NaN()),
511 id(id) {}
512
513 PointerDetails::PointerDetails(EventPointerType pointer_type,
514 float radius_x,
515 float radius_y,
516 float force,
517 float tilt_x,
518 float tilt_y,
519 float tangential_pressure,
520 int twist,
521 uint32_t id)
522 : pointer_type(pointer_type),
523 // If we aren't provided with a radius on one axis, use the
524 // information from the other axis.
525 radius_x(radius_x > 0 ? radius_x : radius_y),
526 radius_y(radius_y > 0 ? radius_y : radius_x),
527 force(force),
528 tilt_x(tilt_x),
529 tilt_y(tilt_y),
530 tangential_pressure(tangential_pressure),
531 twist(twist),
532 id(id) {}
533
534 PointerDetails::PointerDetails(EventPointerType pointer_type,
535 const gfx::Vector2d& offset)
536 : pointer_type(pointer_type),
537 force(std::numeric_limits<float>::quiet_NaN()),
538 offset(offset) {}
539
540 PointerDetails::PointerDetails(const PointerDetails& other) = default;
541
542 ////////////////////////////////////////////////////////////////////////////////
504 // MouseEvent 543 // MouseEvent
505 544
506 MouseEvent::MouseEvent(const base::NativeEvent& native_event) 545 MouseEvent::MouseEvent(const base::NativeEvent& native_event)
507 : LocatedEvent(native_event), 546 : LocatedEvent(native_event),
508 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), 547 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)),
509 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { 548 pointer_details_(GetMousePointerDetailsFromNative(native_event)) {
510 latency()->AddLatencyNumberWithTimestamp( 549 latency()->AddLatencyNumberWithTimestamp(
511 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, 550 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0,
512 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); 551 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1);
513 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 552 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 const gfx::Point& root_location, 605 const gfx::Point& root_location,
567 base::TimeTicks time_stamp, 606 base::TimeTicks time_stamp,
568 int flags, 607 int flags,
569 int changed_button_flags) 608 int changed_button_flags)
570 : LocatedEvent(type, 609 : LocatedEvent(type,
571 gfx::PointF(location), 610 gfx::PointF(location),
572 gfx::PointF(root_location), 611 gfx::PointF(root_location),
573 time_stamp, 612 time_stamp,
574 flags), 613 flags),
575 changed_button_flags_(changed_button_flags), 614 changed_button_flags_(changed_button_flags),
576 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { 615 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE,
616 PointerEvent::kMousePointerId)) {
577 DCHECK_NE(ET_MOUSEWHEEL, type); 617 DCHECK_NE(ET_MOUSEWHEEL, type);
578 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 618 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
579 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) 619 if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
580 SetType(ET_MOUSE_DRAGGED); 620 SetType(ET_MOUSE_DRAGGED);
581 } 621 }
582 622
583 // static 623 // static
584 bool MouseEvent::IsRepeatedClickEvent( 624 bool MouseEvent::IsRepeatedClickEvent(
585 const MouseEvent& event1, 625 const MouseEvent& event1,
586 const MouseEvent& event2) { 626 const MouseEvent& event2) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 #else 799 #else
760 // This value matches GTK+ wheel scroll amount. 800 // This value matches GTK+ wheel scroll amount.
761 const int MouseWheelEvent::kWheelDelta = 53; 801 const int MouseWheelEvent::kWheelDelta = 53;
762 #endif 802 #endif
763 803
764 //////////////////////////////////////////////////////////////////////////////// 804 ////////////////////////////////////////////////////////////////////////////////
765 // TouchEvent 805 // TouchEvent
766 806
767 TouchEvent::TouchEvent(const base::NativeEvent& native_event) 807 TouchEvent::TouchEvent(const base::NativeEvent& native_event)
768 : LocatedEvent(native_event), 808 : LocatedEvent(native_event),
769 touch_id_(GetTouchId(native_event)),
770 unique_event_id_(ui::GetNextTouchEventId()), 809 unique_event_id_(ui::GetNextTouchEventId()),
771 rotation_angle_(GetTouchAngle(native_event)), 810 rotation_angle_(GetTouchAngle(native_event)),
772 may_cause_scrolling_(false), 811 may_cause_scrolling_(false),
773 should_remove_native_touch_id_mapping_(false), 812 should_remove_native_touch_id_mapping_(false),
774 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) { 813 pointer_details_(GetTouchPointerDetailsFromNative(native_event)) {
775 latency()->AddLatencyNumberWithTimestamp( 814 latency()->AddLatencyNumberWithTimestamp(
776 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, 815 INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0,
777 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1); 816 base::TimeTicks::FromInternalValue(time_stamp().ToInternalValue()), 1);
778 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 817 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
779 818
780 FixRotationAngle(); 819 FixRotationAngle();
781 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) 820 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED)
782 should_remove_native_touch_id_mapping_ = true; 821 should_remove_native_touch_id_mapping_ = true;
783 } 822 }
784 823
785 TouchEvent::TouchEvent(const PointerEvent& pointer_event) 824 TouchEvent::TouchEvent(const PointerEvent& pointer_event)
786 : LocatedEvent(pointer_event), 825 : LocatedEvent(pointer_event),
787 touch_id_(pointer_event.pointer_id()),
788 unique_event_id_(ui::GetNextTouchEventId()), 826 unique_event_id_(ui::GetNextTouchEventId()),
789 rotation_angle_(0.0f), 827 rotation_angle_(0.0f),
790 may_cause_scrolling_(false), 828 may_cause_scrolling_(false),
791 should_remove_native_touch_id_mapping_(false), 829 should_remove_native_touch_id_mapping_(false),
792 pointer_details_(pointer_event.pointer_details()) { 830 pointer_details_(pointer_event.pointer_details()) {
793 DCHECK(pointer_event.IsTouchPointerEvent()); 831 DCHECK(pointer_event.IsTouchPointerEvent());
794 switch (pointer_event.type()) { 832 switch (pointer_event.type()) {
795 case ET_POINTER_DOWN: 833 case ET_POINTER_DOWN:
796 SetType(ET_TOUCH_PRESSED); 834 SetType(ET_TOUCH_PRESSED);
797 break; 835 break;
(...skipping 10 matching lines...) Expand all
808 SetType(ET_TOUCH_CANCELLED); 846 SetType(ET_TOUCH_CANCELLED);
809 break; 847 break;
810 848
811 default: 849 default:
812 NOTREACHED(); 850 NOTREACHED();
813 } 851 }
814 } 852 }
815 853
816 TouchEvent::TouchEvent(EventType type, 854 TouchEvent::TouchEvent(EventType type,
817 const gfx::Point& location, 855 const gfx::Point& location,
818 int touch_id, 856 uint32_t touch_id,
819 base::TimeTicks time_stamp) 857 base::TimeTicks time_stamp)
820 : LocatedEvent(type, 858 : LocatedEvent(type,
821 gfx::PointF(location), 859 gfx::PointF(location),
822 gfx::PointF(location), 860 gfx::PointF(location),
823 time_stamp, 861 time_stamp,
824 0), 862 0),
825 touch_id_(touch_id),
826 unique_event_id_(ui::GetNextTouchEventId()), 863 unique_event_id_(ui::GetNextTouchEventId()),
827 rotation_angle_(0.0f), 864 rotation_angle_(0.0f),
828 may_cause_scrolling_(false), 865 may_cause_scrolling_(false),
829 should_remove_native_touch_id_mapping_(false), 866 should_remove_native_touch_id_mapping_(false),
830 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { 867 pointer_details_(
868 PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, touch_id)) {
831 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 869 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
832 } 870 }
833 871
834 TouchEvent::TouchEvent(EventType type, 872 TouchEvent::TouchEvent(EventType type,
835 const gfx::Point& location, 873 const gfx::Point& location,
836 int flags, 874 int flags,
837 int touch_id, 875 uint32_t touch_id,
838 base::TimeTicks time_stamp, 876 base::TimeTicks time_stamp,
839 float radius_x, 877 float radius_x,
840 float radius_y, 878 float radius_y,
841 float angle, 879 float angle,
842 float force) 880 float force)
843 : LocatedEvent(type, 881 : LocatedEvent(type,
844 gfx::PointF(location), 882 gfx::PointF(location),
845 gfx::PointF(location), 883 gfx::PointF(location),
846 time_stamp, 884 time_stamp,
847 flags), 885 flags),
848 touch_id_(touch_id),
849 unique_event_id_(ui::GetNextTouchEventId()), 886 unique_event_id_(ui::GetNextTouchEventId()),
850 rotation_angle_(angle), 887 rotation_angle_(angle),
851 may_cause_scrolling_(false), 888 may_cause_scrolling_(false),
852 should_remove_native_touch_id_mapping_(false), 889 should_remove_native_touch_id_mapping_(false),
853 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, 890 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH,
854 radius_x, 891 radius_x,
855 radius_y, 892 radius_y,
856 force, 893 force,
857 /* tilt_x */ 0.0f, 894 /* tilt_x */ 0.0f,
858 /* tilt_y */ 0.0f)) { 895 /* tilt_y */ 0.0f,
896 /* tangential_pressure */ 0.0f,
897 /* twist */ 0,
898 touch_id)) {
859 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 899 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
860 FixRotationAngle(); 900 FixRotationAngle();
861 } 901 }
862 902
863 TouchEvent::TouchEvent(const TouchEvent& copy) 903 TouchEvent::TouchEvent(const TouchEvent& copy)
864 : LocatedEvent(copy), 904 : LocatedEvent(copy),
865 touch_id_(copy.touch_id_),
866 unique_event_id_(copy.unique_event_id_), 905 unique_event_id_(copy.unique_event_id_),
867 rotation_angle_(copy.rotation_angle_), 906 rotation_angle_(copy.rotation_angle_),
868 may_cause_scrolling_(copy.may_cause_scrolling_), 907 may_cause_scrolling_(copy.may_cause_scrolling_),
869 should_remove_native_touch_id_mapping_(false), 908 should_remove_native_touch_id_mapping_(false),
870 pointer_details_(copy.pointer_details_) { 909 pointer_details_(copy.pointer_details_) {
871 // Copied events should not remove touch id mapping, as this either causes the 910 // 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 911 // 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_|. 912 // the copy to attempt to remove the mapping from a null |native_event_|.
874 } 913 }
875 914
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 case ET_TOUCH_RELEASED: 966 case ET_TOUCH_RELEASED:
928 case ET_TOUCH_CANCELLED: 967 case ET_TOUCH_CANCELLED:
929 return true; 968 return true;
930 default: 969 default:
931 return false; 970 return false;
932 } 971 }
933 } 972 }
934 973
935 PointerEvent::PointerEvent(const PointerEvent& pointer_event) 974 PointerEvent::PointerEvent(const PointerEvent& pointer_event)
936 : LocatedEvent(pointer_event), 975 : LocatedEvent(pointer_event),
937 pointer_id_(pointer_event.pointer_id()),
938 changed_button_flags_(pointer_event.changed_button_flags()), 976 changed_button_flags_(pointer_event.changed_button_flags()),
939 details_(pointer_event.pointer_details()) { 977 details_(pointer_event.pointer_details()) {
940 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) 978 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH)
941 latency()->set_source_event_type(ui::SourceEventType::TOUCH); 979 latency()->set_source_event_type(ui::SourceEventType::TOUCH);
942 else if (pointer_event.type() == ET_POINTER_WHEEL_CHANGED) 980 else if (pointer_event.type() == ET_POINTER_WHEEL_CHANGED)
943 latency()->set_source_event_type(ui::SourceEventType::WHEEL); 981 latency()->set_source_event_type(ui::SourceEventType::WHEEL);
944 else 982 else
945 latency()->set_source_event_type(ui::SourceEventType::OTHER); 983 latency()->set_source_event_type(ui::SourceEventType::OTHER);
946 } 984 }
947 985
948 PointerEvent::PointerEvent(const MouseEvent& mouse_event) 986 PointerEvent::PointerEvent(const MouseEvent& mouse_event)
949 : LocatedEvent(mouse_event), 987 : LocatedEvent(mouse_event),
950 pointer_id_(kMousePointerId),
951 changed_button_flags_(mouse_event.changed_button_flags()), 988 changed_button_flags_(mouse_event.changed_button_flags()),
952 details_(mouse_event.pointer_details()) { 989 details_(mouse_event.pointer_details()) {
953 DCHECK(CanConvertFrom(mouse_event)); 990 DCHECK(CanConvertFrom(mouse_event));
954 switch (mouse_event.type()) { 991 switch (mouse_event.type()) {
955 case ET_MOUSE_PRESSED: 992 case ET_MOUSE_PRESSED:
956 SetType(ET_POINTER_DOWN); 993 SetType(ET_POINTER_DOWN);
957 latency()->set_source_event_type(ui::SourceEventType::OTHER); 994 latency()->set_source_event_type(ui::SourceEventType::OTHER);
958 break; 995 break;
959 996
960 case ET_MOUSE_DRAGGED: 997 case ET_MOUSE_DRAGGED:
(...skipping 24 matching lines...) Expand all
985 latency()->set_source_event_type(ui::SourceEventType::WHEEL); 1022 latency()->set_source_event_type(ui::SourceEventType::WHEEL);
986 break; 1023 break;
987 1024
988 case ET_MOUSE_CAPTURE_CHANGED: 1025 case ET_MOUSE_CAPTURE_CHANGED:
989 SetType(ET_POINTER_CAPTURE_CHANGED); 1026 SetType(ET_POINTER_CAPTURE_CHANGED);
990 break; 1027 break;
991 1028
992 default: 1029 default:
993 NOTREACHED(); 1030 NOTREACHED();
994 } 1031 }
1032 details_.id = static_cast<uint32_t>(kMousePointerId);
sadrul 2017/02/07 05:40:42 Should not be necessary?
lanwei 2017/02/10 20:54:38 Done.
995 } 1033 }
996 1034
997 PointerEvent::PointerEvent(const TouchEvent& touch_event) 1035 PointerEvent::PointerEvent(const TouchEvent& touch_event)
998 : LocatedEvent(touch_event), 1036 : LocatedEvent(touch_event),
999 pointer_id_(touch_event.touch_id()),
1000 changed_button_flags_(0), 1037 changed_button_flags_(0),
1001 details_(touch_event.pointer_details()) { 1038 details_(touch_event.pointer_details()) {
1002 DCHECK(CanConvertFrom(touch_event)); 1039 DCHECK(CanConvertFrom(touch_event));
1003 switch (touch_event.type()) { 1040 switch (touch_event.type()) {
1004 case ET_TOUCH_PRESSED: 1041 case ET_TOUCH_PRESSED:
1005 SetType(ET_POINTER_DOWN); 1042 SetType(ET_POINTER_DOWN);
1006 break; 1043 break;
1007 1044
1008 case ET_TOUCH_MOVED: 1045 case ET_TOUCH_MOVED:
1009 SetType(ET_POINTER_MOVED); 1046 SetType(ET_POINTER_MOVED);
(...skipping 10 matching lines...) Expand all
1020 default: 1057 default:
1021 NOTREACHED(); 1058 NOTREACHED();
1022 } 1059 }
1023 latency()->set_source_event_type(ui::SourceEventType::TOUCH); 1060 latency()->set_source_event_type(ui::SourceEventType::TOUCH);
1024 } 1061 }
1025 1062
1026 PointerEvent::PointerEvent(EventType type, 1063 PointerEvent::PointerEvent(EventType type,
1027 const gfx::Point& location, 1064 const gfx::Point& location,
1028 const gfx::Point& root_location, 1065 const gfx::Point& root_location,
1029 int flags, 1066 int flags,
1030 int pointer_id, 1067 uint32_t pointer_id,
1031 int changed_button_flags, 1068 int changed_button_flags,
1032 const PointerDetails& pointer_details, 1069 const PointerDetails& pointer_details,
1033 base::TimeTicks time_stamp) 1070 base::TimeTicks time_stamp)
1034 : LocatedEvent(type, 1071 : LocatedEvent(type,
1035 gfx::PointF(location), 1072 gfx::PointF(location),
1036 gfx::PointF(root_location), 1073 gfx::PointF(root_location),
1037 time_stamp, 1074 time_stamp,
1038 flags), 1075 flags),
1039 pointer_id_(pointer_id),
1040 changed_button_flags_(changed_button_flags), 1076 changed_button_flags_(changed_button_flags),
1041 details_(pointer_details) { 1077 details_(pointer_details) {
1078 details_.id = pointer_id;
1042 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH) 1079 if (details_.pointer_type == EventPointerType::POINTER_TYPE_TOUCH)
1043 latency()->set_source_event_type(ui::SourceEventType::TOUCH); 1080 latency()->set_source_event_type(ui::SourceEventType::TOUCH);
1044 else if (type == ET_POINTER_WHEEL_CHANGED) 1081 else if (type == ET_POINTER_WHEEL_CHANGED)
1045 latency()->set_source_event_type(ui::SourceEventType::WHEEL); 1082 latency()->set_source_event_type(ui::SourceEventType::WHEEL);
1046 else 1083 else
1047 latency()->set_source_event_type(ui::SourceEventType::OTHER); 1084 latency()->set_source_event_type(ui::SourceEventType::OTHER);
1048 } 1085 }
1049 1086
1050 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); 1087 const uint32_t PointerEvent::kMousePointerId =
1088 std::numeric_limits<int32_t>::max();
sadrul 2017/02/07 05:40:42 uint32_t
lanwei 2017/02/10 20:54:38 Done.
1051 1089
1052 //////////////////////////////////////////////////////////////////////////////// 1090 ////////////////////////////////////////////////////////////////////////////////
1053 // KeyEvent 1091 // KeyEvent
1054 1092
1055 // static 1093 // static
1056 KeyEvent* KeyEvent::last_key_event_ = NULL; 1094 KeyEvent* KeyEvent::last_key_event_ = NULL;
1057 1095
1058 // static 1096 // static
1059 bool KeyEvent::IsRepeated(const KeyEvent& event) { 1097 bool KeyEvent::IsRepeated(const KeyEvent& event) {
1060 // A safe guard in case if there were continous key pressed events that are 1098 // A safe guard in case if there were continous key pressed events that are
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 flags | EF_FROM_TOUCH), 1428 flags | EF_FROM_TOUCH),
1391 details_(details), 1429 details_(details),
1392 unique_touch_event_id_(unique_touch_event_id) { 1430 unique_touch_event_id_(unique_touch_event_id) {
1393 latency()->set_source_event_type(ui::SourceEventType::TOUCH); 1431 latency()->set_source_event_type(ui::SourceEventType::TOUCH);
1394 } 1432 }
1395 1433
1396 GestureEvent::~GestureEvent() { 1434 GestureEvent::~GestureEvent() {
1397 } 1435 }
1398 1436
1399 } // namespace ui 1437 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698