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

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

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

Powered by Google App Engine
This is Rietveld 408576698