1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_
6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_
8 #include "base/logging.h"
9 #include "ui/events/event_constants.h"
10 #include "ui/events/events_base_export.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/geometry/rect_conversions.h"
16 struct EVENTS_BASE_EXPORT GestureEventDetails
{
18 GestureEventDetails();
19 explicit GestureEventDetails(EventType type
);
20 GestureEventDetails(EventType type
, float delta_x
, float delta_y
);
22 // The caller is responsible for ensuring that the gesture data from |other|
23 // is compatible and sufficient for that expected by gestures of |type|.
24 GestureEventDetails(EventType type
, const GestureEventDetails
& other
);
26 EventType
type() const { return type_
; }
28 int touch_points() const { return touch_points_
; }
29 void set_touch_points(int touch_points
) {
30 DCHECK_GT(touch_points
, 0);
31 touch_points_
= touch_points
;
34 int oldest_touch_id() const { return oldest_touch_id_
; }
35 void set_oldest_touch_id(int oldest_touch_id
) {
36 DCHECK_GE(oldest_touch_id
, 0);
37 oldest_touch_id_
= oldest_touch_id
;
40 const gfx::Rect
bounding_box() const {
41 return ToEnclosingRect(bounding_box_
);
44 const gfx::RectF
& bounding_box_f() const {
48 void set_bounding_box(const gfx::RectF
& box
) { bounding_box_
= box
; }
50 float scroll_x_hint() const {
51 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN
, type_
);
52 return data_
.scroll_begin
.x_hint
;
55 float scroll_y_hint() const {
56 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN
, type_
);
57 return data_
.scroll_begin
.y_hint
;
60 float scroll_x() const {
61 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE
, type_
);
62 return data_
.scroll_update
.x
;
65 float scroll_y() const {
66 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE
, type_
);
67 return data_
.scroll_update
.y
;
70 float velocity_x() const {
71 DCHECK_EQ(ET_SCROLL_FLING_START
, type_
);
72 return data_
.fling_velocity
.x
;
75 float velocity_y() const {
76 DCHECK_EQ(ET_SCROLL_FLING_START
, type_
);
77 return data_
.fling_velocity
.y
;
80 float first_finger_width() const {
81 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP
, type_
);
82 return data_
.first_finger_enclosing_rectangle
.width
;
85 float first_finger_height() const {
86 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP
, type_
);
87 return data_
.first_finger_enclosing_rectangle
.height
;
91 DCHECK_EQ(ET_GESTURE_PINCH_UPDATE
, type_
);
95 bool swipe_left() const {
96 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
97 return data_
.swipe
.left
;
100 bool swipe_right() const {
101 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
102 return data_
.swipe
.right
;
105 bool swipe_up() const {
106 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
107 return data_
.swipe
.up
;
110 bool swipe_down() const {
111 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
112 return data_
.swipe
.down
;
115 int tap_count() const {
116 DCHECK(type_
== ET_GESTURE_TAP
||
117 type_
== ET_GESTURE_TAP_UNCONFIRMED
||
118 type_
== ET_GESTURE_DOUBLE_TAP
);
119 return data_
.tap_count
;
122 void set_tap_count(int tap_count
) {
123 DCHECK_GE(tap_count
, 0);
124 DCHECK(type_
== ET_GESTURE_TAP
||
125 type_
== ET_GESTURE_TAP_UNCONFIRMED
||
126 type_
== ET_GESTURE_DOUBLE_TAP
);
127 data_
.tap_count
= tap_count
;
130 void set_scale(float scale
) {
131 DCHECK_GE(scale
, 0.0f
);
132 DCHECK_EQ(type_
, ET_GESTURE_PINCH_UPDATE
);
136 void mark_previous_scroll_update_in_sequence_prevented() {
137 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE
, type_
);
138 data_
.scroll_update
.previous_update_in_sequence_prevented
= true;
141 bool previous_scroll_update_in_sequence_prevented() const {
142 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE
, type_
);
143 return data_
.scroll_update
.previous_update_in_sequence_prevented
;
150 struct { // SCROLL start details.
151 // Distance that caused the scroll to start. Generally redundant with
152 // the x/y values from the first scroll_update.
157 struct { // SCROLL delta.
160 // Whether any previous scroll update in the current scroll sequence was
161 // suppressed because the underlying touch was consumed.
162 bool previous_update_in_sequence_prevented
;
165 float scale
; // PINCH scale.
167 struct { // FLING velocity.
172 // Dimensions of the first finger's enclosing rectangle for
177 } first_finger_enclosing_rectangle
;
179 struct { // SWIPE direction.
186 // Tap information must be set for ET_GESTURE_TAP,
187 // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events.
188 int tap_count
; // TAP repeat count.
191 int touch_points_
; // Number of active touch points in the gesture.
193 // Bounding box is an axis-aligned rectangle that contains all the
194 // enclosing rectangles of the touch-points in the gesture.
195 gfx::RectF bounding_box_
;
197 // The touch id of the oldest touch contributing to the gesture.
198 int oldest_touch_id_
;
203 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_