| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 401 |
| 402 // |location_| multiplied by an optional transformation matrix for | 402 // |location_| multiplied by an optional transformation matrix for |
| 403 // rotations, animations and skews. | 403 // rotations, animations and skews. |
| 404 gfx::PointF root_location_; | 404 gfx::PointF root_location_; |
| 405 }; | 405 }; |
| 406 | 406 |
| 407 // Structure for handling common fields between touch and mouse to support | 407 // Structure for handling common fields between touch and mouse to support |
| 408 // PointerEvents API. | 408 // PointerEvents API. |
| 409 struct EVENTS_EXPORT PointerDetails { | 409 struct EVENTS_EXPORT PointerDetails { |
| 410 public: | 410 public: |
| 411 PointerDetails() {} | 411 PointerDetails(); |
| 412 explicit PointerDetails(EventPointerType pointer_type) | 412 explicit PointerDetails(EventPointerType pointer_type, uint32_t id = 0); |
| 413 : pointer_type(pointer_type), | |
| 414 force(std::numeric_limits<float>::quiet_NaN()) {} | |
| 415 PointerDetails(EventPointerType pointer_type, | 413 PointerDetails(EventPointerType pointer_type, |
| 416 float radius_x, | 414 float radius_x, |
| 417 float radius_y, | 415 float radius_y, |
| 418 float force, | 416 float force, |
| 419 float tilt_x, | 417 float tilt_x, |
| 420 float tilt_y, | 418 float tilt_y, |
| 421 float tangential_pressure = 0.0f, | 419 float tangential_pressure = 0.0f, |
| 422 int twist = 0) | 420 int twist = 0, |
| 423 : pointer_type(pointer_type), | 421 uint32_t id = 0); |
| 424 // If we aren't provided with a radius on one axis, use the | 422 PointerDetails(EventPointerType pointer_type, const gfx::Vector2d& offset); |
| 425 // information from the other axis. | 423 PointerDetails(const PointerDetails& other); |
| 426 radius_x(radius_x > 0 ? radius_x : radius_y), | |
| 427 radius_y(radius_y > 0 ? radius_y : radius_x), | |
| 428 force(force), | |
| 429 tilt_x(tilt_x), | |
| 430 tilt_y(tilt_y), | |
| 431 tangential_pressure(tangential_pressure), | |
| 432 twist(twist) {} | |
| 433 PointerDetails(EventPointerType pointer_type, const gfx::Vector2d& offset) | |
| 434 : pointer_type(pointer_type), | |
| 435 force(std::numeric_limits<float>::quiet_NaN()), | |
| 436 offset(offset) {} | |
| 437 | 424 |
| 438 bool operator==(const PointerDetails& other) const { | 425 bool operator==(const PointerDetails& other) const { |
| 439 return pointer_type == other.pointer_type && radius_x == other.radius_x && | 426 return pointer_type == other.pointer_type && radius_x == other.radius_x && |
| 440 radius_y == other.radius_y && | 427 radius_y == other.radius_y && |
| 441 (force == other.force || | 428 (force == other.force || |
| 442 (std::isnan(force) && std::isnan(other.force))) && | 429 (std::isnan(force) && std::isnan(other.force))) && |
| 443 tilt_x == other.tilt_x && tilt_y == other.tilt_y && | 430 tilt_x == other.tilt_x && tilt_y == other.tilt_y && |
| 444 tangential_pressure == other.tangential_pressure && | 431 tangential_pressure == other.tangential_pressure && |
| 445 twist == other.twist && offset == other.offset; | 432 twist == other.twist && id == other.id && offset == other.offset; |
| 446 } | 433 } |
| 447 | 434 |
| 448 // The type of pointer device. | 435 // The type of pointer device. |
| 449 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; | 436 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; |
| 450 | 437 |
| 451 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. | 438 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
| 452 float radius_x = 0.0; | 439 float radius_x = 0.0; |
| 453 | 440 |
| 454 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 441 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
| 455 float radius_y = 0.0; | 442 float radius_y = 0.0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 467 // The normalized tangential pressure (or barrel pressure), typically set by | 454 // The normalized tangential pressure (or barrel pressure), typically set by |
| 468 // an additional control of the stylus, which has a range of [-1,1], where 0 | 455 // an additional control of the stylus, which has a range of [-1,1], where 0 |
| 469 // is the neutral position of the control. Always 0 if the device does not | 456 // is the neutral position of the control. Always 0 if the device does not |
| 470 // support it. | 457 // support it. |
| 471 float tangential_pressure = 0.0; | 458 float tangential_pressure = 0.0; |
| 472 | 459 |
| 473 // The clockwise rotation of a pen stylus around its own major axis, in | 460 // The clockwise rotation of a pen stylus around its own major axis, in |
| 474 // degrees in the range [0,359]. Always 0 if the device does not support it. | 461 // degrees in the range [0,359]. Always 0 if the device does not support it. |
| 475 int twist = 0; | 462 int twist = 0; |
| 476 | 463 |
| 464 // An identifier that uniquely identifies a pointer during its lifetime. |
| 465 uint32_t id = 0; |
| 466 |
| 477 // Only used by mouse wheel events. The amount to scroll. This is in multiples | 467 // Only used by mouse wheel events. The amount to scroll. This is in multiples |
| 478 // of kWheelDelta. | 468 // of kWheelDelta. |
| 479 // Note: offset_.x() > 0/offset_.y() > 0 means scroll left/up. | 469 // Note: offset_.x() > 0/offset_.y() > 0 means scroll left/up. |
| 480 gfx::Vector2d offset; | 470 gfx::Vector2d offset; |
| 481 }; | 471 }; |
| 482 | 472 |
| 483 class EVENTS_EXPORT MouseEvent : public LocatedEvent { | 473 class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| 484 public: | 474 public: |
| 485 explicit MouseEvent(const base::NativeEvent& native_event); | 475 explicit MouseEvent(const base::NativeEvent& native_event); |
| 486 | 476 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 | 646 |
| 657 // |pointer_event.IsTouchPointerEvent()| must be true. | 647 // |pointer_event.IsTouchPointerEvent()| must be true. |
| 658 explicit TouchEvent(const PointerEvent& pointer_event); | 648 explicit TouchEvent(const PointerEvent& pointer_event); |
| 659 | 649 |
| 660 // Create a new TouchEvent which is identical to the provided model. | 650 // Create a new TouchEvent which is identical to the provided model. |
| 661 // If source / target windows are provided, the model location will be | 651 // If source / target windows are provided, the model location will be |
| 662 // converted from |source| coordinate system to |target| coordinate system. | 652 // converted from |source| coordinate system to |target| coordinate system. |
| 663 template <class T> | 653 template <class T> |
| 664 TouchEvent(const TouchEvent& model, T* source, T* target) | 654 TouchEvent(const TouchEvent& model, T* source, T* target) |
| 665 : LocatedEvent(model, source, target), | 655 : LocatedEvent(model, source, target), |
| 666 touch_id_(model.touch_id_), | |
| 667 unique_event_id_(model.unique_event_id_), | 656 unique_event_id_(model.unique_event_id_), |
| 668 rotation_angle_(model.rotation_angle_), | 657 rotation_angle_(model.rotation_angle_), |
| 669 may_cause_scrolling_(model.may_cause_scrolling_), | 658 may_cause_scrolling_(model.may_cause_scrolling_), |
| 670 should_remove_native_touch_id_mapping_(false), | 659 should_remove_native_touch_id_mapping_(false), |
| 671 pointer_details_(model.pointer_details_) {} | 660 pointer_details_(model.pointer_details_) {} |
| 672 | 661 |
| 673 TouchEvent(EventType type, | 662 TouchEvent(EventType type, |
| 674 const gfx::Point& location, | 663 const gfx::Point& location, |
| 675 int touch_id, | 664 uint32_t touch_id, |
| 676 base::TimeTicks time_stamp); | 665 base::TimeTicks time_stamp); |
| 677 | 666 |
| 678 TouchEvent(EventType type, | 667 TouchEvent(EventType type, |
| 679 const gfx::Point& location, | 668 const gfx::Point& location, |
| 680 int flags, | 669 int flags, |
| 681 int touch_id, | 670 uint32_t touch_id, |
| 682 base::TimeTicks timestamp, | 671 base::TimeTicks timestamp, |
| 683 float radius_x, | 672 float radius_x, |
| 684 float radius_y, | 673 float radius_y, |
| 685 float angle, | 674 float angle, |
| 686 float force); | 675 float force); |
| 687 | 676 |
| 688 TouchEvent(const TouchEvent& copy); | 677 TouchEvent(const TouchEvent& copy); |
| 689 | 678 |
| 690 ~TouchEvent() override; | 679 ~TouchEvent() override; |
| 691 | 680 |
| 692 // The id of the pointer this event modifies. | |
| 693 int touch_id() const { return touch_id_; } | |
| 694 // A unique identifier for this event. | 681 // A unique identifier for this event. |
| 695 uint32_t unique_event_id() const { return unique_event_id_; } | 682 uint32_t unique_event_id() const { return unique_event_id_; } |
| 696 | 683 |
| 697 float rotation_angle() const { return rotation_angle_; } | 684 float rotation_angle() const { return rotation_angle_; } |
| 698 | 685 |
| 699 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; } | 686 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; } |
| 700 bool may_cause_scrolling() const { return may_cause_scrolling_; } | 687 bool may_cause_scrolling() const { return may_cause_scrolling_; } |
| 701 | 688 |
| 702 void set_should_remove_native_touch_id_mapping( | 689 void set_should_remove_native_touch_id_mapping( |
| 703 bool should_remove_native_touch_id_mapping) { | 690 bool should_remove_native_touch_id_mapping) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 718 // Event details common to MouseEvent and TouchEvent. | 705 // Event details common to MouseEvent and TouchEvent. |
| 719 const PointerDetails& pointer_details() const { return pointer_details_; } | 706 const PointerDetails& pointer_details() const { return pointer_details_; } |
| 720 void set_pointer_details(const PointerDetails& pointer_details) { | 707 void set_pointer_details(const PointerDetails& pointer_details) { |
| 721 pointer_details_ = pointer_details; | 708 pointer_details_ = pointer_details; |
| 722 } | 709 } |
| 723 | 710 |
| 724 private: | 711 private: |
| 725 // Adjusts rotation_angle_ to within the acceptable range. | 712 // Adjusts rotation_angle_ to within the acceptable range. |
| 726 void FixRotationAngle(); | 713 void FixRotationAngle(); |
| 727 | 714 |
| 728 // The identity (typically finger) of the touch starting at 0 and incrementing | |
| 729 // for each separable additional touch that the hardware can detect. | |
| 730 int touch_id_; | |
| 731 | |
| 732 // A unique identifier for the touch event. | 715 // A unique identifier for the touch event. |
| 733 uint32_t unique_event_id_; | 716 uint32_t unique_event_id_; |
| 734 | 717 |
| 735 // Clockwise angle (in degrees) of the major axis from the X axis. Must be | 718 // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
| 736 // less than 180 and non-negative. | 719 // less than 180 and non-negative. |
| 737 float rotation_angle_; | 720 float rotation_angle_; |
| 738 | 721 |
| 739 // Whether the (unhandled) touch event will produce a scroll event (e.g., a | 722 // Whether the (unhandled) touch event will produce a scroll event (e.g., a |
| 740 // touchmove that exceeds the platform slop region, or a touchend that | 723 // touchmove that exceeds the platform slop region, or a touchend that |
| 741 // causes a fling). Defaults to false. | 724 // causes a fling). Defaults to false. |
| 742 bool may_cause_scrolling_; | 725 bool may_cause_scrolling_; |
| 743 | 726 |
| 744 // True if this event should remove the mapping between the native | 727 // True if this event should remove the mapping between the native |
| 745 // event id and the touch_id_. This should only be the case for | 728 // event id and the touch_id_. This should only be the case for |
| 746 // release and cancel events where the associated touch press event | 729 // release and cancel events where the associated touch press event |
| 747 // created a mapping between the native id and the touch_id_. | 730 // created a mapping between the native id and the touch_id_. |
| 748 bool should_remove_native_touch_id_mapping_; | 731 bool should_remove_native_touch_id_mapping_; |
| 749 | 732 |
| 750 // Structure for holding pointer details for implementing PointerEvents API. | 733 // Structure for holding pointer details for implementing PointerEvents API. |
| 751 PointerDetails pointer_details_; | 734 PointerDetails pointer_details_; |
| 752 }; | 735 }; |
| 753 | 736 |
| 754 class EVENTS_EXPORT PointerEvent : public LocatedEvent { | 737 class EVENTS_EXPORT PointerEvent : public LocatedEvent { |
| 755 public: | 738 public: |
| 756 static const int32_t kMousePointerId; | 739 static const uint32_t kMousePointerId; |
| 757 | 740 |
| 758 // Returns true if a PointerEvent can be constructed from |event|. Currently, | 741 // Returns true if a PointerEvent can be constructed from |event|. Currently, |
| 759 // only mouse and touch events can be converted to pointer events. | 742 // only mouse and touch events can be converted to pointer events. |
| 760 static bool CanConvertFrom(const Event& event); | 743 static bool CanConvertFrom(const Event& event); |
| 761 | 744 |
| 762 PointerEvent(const PointerEvent& pointer_event); | 745 PointerEvent(const PointerEvent& pointer_event); |
| 763 explicit PointerEvent(const MouseEvent& mouse_event); | 746 explicit PointerEvent(const MouseEvent& mouse_event); |
| 764 explicit PointerEvent(const TouchEvent& touch_event); | 747 explicit PointerEvent(const TouchEvent& touch_event); |
| 765 | 748 |
| 766 PointerEvent(EventType type, | 749 PointerEvent(EventType type, |
| 767 const gfx::Point& location, | 750 const gfx::Point& location, |
| 768 const gfx::Point& root_location, | 751 const gfx::Point& root_location, |
| 769 int flags, | 752 int flags, |
| 770 int pointer_id, | 753 uint32_t pointer_id, |
| 771 int changed_button_flags, | 754 int changed_button_flags, |
| 772 const PointerDetails& pointer_details, | 755 const PointerDetails& pointer_details, |
| 773 base::TimeTicks time_stamp); | 756 base::TimeTicks time_stamp); |
| 774 | 757 |
| 775 int32_t pointer_id() const { return pointer_id_; } | |
| 776 int changed_button_flags() const { return changed_button_flags_; } | 758 int changed_button_flags() const { return changed_button_flags_; } |
| 777 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 759 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
| 778 const PointerDetails& pointer_details() const { return details_; } | 760 const PointerDetails& pointer_details() const { return details_; } |
| 779 | 761 |
| 780 private: | 762 private: |
| 781 int32_t pointer_id_; | |
| 782 int changed_button_flags_; | 763 int changed_button_flags_; |
| 783 PointerDetails details_; | 764 PointerDetails details_; |
| 784 }; | 765 }; |
| 785 | 766 |
| 786 // A KeyEvent is really two distinct classes, melded together due to the | 767 // A KeyEvent is really two distinct classes, melded together due to the |
| 787 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), | 768 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), |
| 788 // or a character event (is_char_ == true). | 769 // or a character event (is_char_ == true). |
| 789 // | 770 // |
| 790 // For a keystroke event, | 771 // For a keystroke event, |
| 791 // -- |bool is_char_| is false. | 772 // -- |bool is_char_| is false. |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 // dispatched. This field gets a non-zero value only for gestures that are | 1034 // dispatched. This field gets a non-zero value only for gestures that are |
| 1054 // released through TouchDispositionGestureFilter::SendGesture. The gesture | 1035 // released through TouchDispositionGestureFilter::SendGesture. The gesture |
| 1055 // events that aren't fired directly in response to processing a touch-event | 1036 // events that aren't fired directly in response to processing a touch-event |
| 1056 // (e.g. timer fired ones), this id is zero. See crbug.com/618738. | 1037 // (e.g. timer fired ones), this id is zero. See crbug.com/618738. |
| 1057 uint32_t unique_touch_event_id_; | 1038 uint32_t unique_touch_event_id_; |
| 1058 }; | 1039 }; |
| 1059 | 1040 |
| 1060 } // namespace ui | 1041 } // namespace ui |
| 1061 | 1042 |
| 1062 #endif // UI_EVENTS_EVENT_H_ | 1043 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |