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
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_GESTURES_GESTURE_TYPES_H_
6 #define UI_EVENTS_GESTURES_GESTURE_TYPES_H_
8 #include "base/logging.h"
9 #include "ui/events/event_constants.h"
10 #include "ui/events/events_export.h"
11 #include "ui/gfx/rect.h"
18 struct EVENTS_EXPORT GestureEventDetails {
20 GestureEventDetails(EventType type, float delta_x, float delta_y);
21 GestureEventDetails(EventType type,
22 float delta_x, float delta_y,
23 float delta_x_ordinal, float delta_y_ordinal);
25 EventType type() const { return type_; }
27 int touch_points() const { return touch_points_; }
28 void set_touch_points(int touch_points) { touch_points_ = touch_points; }
30 const gfx::Rect& bounding_box() const { return bounding_box_; }
31 void set_bounding_box(const gfx::Rect& box) { bounding_box_ = box; }
33 void SetScrollVelocity(float velocity_x, float velocity_y,
34 float velocity_x_ordinal, float velocity_y_ordinal);
36 float scroll_x() const {
37 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
38 return data.scroll_update.x;
41 float scroll_y() const {
42 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
43 return data.scroll_update.y;
46 float velocity_x() const {
47 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
48 type_ == ui::ET_SCROLL_FLING_START);
49 return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.x :
50 data.scroll_update.velocity_x;
53 float velocity_y() const {
54 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
55 type_ == ui::ET_SCROLL_FLING_START);
56 return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.y :
57 data.scroll_update.velocity_y;
60 // *_ordinal values are unmodified by rail based clamping.
61 float scroll_x_ordinal() const {
62 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
63 return data.scroll_update.x_ordinal;
66 float scroll_y_ordinal() const {
67 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
68 return data.scroll_update.y_ordinal;
71 float velocity_x_ordinal() const {
72 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
73 type_ == ui::ET_SCROLL_FLING_START);
74 return type_ == ui::ET_SCROLL_FLING_START ?
75 data.fling_velocity.x_ordinal :
76 data.scroll_update.velocity_x_ordinal;
79 float velocity_y_ordinal() const {
80 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
81 type_ == ui::ET_SCROLL_FLING_START);
82 return type_ == ui::ET_SCROLL_FLING_START ?
83 data.fling_velocity.y_ordinal :
84 data.scroll_update.velocity_y_ordinal;
87 int touch_id() const {
88 CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_);
92 float first_finger_width() const {
93 CHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_);
94 return data.first_finger_enclosing_rectangle.width;
97 float first_finger_height() const {
98 CHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_);
99 return data.first_finger_enclosing_rectangle.height;
102 float scale() const {
103 CHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_);
107 bool swipe_left() const {
108 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
109 return data.swipe.left;
112 bool swipe_right() const {
113 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
114 return data.swipe.right;
117 bool swipe_up() const {
118 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
119 return data.swipe.up;
122 bool swipe_down() const {
123 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
124 return data.swipe.down;
127 int tap_count() const {
128 CHECK_EQ(ui::ET_GESTURE_TAP, type_);
129 return data.tap_count;
135 struct { // SCROLL delta.
142 float velocity_x_ordinal;
143 float velocity_y_ordinal;
146 float scale; // PINCH scale.
148 struct { // FLING velocity.
155 int touch_id; // LONG_PRESS touch-id.
157 // Dimensions of the first finger's enclosing rectangle for TWO_FINGER_TAP.
161 } first_finger_enclosing_rectangle;
163 struct { // SWIPE direction.
170 int tap_count; // TAP repeat count.
173 int touch_points_; // Number of active touch points in the gesture.
175 // Bounding box is an axis-aligned rectangle that contains all the
176 // enclosing rectangles of the touch-points in the gesture.
177 gfx::Rect bounding_box_;
180 // An abstract type for consumers of gesture-events created by the
181 // gesture-recognizer.
182 class EVENTS_EXPORT GestureConsumer {
184 virtual ~GestureConsumer() {}
187 // GestureEventHelper creates implementation-specific gesture events and
188 // can dispatch them.
189 class EVENTS_EXPORT GestureEventHelper {
191 virtual ~GestureEventHelper() {
194 // Returns true if this helper can dispatch events to |consumer|.
195 virtual bool CanDispatchToConsumer(GestureConsumer* consumer) = 0;
196 virtual void DispatchPostponedGestureEvent(GestureEvent* event) = 0;
197 virtual void DispatchCancelTouchEvent(TouchEvent* event) = 0;
202 #endif // UI_EVENTS_GESTURES_GESTURE_TYPES_H_