Add ICU message format support
[chromium-blink-merge.git] / ui / events / gesture_event_details.h
blob502df8abdf6d13a92033ee9f931eaca9a32f2cc7
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"
14 namespace ui {
16 struct EVENTS_BASE_EXPORT GestureEventDetails {
17 public:
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 // TODO(tdresser): Return RectF. See crbug.com/337824.
41 const gfx::Rect bounding_box() const {
42 return ToEnclosingRect(bounding_box_);
45 const gfx::RectF& bounding_box_f() const {
46 return bounding_box_;
49 void set_bounding_box(const gfx::RectF& box) { bounding_box_ = box; }
51 float scroll_x_hint() const {
52 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN, type_);
53 return data_.scroll_begin.x_hint;
56 float scroll_y_hint() const {
57 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN, type_);
58 return data_.scroll_begin.y_hint;
61 float scroll_x() const {
62 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_);
63 return data_.scroll_update.x;
66 float scroll_y() const {
67 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_);
68 return data_.scroll_update.y;
71 float velocity_x() const {
72 DCHECK_EQ(ET_SCROLL_FLING_START, type_);
73 return data_.fling_velocity.x;
76 float velocity_y() const {
77 DCHECK_EQ(ET_SCROLL_FLING_START, type_);
78 return data_.fling_velocity.y;
81 float first_finger_width() const {
82 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP, type_);
83 return data_.first_finger_enclosing_rectangle.width;
86 float first_finger_height() const {
87 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP, type_);
88 return data_.first_finger_enclosing_rectangle.height;
91 float scale() const {
92 DCHECK_EQ(ET_GESTURE_PINCH_UPDATE, type_);
93 return data_.scale;
96 bool swipe_left() const {
97 DCHECK_EQ(ET_GESTURE_SWIPE, type_);
98 return data_.swipe.left;
101 bool swipe_right() const {
102 DCHECK_EQ(ET_GESTURE_SWIPE, type_);
103 return data_.swipe.right;
106 bool swipe_up() const {
107 DCHECK_EQ(ET_GESTURE_SWIPE, type_);
108 return data_.swipe.up;
111 bool swipe_down() const {
112 DCHECK_EQ(ET_GESTURE_SWIPE, type_);
113 return data_.swipe.down;
116 int tap_count() const {
117 DCHECK(type_ == ET_GESTURE_TAP ||
118 type_ == ET_GESTURE_TAP_UNCONFIRMED ||
119 type_ == ET_GESTURE_DOUBLE_TAP);
120 return data_.tap_count;
123 void set_tap_count(int tap_count) {
124 DCHECK_GE(tap_count, 0);
125 DCHECK(type_ == ET_GESTURE_TAP ||
126 type_ == ET_GESTURE_TAP_UNCONFIRMED ||
127 type_ == ET_GESTURE_DOUBLE_TAP);
128 data_.tap_count = tap_count;
131 void set_scale(float scale) {
132 DCHECK_GE(scale, 0.0f);
133 DCHECK_EQ(type_, ET_GESTURE_PINCH_UPDATE);
134 data_.scale = scale;
137 void mark_previous_scroll_update_in_sequence_prevented() {
138 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_);
139 data_.scroll_update.previous_update_in_sequence_prevented = true;
142 bool previous_scroll_update_in_sequence_prevented() const {
143 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_);
144 return data_.scroll_update.previous_update_in_sequence_prevented;
147 private:
148 EventType type_;
149 union Details {
150 Details();
151 struct { // SCROLL start details.
152 // Distance that caused the scroll to start. Generally redundant with
153 // the x/y values from the first scroll_update.
154 float x_hint;
155 float y_hint;
156 } scroll_begin;
158 struct { // SCROLL delta.
159 float x;
160 float y;
161 // Whether any previous scroll update in the current scroll sequence was
162 // suppressed because the underlying touch was consumed.
163 bool previous_update_in_sequence_prevented;
164 } scroll_update;
166 float scale; // PINCH scale.
168 struct { // FLING velocity.
169 float x;
170 float y;
171 } fling_velocity;
173 // Dimensions of the first finger's enclosing rectangle for
174 // TWO_FINGER_TAP.
175 struct {
176 float width;
177 float height;
178 } first_finger_enclosing_rectangle;
180 struct { // SWIPE direction.
181 bool left;
182 bool right;
183 bool up;
184 bool down;
185 } swipe;
187 // Tap information must be set for ET_GESTURE_TAP,
188 // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events.
189 int tap_count; // TAP repeat count.
190 } data_;
192 int touch_points_; // Number of active touch points in the gesture.
194 // Bounding box is an axis-aligned rectangle that contains all the
195 // enclosing rectangles of the touch-points in the gesture.
196 gfx::RectF bounding_box_;
198 // The touch id of the oldest touch contributing to the gesture.
199 int oldest_touch_id_;
202 } // namespace ui
204 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_