Chromium Code Reviews| Index: ui/events/event.h |
| diff --git a/ui/events/event.h b/ui/events/event.h |
| index 49d650a5d70bb0bb066063c19a2630efc3a59eac..a48230c4956be592bde14fea82aa251717994a38 100644 |
| --- a/ui/events/event.h |
| +++ b/ui/events/event.h |
| @@ -322,6 +322,63 @@ class EVENTS_EXPORT LocatedEvent : public Event { |
| gfx::PointF root_location_; |
| }; |
| +// Structure for handling common fields between touch and mouse to support |
| +// PointerEvents API. |
| +class EVENTS_EXPORT PointerDetails { |
| + public: |
| + PointerDetails() {} |
| + explicit PointerDetails(EventPointerType pointer_type) |
| + : pointer_type_(pointer_type) {} |
| + PointerDetails(EventPointerType pointer_type, |
| + float radius_x, |
| + float radius_y, |
| + float force, |
| + float tilt_x, |
| + float tilt_y) |
| + : pointer_type_(pointer_type), |
| + radius_x_(radius_x), |
| + radius_y_(radius_y), |
| + force_(force), |
| + tilt_x_(tilt_x), |
| + tilt_y_(tilt_y) {} |
| + |
| + EventPointerType pointer_type() const { return pointer_type_; }; |
| + |
| + // If we aren't provided with a radius on one axis, use the |
| + // information from the other axis. |
| + float radius_x() const { return radius_x_ > 0 ? radius_x_ : radius_y_; } |
| + float radius_y() const { return radius_y_ > 0 ? radius_y_ : radius_x_; } |
| + float force() const { return force_; } |
| + float tilt_x() const { return tilt_x_; } |
| + float tilt_y() const { return tilt_y_; } |
| + |
| + void set_pointer_type(EventPointerType type) { pointer_type_ = type; } |
| + void set_radius_x(float r) { radius_x_ = r; } |
| + void set_radius_y(float r) { radius_y_ = r; } |
| + void set_force(float f) { force_ = f; } |
| + void set_tilt_x(float t) { tilt_x_ = t; } |
| + void set_tilt_y(float t) { tilt_y_ = t; } |
| + |
| + private: |
| + // The type of pointer device. |
| + EventPointerType pointer_type_ = EventPointerType::POINTER_TYPE_UNKNOWN; |
| + |
| + // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
| + float radius_x_ = 0.0; |
| + |
| + // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
| + float radius_y_ = 0.0; |
| + |
| + // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. |
| + float force_ = 0.0; |
| + |
| + // Angle of tilt of the X (major) axis. 0.0 if unknown. |
| + float tilt_x_ = 0.0; |
| + |
| + // Angle of tilt of the Y (minor) axis. 0.0 if unknown. |
| + float tilt_y_ = 0.0; |
| +}; |
| + |
| class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| public: |
| explicit MouseEvent(const base::NativeEvent& native_event); |
| @@ -333,8 +390,8 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| template <class T> |
| MouseEvent(const MouseEvent& model, T* source, T* target) |
| : LocatedEvent(model, source, target), |
| - changed_button_flags_(model.changed_button_flags_) { |
| - } |
| + changed_button_flags_(model.changed_button_flags_), |
| + pointer_details_(model.pointer_details_) {} |
| template <class T> |
| MouseEvent(const MouseEvent& model, |
| @@ -343,7 +400,8 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| EventType type, |
| int flags) |
| : LocatedEvent(model, source, target), |
| - changed_button_flags_(model.changed_button_flags_) { |
| + changed_button_flags_(model.changed_button_flags_), |
| + pointer_details_(model.pointer_details_) { |
| SetType(type); |
| set_flags(flags); |
| } |
| @@ -407,6 +465,9 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| // Updates the button that changed. |
| void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
| + // Event details common to MouseEvent and TouchEvent. |
| + PointerDetails* pointer_details() { return &pointer_details_; } |
| + |
| private: |
| FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
| FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
| @@ -434,6 +495,9 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { |
| // to true when the next event either has a different timestamp or we see a |
| // release signalling that the press (click) event was completed. |
| static bool last_click_complete_; |
| + |
| + // Structure for holding pointer details for implementing PointerEvents API. |
| + PointerDetails pointer_details_; |
| }; |
| class ScrollEvent; |
| @@ -486,12 +550,10 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
| : LocatedEvent(model, source, target), |
| touch_id_(model.touch_id_), |
| unique_event_id_(model.unique_event_id_), |
| - radius_x_(model.radius_x_), |
| - radius_y_(model.radius_y_), |
| rotation_angle_(model.rotation_angle_), |
| - force_(model.force_), |
| may_cause_scrolling_(model.may_cause_scrolling_), |
| - should_remove_native_touch_id_mapping_(false) {} |
| + should_remove_native_touch_id_mapping_(false), |
| + pointer_details_(model.pointer_details_) {} |
| TouchEvent(EventType type, |
| const gfx::PointF& location, |
| @@ -516,19 +578,21 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
| int touch_id() const { return touch_id_; } |
| // A unique identifier for this event. |
| uint32 unique_event_id() const { return unique_event_id_; } |
| - // If we aren't provided with a radius on one axis, use the |
| - // information from the other axis. |
| - float radius_x() const { return radius_x_ > 0 ? radius_x_ : radius_y_; } |
| - float radius_y() const { return radius_y_ > 0 ? radius_y_ : radius_x_; } |
| + |
| + // TODO(robert.bradford): Drop these shims. |
| + float radius_x() const { return pointer_details_.radius_x(); } |
| + float radius_y() const { return pointer_details_.radius_y(); } |
| + float force() const { return pointer_details_.force(); } |
| + |
| float rotation_angle() const { return rotation_angle_; } |
| - float force() const { return force_; } |
| void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; } |
| bool may_cause_scrolling() const { return may_cause_scrolling_; } |
| - // Used for unit tests. |
| - void set_radius_x(const float r) { radius_x_ = r; } |
| - void set_radius_y(const float r) { radius_y_ = r; } |
| + // TODO(robert.bradford): ozone_platform_egltest.cc could use |
| + // UpdateForRootTransform() instead: crbug.com/519337 |
| + void set_radius_x(const float r) { pointer_details()->set_radius_x(r); } |
| + void set_radius_y(const float r) { pointer_details()->set_radius_y(r); } |
| void set_should_remove_native_touch_id_mapping( |
| bool should_remove_native_touch_id_mapping) { |
| @@ -546,6 +610,9 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
| return !!(result() & ER_DISABLE_SYNC_HANDLING); |
| } |
| + // Event details common to MouseEvent and TouchEvent. |
| + PointerDetails* pointer_details() { return &pointer_details_; } |
|
sadrul
2015/08/17 14:44:43
Can this return a const& instead?
The callers sho
|
| + |
| private: |
| // Adjusts rotation_angle_ to within the acceptable range. |
| void FixRotationAngle(); |
| @@ -557,19 +624,10 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
| // A unique identifier for the touch event. |
| const uint32 unique_event_id_; |
| - // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
| - float radius_x_; |
| - |
| - // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
| - float radius_y_; |
| - |
| // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
| // less than 180 and non-negative. |
| float rotation_angle_; |
| - // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. |
| - float force_; |
| - |
| // Whether the (unhandled) touch event will produce a scroll event (e.g., a |
| // touchmove that exceeds the platform slop region, or a touchend that |
| // causes a fling). Defaults to false. |
| @@ -580,6 +638,9 @@ class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
| // release and cancel events where the associated touch press event |
| // created a mapping between the native id and the touch_id_. |
| bool should_remove_native_touch_id_mapping_; |
| + |
| + // Structure for holding pointer details for implementing PointerEvents API. |
| + PointerDetails pointer_details_; |
| }; |
| // An interface that individual platforms can use to store additional data on |