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/rect.h"
12 #include "ui/gfx/rect_conversions.h"
16 struct EVENTS_BASE_EXPORT GestureEventDetails
{
18 GestureEventDetails();
19 GestureEventDetails(EventType type
, float delta_x
, float delta_y
);
21 EventType
type() const { return type_
; }
23 int touch_points() const { return touch_points_
; }
24 void set_touch_points(int touch_points
) {
25 DCHECK_GT(touch_points
, 0);
26 touch_points_
= touch_points
;
29 int oldest_touch_id() const { return oldest_touch_id_
; }
30 void set_oldest_touch_id(int oldest_touch_id
) {
31 DCHECK_GE(oldest_touch_id
, 0);
32 oldest_touch_id_
= oldest_touch_id
;
35 // TODO(tdresser): Return RectF. See crbug.com/337824.
36 const gfx::Rect
bounding_box() const {
37 return ToEnclosingRect(bounding_box_
);
40 const gfx::RectF
& bounding_box_f() const {
44 void set_bounding_box(const gfx::RectF
& box
) { bounding_box_
= box
; }
46 float scroll_x_hint() const {
47 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN
, type_
);
48 return data
.scroll_begin
.x_hint
;
51 float scroll_y_hint() const {
52 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN
, type_
);
53 return data
.scroll_begin
.y_hint
;
56 float scroll_x() const {
57 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE
, type_
);
58 return data
.scroll_update
.x
;
61 float scroll_y() const {
62 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE
, type_
);
63 return data
.scroll_update
.y
;
66 float velocity_x() const {
67 DCHECK_EQ(ET_SCROLL_FLING_START
, type_
);
68 return data
.fling_velocity
.x
;
71 float velocity_y() const {
72 DCHECK_EQ(ET_SCROLL_FLING_START
, type_
);
73 return data
.fling_velocity
.y
;
76 float first_finger_width() const {
77 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP
, type_
);
78 return data
.first_finger_enclosing_rectangle
.width
;
81 float first_finger_height() const {
82 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP
, type_
);
83 return data
.first_finger_enclosing_rectangle
.height
;
87 DCHECK_EQ(ET_GESTURE_PINCH_UPDATE
, type_
);
91 bool swipe_left() const {
92 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
93 return data
.swipe
.left
;
96 bool swipe_right() const {
97 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
98 return data
.swipe
.right
;
101 bool swipe_up() const {
102 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
103 return data
.swipe
.up
;
106 bool swipe_down() const {
107 DCHECK_EQ(ET_GESTURE_SWIPE
, type_
);
108 return data
.swipe
.down
;
111 int tap_count() const {
112 DCHECK(type_
== ET_GESTURE_TAP
||
113 type_
== ET_GESTURE_TAP_UNCONFIRMED
||
114 type_
== ET_GESTURE_DOUBLE_TAP
);
115 return data
.tap_count
;
118 void set_tap_count(int tap_count
) {
119 DCHECK_GE(tap_count
, 0);
120 DCHECK(type_
== ET_GESTURE_TAP
||
121 type_
== ET_GESTURE_TAP_UNCONFIRMED
||
122 type_
== ET_GESTURE_DOUBLE_TAP
);
123 data
.tap_count
= tap_count
;
130 struct { // SCROLL start details.
131 // Distance that caused the scroll to start. Generally redundant with
132 // the x/y values from the first scroll_update.
137 struct { // SCROLL delta.
142 float scale
; // PINCH scale.
144 struct { // FLING velocity.
149 // Dimensions of the first finger's enclosing rectangle for
154 } first_finger_enclosing_rectangle
;
156 struct { // SWIPE direction.
163 // Tap information must be set for ET_GESTURE_TAP,
164 // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events.
165 int tap_count
; // TAP repeat count.
168 int touch_points_
; // Number of active touch points in the gesture.
170 // Bounding box is an axis-aligned rectangle that contains all the
171 // enclosing rectangles of the touch-points in the gesture.
172 gfx::RectF bounding_box_
;
174 // The touch id of the oldest touch contributing to the gesture.
175 int oldest_touch_id_
;
180 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_