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 #ifndef UI_EVENTS_EVENT_H_ | 5 #ifndef UI_EVENTS_EVENT_H_ |
6 #define UI_EVENTS_EVENT_H_ | 6 #define UI_EVENTS_EVENT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/events/keycodes/dom/dom_key.h" | 21 #include "ui/events/keycodes/dom/dom_key.h" |
22 #include "ui/events/keycodes/keyboard_codes.h" | 22 #include "ui/events/keycodes/keyboard_codes.h" |
23 #include "ui/events/latency_info.h" | 23 #include "ui/events/latency_info.h" |
24 #include "ui/gfx/geometry/point.h" | 24 #include "ui/gfx/geometry/point.h" |
25 #include "ui/gfx/geometry/point_conversions.h" | 25 #include "ui/gfx/geometry/point_conversions.h" |
26 | 26 |
27 namespace gfx { | 27 namespace gfx { |
28 class Transform; | 28 class Transform; |
29 } | 29 } |
30 | 30 |
31 namespace IPC { | |
32 template <class P> struct ParamTraits; | |
33 } | |
34 | |
35 namespace ui { | 31 namespace ui { |
36 class EventTarget; | 32 class EventTarget; |
37 class KeyEvent; | 33 class KeyEvent; |
38 class LocatedEvent; | 34 class LocatedEvent; |
39 class MouseEvent; | 35 class MouseEvent; |
40 class MouseWheelEvent; | 36 class MouseWheelEvent; |
41 class PointerEvent; | 37 class PointerEvent; |
42 class ScrollEvent; | 38 class ScrollEvent; |
43 class TouchEvent; | 39 class TouchEvent; |
44 enum class DomCode; | 40 enum class DomCode; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 286 |
291 void set_time_stamp(const base::TimeDelta& time_stamp) { | 287 void set_time_stamp(const base::TimeDelta& time_stamp) { |
292 time_stamp_ = time_stamp; | 288 time_stamp_ = time_stamp; |
293 } | 289 } |
294 | 290 |
295 void set_name(const std::string& name) { name_ = name; } | 291 void set_name(const std::string& name) { name_ = name; } |
296 | 292 |
297 private: | 293 private: |
298 friend class EventTestApi; | 294 friend class EventTestApi; |
299 | 295 |
300 // For (de)serialization. | |
301 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
302 | |
303 EventType type_; | 296 EventType type_; |
304 std::string name_; | 297 std::string name_; |
305 base::TimeDelta time_stamp_; | 298 base::TimeDelta time_stamp_; |
306 LatencyInfo latency_; | 299 LatencyInfo latency_; |
307 int flags_; | 300 int flags_; |
308 base::NativeEvent native_event_; | 301 base::NativeEvent native_event_; |
309 bool delete_native_event_; | 302 bool delete_native_event_; |
310 bool cancelable_; | 303 bool cancelable_; |
311 EventTarget* target_; | 304 EventTarget* target_; |
312 EventPhase phase_; | 305 EventPhase phase_; |
313 EventResult result_; | 306 EventResult result_; |
314 | 307 |
315 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information | 308 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information |
316 // is not available. | 309 // is not available. |
317 int source_device_id_; | 310 int source_device_id_; |
318 }; | 311 }; |
319 | 312 |
320 class EVENTS_EXPORT CancelModeEvent : public Event { | 313 class EVENTS_EXPORT CancelModeEvent : public Event { |
321 public: | 314 public: |
322 CancelModeEvent(); | 315 CancelModeEvent(); |
323 ~CancelModeEvent() override; | 316 ~CancelModeEvent() override; |
324 | |
325 private: | |
326 // For (de)serialization. | |
327 CancelModeEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
328 : Event(type, time_stamp, flags) {} | |
329 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
330 friend struct IPC::ParamTraits<ui::CancelModeEvent>; | |
331 }; | 317 }; |
332 | 318 |
333 class EVENTS_EXPORT LocatedEvent : public Event { | 319 class EVENTS_EXPORT LocatedEvent : public Event { |
334 public: | 320 public: |
335 ~LocatedEvent() override; | 321 ~LocatedEvent() override; |
336 | 322 |
337 float x() const { return location_.x(); } | 323 float x() const { return location_.x(); } |
338 float y() const { return location_.y(); } | 324 float y() const { return location_.y(); } |
339 void set_location(const gfx::Point& location) { | 325 void set_location(const gfx::Point& location) { |
340 location_ = gfx::PointF(location); | 326 location_ = gfx::PointF(location); |
(...skipping 24 matching lines...) Expand all Loading... |
365 return; | 351 return; |
366 gfx::Point offset = gfx::ToFlooredPoint(location_); | 352 gfx::Point offset = gfx::ToFlooredPoint(location_); |
367 T::ConvertPointToTarget(source, target, &offset); | 353 T::ConvertPointToTarget(source, target, &offset); |
368 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; | 354 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; |
369 location_= location_ - diff; | 355 location_= location_ - diff; |
370 } | 356 } |
371 | 357 |
372 protected: | 358 protected: |
373 friend class LocatedEventTestApi; | 359 friend class LocatedEventTestApi; |
374 | 360 |
375 // For (de)serialization. | |
376 LocatedEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
377 : Event(type, time_stamp, flags) {} | |
378 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
379 friend struct IPC::ParamTraits<ui::LocatedEvent>; | |
380 | |
381 explicit LocatedEvent(const base::NativeEvent& native_event); | 361 explicit LocatedEvent(const base::NativeEvent& native_event); |
382 | 362 |
383 // Create a new LocatedEvent which is identical to the provided model. | 363 // Create a new LocatedEvent which is identical to the provided model. |
384 // If source / target windows are provided, the model location will be | 364 // If source / target windows are provided, the model location will be |
385 // converted from |source| coordinate system to |target| coordinate system. | 365 // converted from |source| coordinate system to |target| coordinate system. |
386 template <class T> | 366 template <class T> |
387 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 367 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
388 : Event(model), | 368 : Event(model), |
389 location_(model.location_), | 369 location_(model.location_), |
390 root_location_(model.root_location_) { | 370 root_location_(model.root_location_) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 bool operator==(const PointerDetails& other) const { | 411 bool operator==(const PointerDetails& other) const { |
432 return pointer_type == other.pointer_type && | 412 return pointer_type == other.pointer_type && |
433 radius_x == other.radius_x && | 413 radius_x == other.radius_x && |
434 radius_y == other.radius_y && | 414 radius_y == other.radius_y && |
435 (force == other.force || | 415 (force == other.force || |
436 (std::isnan(force) && std::isnan(other.force))) && | 416 (std::isnan(force) && std::isnan(other.force))) && |
437 tilt_x == other.tilt_x && | 417 tilt_x == other.tilt_x && |
438 tilt_y == other.tilt_y; | 418 tilt_y == other.tilt_y; |
439 } | 419 } |
440 | 420 |
441 // For serialization. | |
442 friend struct IPC::ParamTraits<ui::PointerDetails>; | |
443 | |
444 // The type of pointer device. | 421 // The type of pointer device. |
445 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; | 422 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; |
446 | 423 |
447 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. | 424 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
448 float radius_x = 0.0; | 425 float radius_x = 0.0; |
449 | 426 |
450 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 427 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
451 float radius_y = 0.0; | 428 float radius_y = 0.0; |
452 | 429 |
453 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means | 430 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 533 |
557 // Updates the button that changed. | 534 // Updates the button that changed. |
558 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 535 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
559 | 536 |
560 // Event details common to MouseEvent and TouchEvent. | 537 // Event details common to MouseEvent and TouchEvent. |
561 const PointerDetails& pointer_details() const { return pointer_details_; } | 538 const PointerDetails& pointer_details() const { return pointer_details_; } |
562 void set_pointer_details(const PointerDetails& details) { | 539 void set_pointer_details(const PointerDetails& details) { |
563 pointer_details_ = details; | 540 pointer_details_ = details; |
564 } | 541 } |
565 | 542 |
566 protected: | |
567 // For (de)serialization. | |
568 MouseEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
569 : LocatedEvent(type, time_stamp, flags) {} | |
570 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
571 friend struct IPC::ParamTraits<ui::MouseEvent>; | |
572 | |
573 private: | 543 private: |
574 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 544 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
575 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 545 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
576 | 546 |
577 // Returns the repeat count based on the previous mouse click, if it is | 547 // Returns the repeat count based on the previous mouse click, if it is |
578 // recent enough and within a small enough distance. | 548 // recent enough and within a small enough distance. |
579 static int GetRepeatCount(const MouseEvent& click_event); | 549 static int GetRepeatCount(const MouseEvent& click_event); |
580 | 550 |
581 // Resets the last_click_event_ for unit tests. | 551 // Resets the last_click_event_ for unit tests. |
582 static void ResetLastClickForTest(); | 552 static void ResetLastClickForTest(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 int flags, | 593 int flags, |
624 int changed_button_flags); | 594 int changed_button_flags); |
625 | 595 |
626 // The amount to scroll. This is in multiples of kWheelDelta. | 596 // The amount to scroll. This is in multiples of kWheelDelta. |
627 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. | 597 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. |
628 int x_offset() const { return offset_.x(); } | 598 int x_offset() const { return offset_.x(); } |
629 int y_offset() const { return offset_.y(); } | 599 int y_offset() const { return offset_.y(); } |
630 const gfx::Vector2d& offset() const { return offset_; } | 600 const gfx::Vector2d& offset() const { return offset_; } |
631 | 601 |
632 private: | 602 private: |
633 // For (de)serialization. | |
634 MouseWheelEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
635 : MouseEvent(type, time_stamp, flags) {} | |
636 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
637 friend struct IPC::ParamTraits<ui::MouseWheelEvent>; | |
638 | |
639 gfx::Vector2d offset_; | 603 gfx::Vector2d offset_; |
640 }; | 604 }; |
641 | 605 |
642 class EVENTS_EXPORT TouchEvent : public LocatedEvent { | 606 class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
643 public: | 607 public: |
644 explicit TouchEvent(const base::NativeEvent& native_event); | 608 explicit TouchEvent(const base::NativeEvent& native_event); |
645 | 609 |
646 // |pointer_event.IsTouchPointerEvent()| must be true. | 610 // |pointer_event.IsTouchPointerEvent()| must be true. |
647 explicit TouchEvent(const PointerEvent& pointer_event); | 611 explicit TouchEvent(const PointerEvent& pointer_event); |
648 | 612 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 return !!(result() & ER_DISABLE_SYNC_HANDLING); | 668 return !!(result() & ER_DISABLE_SYNC_HANDLING); |
705 } | 669 } |
706 | 670 |
707 // Event details common to MouseEvent and TouchEvent. | 671 // Event details common to MouseEvent and TouchEvent. |
708 const PointerDetails& pointer_details() const { return pointer_details_; } | 672 const PointerDetails& pointer_details() const { return pointer_details_; } |
709 void set_pointer_details(const PointerDetails& pointer_details) { | 673 void set_pointer_details(const PointerDetails& pointer_details) { |
710 pointer_details_ = pointer_details; | 674 pointer_details_ = pointer_details; |
711 } | 675 } |
712 | 676 |
713 private: | 677 private: |
714 // For (de)serialization. | |
715 TouchEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
716 : LocatedEvent(type, time_stamp, flags), | |
717 should_remove_native_touch_id_mapping_(false) {} | |
718 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
719 friend struct IPC::ParamTraits<ui::TouchEvent>; | |
720 | |
721 // Adjusts rotation_angle_ to within the acceptable range. | 678 // Adjusts rotation_angle_ to within the acceptable range. |
722 void FixRotationAngle(); | 679 void FixRotationAngle(); |
723 | 680 |
724 // The identity (typically finger) of the touch starting at 0 and incrementing | 681 // The identity (typically finger) of the touch starting at 0 and incrementing |
725 // for each separable additional touch that the hardware can detect. | 682 // for each separable additional touch that the hardware can detect. |
726 int touch_id_; | 683 int touch_id_; |
727 | 684 |
728 // A unique identifier for the touch event. | 685 // A unique identifier for the touch event. |
729 uint32_t unique_event_id_; | 686 uint32_t unique_event_id_; |
730 | 687 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 EventPointerType pointer_type, | 721 EventPointerType pointer_type, |
765 const gfx::Point& location, | 722 const gfx::Point& location, |
766 const gfx::Point& root_location, | 723 const gfx::Point& root_location, |
767 int flags, | 724 int flags, |
768 int pointer_id, | 725 int pointer_id, |
769 base::TimeDelta time_stamp); | 726 base::TimeDelta time_stamp); |
770 | 727 |
771 int32_t pointer_id() const { return pointer_id_; } | 728 int32_t pointer_id() const { return pointer_id_; } |
772 const PointerDetails& pointer_details() const { return details_; } | 729 const PointerDetails& pointer_details() const { return details_; } |
773 | 730 |
774 protected: | |
775 // For (de)serialization. | |
776 PointerEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
777 : LocatedEvent(type, time_stamp, flags) {} | |
778 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
779 friend struct IPC::ParamTraits<ui::PointerEvent>; | |
780 | |
781 private: | 731 private: |
782 int32_t pointer_id_; | 732 int32_t pointer_id_; |
783 PointerDetails details_; | 733 PointerDetails details_; |
784 }; | 734 }; |
785 | 735 |
786 // An interface that individual platforms can use to store additional data on | 736 // An interface that individual platforms can use to store additional data on |
787 // KeyEvent. | 737 // KeyEvent. |
788 // | 738 // |
789 // Currently only used in mojo. | 739 // Currently only used in mojo. |
790 class EVENTS_EXPORT ExtendedKeyEventData { | 740 class EVENTS_EXPORT ExtendedKeyEventData { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 // (Native X11 event flags describe the state before the event.) | 891 // (Native X11 event flags describe the state before the event.) |
942 void NormalizeFlags(); | 892 void NormalizeFlags(); |
943 | 893 |
944 protected: | 894 protected: |
945 friend class KeyEventTestApi; | 895 friend class KeyEventTestApi; |
946 | 896 |
947 // This allows a subclass TranslatedKeyEvent to be a non character event. | 897 // This allows a subclass TranslatedKeyEvent to be a non character event. |
948 void set_is_char(bool is_char) { is_char_ = is_char; } | 898 void set_is_char(bool is_char) { is_char_ = is_char; } |
949 | 899 |
950 private: | 900 private: |
951 // For (de)serialization. | |
952 KeyEvent(EventType type, base::TimeDelta time_stamp, int flags); | |
953 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
954 friend struct IPC::ParamTraits<ui::KeyEvent>; | |
955 | |
956 // Determine key_ on a keystroke event from code_ and flags(). | 901 // Determine key_ on a keystroke event from code_ and flags(). |
957 void ApplyLayout() const; | 902 void ApplyLayout() const; |
958 | 903 |
959 KeyboardCode key_code_; | 904 KeyboardCode key_code_; |
960 | 905 |
961 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). | 906 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). |
962 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 907 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
963 // | 908 // |
964 // This value represents the physical position in the keyboard and can be | 909 // This value represents the physical position in the keyboard and can be |
965 // converted from / to keyboard scan code like XKB. | 910 // converted from / to keyboard scan code like XKB. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 // to provide a consistent user experience. | 969 // to provide a consistent user experience. |
1025 void Scale(const float factor); | 970 void Scale(const float factor); |
1026 | 971 |
1027 float x_offset() const { return x_offset_; } | 972 float x_offset() const { return x_offset_; } |
1028 float y_offset() const { return y_offset_; } | 973 float y_offset() const { return y_offset_; } |
1029 float x_offset_ordinal() const { return x_offset_ordinal_; } | 974 float x_offset_ordinal() const { return x_offset_ordinal_; } |
1030 float y_offset_ordinal() const { return y_offset_ordinal_; } | 975 float y_offset_ordinal() const { return y_offset_ordinal_; } |
1031 int finger_count() const { return finger_count_; } | 976 int finger_count() const { return finger_count_; } |
1032 | 977 |
1033 private: | 978 private: |
1034 // For (de)serialization. | |
1035 ScrollEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
1036 : MouseEvent(type, time_stamp, flags) {} | |
1037 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
1038 friend struct IPC::ParamTraits<ui::ScrollEvent>; | |
1039 | |
1040 // Potential accelerated offsets. | 979 // Potential accelerated offsets. |
1041 float x_offset_; | 980 float x_offset_; |
1042 float y_offset_; | 981 float y_offset_; |
1043 // Unaccelerated offsets. | 982 // Unaccelerated offsets. |
1044 float x_offset_ordinal_; | 983 float x_offset_ordinal_; |
1045 float y_offset_ordinal_; | 984 float y_offset_ordinal_; |
1046 // Number of fingers on the pad. | 985 // Number of fingers on the pad. |
1047 int finger_count_; | 986 int finger_count_; |
1048 }; | 987 }; |
1049 | 988 |
(...skipping 12 matching lines...) Expand all Loading... |
1062 GestureEvent(const GestureEvent& model, T* source, T* target) | 1001 GestureEvent(const GestureEvent& model, T* source, T* target) |
1063 : LocatedEvent(model, source, target), | 1002 : LocatedEvent(model, source, target), |
1064 details_(model.details_) { | 1003 details_(model.details_) { |
1065 } | 1004 } |
1066 | 1005 |
1067 ~GestureEvent() override; | 1006 ~GestureEvent() override; |
1068 | 1007 |
1069 const GestureEventDetails& details() const { return details_; } | 1008 const GestureEventDetails& details() const { return details_; } |
1070 | 1009 |
1071 private: | 1010 private: |
1072 // For (de)serialization. | |
1073 GestureEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
1074 : LocatedEvent(type, time_stamp, flags) {} | |
1075 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
1076 friend struct IPC::ParamTraits<ui::GestureEvent>; | |
1077 | |
1078 GestureEventDetails details_; | 1011 GestureEventDetails details_; |
1079 }; | 1012 }; |
1080 | 1013 |
1081 } // namespace ui | 1014 } // namespace ui |
1082 | 1015 |
1083 #endif // UI_EVENTS_EVENT_H_ | 1016 #endif // UI_EVENTS_EVENT_H_ |
OLD | NEW |