| 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, int pointer_id = -1); |
| 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 int pointer_id = -1); |
| 424 // If we aren't provided with a radius on one axis, use the | 422 PointerDetails(EventPointerType pointer_type, |
| 425 // information from the other axis. | 423 const gfx::Vector2d& pointer_offset, |
| 426 radius_x(radius_x > 0 ? radius_x : radius_y), | 424 int pointer_id = -1); |
| 427 radius_y(radius_y > 0 ? radius_y : radius_x), | 425 PointerDetails(const PointerDetails& other); |
| 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 | 426 |
| 438 bool operator==(const PointerDetails& other) const { | 427 bool operator==(const PointerDetails& other) const { |
| 439 return pointer_type == other.pointer_type && radius_x == other.radius_x && | 428 return pointer_type == other.pointer_type && radius_x == other.radius_x && |
| 440 radius_y == other.radius_y && | 429 radius_y == other.radius_y && |
| 441 (force == other.force || | 430 (force == other.force || |
| 442 (std::isnan(force) && std::isnan(other.force))) && | 431 (std::isnan(force) && std::isnan(other.force))) && |
| 443 tilt_x == other.tilt_x && tilt_y == other.tilt_y && | 432 tilt_x == other.tilt_x && tilt_y == other.tilt_y && |
| 444 tangential_pressure == other.tangential_pressure && | 433 tangential_pressure == other.tangential_pressure && |
| 445 twist == other.twist && offset == other.offset; | 434 twist == other.twist && id == other.id && offset == other.offset; |
| 446 } | 435 } |
| 447 | 436 |
| 437 // A value for pointer id which means it needs to be initialized for all |
| 438 // pointer types. |
| 439 static const int kUnknownPointerId; |
| 440 |
| 448 // The type of pointer device. | 441 // The type of pointer device. |
| 449 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; | 442 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; |
| 450 | 443 |
| 451 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. | 444 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
| 452 float radius_x = 0.0; | 445 float radius_x = 0.0; |
| 453 | 446 |
| 454 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 447 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
| 455 float radius_y = 0.0; | 448 float radius_y = 0.0; |
| 456 | 449 |
| 457 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means | 450 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means |
| 458 // pressure is not supported by the input device. | 451 // pressure is not supported by the input device. |
| 459 float force = 0.0; | 452 float force = 0.0; |
| 460 | 453 |
| 461 // Tilt of a pen/stylus from surface normal as plane angle in degrees, values | 454 // Tilt of a pen/stylus from surface normal as plane angle in degrees, values |
| 462 // lie in [-90,90]. A positive tilt_x is to the right and a positive tilt_y | 455 // lie in [-90,90]. A positive tilt_x is to the right and a positive tilt_y |
| 463 // is towards the user. 0.0 if unknown. | 456 // is towards the user. 0.0 if unknown. |
| 464 float tilt_x = 0.0; | 457 float tilt_x = 0.0; |
| 465 float tilt_y = 0.0; | 458 float tilt_y = 0.0; |
| 466 | 459 |
| 467 // The normalized tangential pressure (or barrel pressure), typically set by | 460 // 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 | 461 // 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 | 462 // is the neutral position of the control. Always 0 if the device does not |
| 470 // support it. | 463 // support it. |
| 471 float tangential_pressure = 0.0; | 464 float tangential_pressure = 0.0; |
| 472 | 465 |
| 473 // The clockwise rotation of a pen stylus around its own major axis, in | 466 // 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. | 467 // degrees in the range [0,359]. Always 0 if the device does not support it. |
| 475 int twist = 0; | 468 int twist = 0; |
| 476 | 469 |
| 470 // An identifier that uniquely identifies a pointer during its lifetime. |
| 471 int id = 0; |
| 472 |
| 477 // Only used by mouse wheel events. The amount to scroll. This is in multiples | 473 // Only used by mouse wheel events. The amount to scroll. This is in multiples |
| 478 // of kWheelDelta. | 474 // of kWheelDelta. |
| 479 // Note: offset_.x() > 0/offset_.y() > 0 means scroll left/up. | 475 // Note: offset_.x() > 0/offset_.y() > 0 means scroll left/up. |
| 480 gfx::Vector2d offset; | 476 gfx::Vector2d offset; |
| 481 }; | 477 }; |
| 482 | 478 |
| 483 class EVENTS_EXPORT MouseEvent : public LocatedEvent { | 479 class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| 484 public: | 480 public: |
| 485 explicit MouseEvent(const base::NativeEvent& native_event); | 481 explicit MouseEvent(const base::NativeEvent& native_event); |
| 486 | 482 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 | 652 |
| 657 // |pointer_event.IsTouchPointerEvent()| must be true. | 653 // |pointer_event.IsTouchPointerEvent()| must be true. |
| 658 explicit TouchEvent(const PointerEvent& pointer_event); | 654 explicit TouchEvent(const PointerEvent& pointer_event); |
| 659 | 655 |
| 660 // Create a new TouchEvent which is identical to the provided model. | 656 // Create a new TouchEvent which is identical to the provided model. |
| 661 // If source / target windows are provided, the model location will be | 657 // If source / target windows are provided, the model location will be |
| 662 // converted from |source| coordinate system to |target| coordinate system. | 658 // converted from |source| coordinate system to |target| coordinate system. |
| 663 template <class T> | 659 template <class T> |
| 664 TouchEvent(const TouchEvent& model, T* source, T* target) | 660 TouchEvent(const TouchEvent& model, T* source, T* target) |
| 665 : LocatedEvent(model, source, target), | 661 : LocatedEvent(model, source, target), |
| 666 touch_id_(model.touch_id_), | |
| 667 unique_event_id_(model.unique_event_id_), | 662 unique_event_id_(model.unique_event_id_), |
| 668 rotation_angle_(model.rotation_angle_), | 663 rotation_angle_(model.rotation_angle_), |
| 669 may_cause_scrolling_(model.may_cause_scrolling_), | 664 may_cause_scrolling_(model.may_cause_scrolling_), |
| 670 should_remove_native_touch_id_mapping_(false), | 665 should_remove_native_touch_id_mapping_(false), |
| 671 pointer_details_(model.pointer_details_) {} | 666 pointer_details_(model.pointer_details_) {} |
| 672 | 667 |
| 673 TouchEvent(EventType type, | 668 TouchEvent(EventType type, |
| 674 const gfx::Point& location, | 669 const gfx::Point& location, |
| 675 int touch_id, | 670 int touch_id, |
| 676 base::TimeTicks time_stamp); | 671 base::TimeTicks time_stamp); |
| 677 | 672 |
| 678 TouchEvent(EventType type, | 673 TouchEvent(EventType type, |
| 679 const gfx::Point& location, | 674 const gfx::Point& location, |
| 680 int flags, | 675 int flags, |
| 681 int touch_id, | 676 int touch_id, |
| 682 base::TimeTicks timestamp, | 677 base::TimeTicks timestamp, |
| 683 float radius_x, | 678 float radius_x, |
| 684 float radius_y, | 679 float radius_y, |
| 685 float angle, | 680 float angle, |
| 686 float force); | 681 float force); |
| 687 | 682 |
| 688 TouchEvent(const TouchEvent& copy); | 683 TouchEvent(const TouchEvent& copy); |
| 689 | 684 |
| 690 ~TouchEvent() override; | 685 ~TouchEvent() override; |
| 691 | 686 |
| 692 // The id of the pointer this event modifies. | |
| 693 int touch_id() const { return touch_id_; } | |
| 694 // A unique identifier for this event. | 687 // A unique identifier for this event. |
| 695 uint32_t unique_event_id() const { return unique_event_id_; } | 688 uint32_t unique_event_id() const { return unique_event_id_; } |
| 696 | 689 |
| 697 float rotation_angle() const { return rotation_angle_; } | 690 float rotation_angle() const { return rotation_angle_; } |
| 698 | 691 |
| 699 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; } | 692 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; } |
| 700 bool may_cause_scrolling() const { return may_cause_scrolling_; } | 693 bool may_cause_scrolling() const { return may_cause_scrolling_; } |
| 701 | 694 |
| 702 void set_should_remove_native_touch_id_mapping( | 695 void set_should_remove_native_touch_id_mapping( |
| 703 bool should_remove_native_touch_id_mapping) { | 696 bool should_remove_native_touch_id_mapping) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 718 // Event details common to MouseEvent and TouchEvent. | 711 // Event details common to MouseEvent and TouchEvent. |
| 719 const PointerDetails& pointer_details() const { return pointer_details_; } | 712 const PointerDetails& pointer_details() const { return pointer_details_; } |
| 720 void set_pointer_details(const PointerDetails& pointer_details) { | 713 void set_pointer_details(const PointerDetails& pointer_details) { |
| 721 pointer_details_ = pointer_details; | 714 pointer_details_ = pointer_details; |
| 722 } | 715 } |
| 723 | 716 |
| 724 private: | 717 private: |
| 725 // Adjusts rotation_angle_ to within the acceptable range. | 718 // Adjusts rotation_angle_ to within the acceptable range. |
| 726 void FixRotationAngle(); | 719 void FixRotationAngle(); |
| 727 | 720 |
| 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. | 721 // A unique identifier for the touch event. |
| 733 uint32_t unique_event_id_; | 722 uint32_t unique_event_id_; |
| 734 | 723 |
| 735 // Clockwise angle (in degrees) of the major axis from the X axis. Must be | 724 // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
| 736 // less than 180 and non-negative. | 725 // less than 180 and non-negative. |
| 737 float rotation_angle_; | 726 float rotation_angle_; |
| 738 | 727 |
| 739 // Whether the (unhandled) touch event will produce a scroll event (e.g., a | 728 // 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 | 729 // touchmove that exceeds the platform slop region, or a touchend that |
| 741 // causes a fling). Defaults to false. | 730 // causes a fling). Defaults to false. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 765 | 754 |
| 766 PointerEvent(EventType type, | 755 PointerEvent(EventType type, |
| 767 const gfx::Point& location, | 756 const gfx::Point& location, |
| 768 const gfx::Point& root_location, | 757 const gfx::Point& root_location, |
| 769 int flags, | 758 int flags, |
| 770 int pointer_id, | 759 int pointer_id, |
| 771 int changed_button_flags, | 760 int changed_button_flags, |
| 772 const PointerDetails& pointer_details, | 761 const PointerDetails& pointer_details, |
| 773 base::TimeTicks time_stamp); | 762 base::TimeTicks time_stamp); |
| 774 | 763 |
| 775 int32_t pointer_id() const { return pointer_id_; } | |
| 776 int changed_button_flags() const { return changed_button_flags_; } | 764 int changed_button_flags() const { return changed_button_flags_; } |
| 777 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 765 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
| 778 const PointerDetails& pointer_details() const { return details_; } | 766 const PointerDetails& pointer_details() const { return details_; } |
| 779 | 767 |
| 780 private: | 768 private: |
| 781 int32_t pointer_id_; | |
| 782 int changed_button_flags_; | 769 int changed_button_flags_; |
| 783 PointerDetails details_; | 770 PointerDetails details_; |
| 784 }; | 771 }; |
| 785 | 772 |
| 786 // A KeyEvent is really two distinct classes, melded together due to the | 773 // 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), | 774 // DOM legacy of Windows key events: a keystroke event (is_char_ == false), |
| 788 // or a character event (is_char_ == true). | 775 // or a character event (is_char_ == true). |
| 789 // | 776 // |
| 790 // For a keystroke event, | 777 // For a keystroke event, |
| 791 // -- |bool is_char_| is false. | 778 // -- |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 | 1040 // dispatched. This field gets a non-zero value only for gestures that are |
| 1054 // released through TouchDispositionGestureFilter::SendGesture. The gesture | 1041 // released through TouchDispositionGestureFilter::SendGesture. The gesture |
| 1055 // events that aren't fired directly in response to processing a touch-event | 1042 // 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. | 1043 // (e.g. timer fired ones), this id is zero. See crbug.com/618738. |
| 1057 uint32_t unique_touch_event_id_; | 1044 uint32_t unique_touch_event_id_; |
| 1058 }; | 1045 }; |
| 1059 | 1046 |
| 1060 } // namespace ui | 1047 } // namespace ui |
| 1061 | 1048 |
| 1062 #endif // UI_EVENTS_EVENT_H_ | 1049 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |