Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gesture_event_details.h
blob58d28fa7f946ce4c73a3af3ba33f8179b21217ad
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"
14 namespace ui {
16 struct EVENTS_BASE_EXPORT GestureEventDetails {
17 public:
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 {
41 return bounding_box_;
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;
86 float scale() const {
87 DCHECK_EQ(ET_GESTURE_PINCH_UPDATE, type_);
88 return data.scale;
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;
126 private:
127 EventType type_;
128 union Details {
129 Details();
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.
133 float x_hint;
134 float y_hint;
135 } scroll_begin;
137 struct { // SCROLL delta.
138 float x;
139 float y;
140 } scroll_update;
142 float scale; // PINCH scale.
144 struct { // FLING velocity.
145 float x;
146 float y;
147 } fling_velocity;
149 // Dimensions of the first finger's enclosing rectangle for
150 // TWO_FINGER_TAP.
151 struct {
152 float width;
153 float height;
154 } first_finger_enclosing_rectangle;
156 struct { // SWIPE direction.
157 bool left;
158 bool right;
159 bool up;
160 bool down;
161 } swipe;
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.
166 } data;
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_;
178 } // namespace ui
180 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_