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) { touch_points_ = touch_points; }
26 // TODO(tdresser): Return RectF. See crbug.com/337824.
27 const gfx::Rect bounding_box() const {
28 return ToEnclosingRect(bounding_box_);
31 const gfx::RectF& bounding_box_f() const {
35 void set_bounding_box(const gfx::RectF& box) { bounding_box_ = box; }
37 float scroll_x_hint() const {
38 DCHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_);
39 return data.scroll_begin.x_hint;
42 float scroll_y_hint() const {
43 DCHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_);
44 return data.scroll_begin.y_hint;
47 float scroll_x() const {
48 DCHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
49 return data.scroll_update.x;
52 float scroll_y() const {
53 DCHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
54 return data.scroll_update.y;
57 float velocity_x() const {
58 DCHECK(type_ == ui::ET_SCROLL_FLING_START);
59 return data.fling_velocity.x;
62 float velocity_y() const {
63 DCHECK(type_ == ui::ET_SCROLL_FLING_START);
64 return data.fling_velocity.y;
67 float first_finger_width() const {
68 DCHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_);
69 return data.first_finger_enclosing_rectangle.width;
72 float first_finger_height() const {
73 DCHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_);
74 return data.first_finger_enclosing_rectangle.height;
78 DCHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_);
82 bool swipe_left() const {
83 DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
84 return data.swipe.left;
87 bool swipe_right() const {
88 DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
89 return data.swipe.right;
92 bool swipe_up() const {
93 DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
97 bool swipe_down() const {
98 DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
99 return data.swipe.down;
102 int tap_count() const {
103 DCHECK(type_ == ui::ET_GESTURE_TAP ||
104 type_ == ui::ET_GESTURE_TAP_UNCONFIRMED ||
105 type_ == ET_GESTURE_DOUBLE_TAP);
106 return data.tap_count;
113 struct { // SCROLL start details.
114 // Distance that caused the scroll to start. Generally redundant with
115 // the x/y values from the first scroll_update.
120 struct { // SCROLL delta.
125 float scale; // PINCH scale.
127 struct { // FLING velocity.
132 // Dimensions of the first finger's enclosing rectangle for
137 } first_finger_enclosing_rectangle;
139 struct { // SWIPE direction.
146 // Tap information must be set for ET_GESTURE_TAP,
147 // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events.
148 int tap_count; // TAP repeat count.
151 int touch_points_; // Number of active touch points in the gesture.
153 // Bounding box is an axis-aligned rectangle that contains all the
154 // enclosing rectangles of the touch-points in the gesture.
155 gfx::RectF bounding_box_;
160 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_