| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ | 5 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ |
| 6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ | 6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/events/event_constants.h" | 9 #include "ui/events/event_constants.h" |
| 10 #include "ui/events/events_base_export.h" | 10 #include "ui/events/events_base_export.h" |
| 11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 12 #include "ui/gfx/rect_conversions.h" | 12 #include "ui/gfx/rect_conversions.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 | 15 |
| 16 struct EVENTS_BASE_EXPORT GestureEventDetails { | 16 struct EVENTS_BASE_EXPORT GestureEventDetails { |
| 17 public: | 17 public: |
| 18 GestureEventDetails(); | 18 GestureEventDetails(); |
| 19 explicit GestureEventDetails(EventType type); | 19 explicit GestureEventDetails(EventType type); |
| 20 GestureEventDetails(EventType type, float delta_x, float delta_y); | 20 GestureEventDetails(EventType type, float delta_x, float delta_y); |
| 21 | 21 |
| 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); |
| 25 |
| 22 EventType type() const { return type_; } | 26 EventType type() const { return type_; } |
| 23 | 27 |
| 24 int touch_points() const { return touch_points_; } | 28 int touch_points() const { return touch_points_; } |
| 25 void set_touch_points(int touch_points) { | 29 void set_touch_points(int touch_points) { |
| 26 DCHECK_GT(touch_points, 0); | 30 DCHECK_GT(touch_points, 0); |
| 27 touch_points_ = touch_points; | 31 touch_points_ = touch_points; |
| 28 } | 32 } |
| 29 | 33 |
| 30 int oldest_touch_id() const { return oldest_touch_id_; } | 34 int oldest_touch_id() const { return oldest_touch_id_; } |
| 31 void set_oldest_touch_id(int oldest_touch_id) { | 35 void set_oldest_touch_id(int oldest_touch_id) { |
| 32 DCHECK_GE(oldest_touch_id, 0); | 36 DCHECK_GE(oldest_touch_id, 0); |
| 33 oldest_touch_id_ = oldest_touch_id; | 37 oldest_touch_id_ = oldest_touch_id; |
| 34 } | 38 } |
| 35 | 39 |
| 36 // TODO(tdresser): Return RectF. See crbug.com/337824. | 40 // TODO(tdresser): Return RectF. See crbug.com/337824. |
| 37 const gfx::Rect bounding_box() const { | 41 const gfx::Rect bounding_box() const { |
| 38 return ToEnclosingRect(bounding_box_); | 42 return ToEnclosingRect(bounding_box_); |
| 39 } | 43 } |
| 40 | 44 |
| 41 const gfx::RectF& bounding_box_f() const { | 45 const gfx::RectF& bounding_box_f() const { |
| 42 return bounding_box_; | 46 return bounding_box_; |
| 43 } | 47 } |
| 44 | 48 |
| 45 void set_bounding_box(const gfx::RectF& box) { bounding_box_ = box; } | 49 void set_bounding_box(const gfx::RectF& box) { bounding_box_ = box; } |
| 46 | 50 |
| 47 float scroll_x_hint() const { | 51 float scroll_x_hint() const { |
| 48 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN, type_); | 52 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN, type_); |
| 49 return data.scroll_begin.x_hint; | 53 return data_.scroll_begin.x_hint; |
| 50 } | 54 } |
| 51 | 55 |
| 52 float scroll_y_hint() const { | 56 float scroll_y_hint() const { |
| 53 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN, type_); | 57 DCHECK_EQ(ET_GESTURE_SCROLL_BEGIN, type_); |
| 54 return data.scroll_begin.y_hint; | 58 return data_.scroll_begin.y_hint; |
| 55 } | 59 } |
| 56 | 60 |
| 57 float scroll_x() const { | 61 float scroll_x() const { |
| 58 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_); | 62 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_); |
| 59 return data.scroll_update.x; | 63 return data_.scroll_update.x; |
| 60 } | 64 } |
| 61 | 65 |
| 62 float scroll_y() const { | 66 float scroll_y() const { |
| 63 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_); | 67 DCHECK_EQ(ET_GESTURE_SCROLL_UPDATE, type_); |
| 64 return data.scroll_update.y; | 68 return data_.scroll_update.y; |
| 65 } | 69 } |
| 66 | 70 |
| 67 float velocity_x() const { | 71 float velocity_x() const { |
| 68 DCHECK_EQ(ET_SCROLL_FLING_START, type_); | 72 DCHECK_EQ(ET_SCROLL_FLING_START, type_); |
| 69 return data.fling_velocity.x; | 73 return data_.fling_velocity.x; |
| 70 } | 74 } |
| 71 | 75 |
| 72 float velocity_y() const { | 76 float velocity_y() const { |
| 73 DCHECK_EQ(ET_SCROLL_FLING_START, type_); | 77 DCHECK_EQ(ET_SCROLL_FLING_START, type_); |
| 74 return data.fling_velocity.y; | 78 return data_.fling_velocity.y; |
| 75 } | 79 } |
| 76 | 80 |
| 77 float first_finger_width() const { | 81 float first_finger_width() const { |
| 78 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP, type_); | 82 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP, type_); |
| 79 return data.first_finger_enclosing_rectangle.width; | 83 return data_.first_finger_enclosing_rectangle.width; |
| 80 } | 84 } |
| 81 | 85 |
| 82 float first_finger_height() const { | 86 float first_finger_height() const { |
| 83 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP, type_); | 87 DCHECK_EQ(ET_GESTURE_TWO_FINGER_TAP, type_); |
| 84 return data.first_finger_enclosing_rectangle.height; | 88 return data_.first_finger_enclosing_rectangle.height; |
| 85 } | 89 } |
| 86 | 90 |
| 87 float scale() const { | 91 float scale() const { |
| 88 DCHECK_EQ(ET_GESTURE_PINCH_UPDATE, type_); | 92 DCHECK_EQ(ET_GESTURE_PINCH_UPDATE, type_); |
| 89 return data.scale; | 93 return data_.scale; |
| 90 } | 94 } |
| 91 | 95 |
| 92 bool swipe_left() const { | 96 bool swipe_left() const { |
| 93 DCHECK_EQ(ET_GESTURE_SWIPE, type_); | 97 DCHECK_EQ(ET_GESTURE_SWIPE, type_); |
| 94 return data.swipe.left; | 98 return data_.swipe.left; |
| 95 } | 99 } |
| 96 | 100 |
| 97 bool swipe_right() const { | 101 bool swipe_right() const { |
| 98 DCHECK_EQ(ET_GESTURE_SWIPE, type_); | 102 DCHECK_EQ(ET_GESTURE_SWIPE, type_); |
| 99 return data.swipe.right; | 103 return data_.swipe.right; |
| 100 } | 104 } |
| 101 | 105 |
| 102 bool swipe_up() const { | 106 bool swipe_up() const { |
| 103 DCHECK_EQ(ET_GESTURE_SWIPE, type_); | 107 DCHECK_EQ(ET_GESTURE_SWIPE, type_); |
| 104 return data.swipe.up; | 108 return data_.swipe.up; |
| 105 } | 109 } |
| 106 | 110 |
| 107 bool swipe_down() const { | 111 bool swipe_down() const { |
| 108 DCHECK_EQ(ET_GESTURE_SWIPE, type_); | 112 DCHECK_EQ(ET_GESTURE_SWIPE, type_); |
| 109 return data.swipe.down; | 113 return data_.swipe.down; |
| 110 } | 114 } |
| 111 | 115 |
| 112 int tap_count() const { | 116 int tap_count() const { |
| 113 DCHECK(type_ == ET_GESTURE_TAP || | 117 DCHECK(type_ == ET_GESTURE_TAP || |
| 114 type_ == ET_GESTURE_TAP_UNCONFIRMED || | 118 type_ == ET_GESTURE_TAP_UNCONFIRMED || |
| 115 type_ == ET_GESTURE_DOUBLE_TAP); | 119 type_ == ET_GESTURE_DOUBLE_TAP); |
| 116 return data.tap_count; | 120 return data_.tap_count; |
| 117 } | 121 } |
| 118 | 122 |
| 119 void set_tap_count(int tap_count) { | 123 void set_tap_count(int tap_count) { |
| 120 DCHECK_GE(tap_count, 0); | 124 DCHECK_GE(tap_count, 0); |
| 121 DCHECK(type_ == ET_GESTURE_TAP || | 125 DCHECK(type_ == ET_GESTURE_TAP || |
| 122 type_ == ET_GESTURE_TAP_UNCONFIRMED || | 126 type_ == ET_GESTURE_TAP_UNCONFIRMED || |
| 123 type_ == ET_GESTURE_DOUBLE_TAP); | 127 type_ == ET_GESTURE_DOUBLE_TAP); |
| 124 data.tap_count = tap_count; | 128 data_.tap_count = tap_count; |
| 125 } | 129 } |
| 126 | 130 |
| 127 void set_scale(float scale) { | 131 void set_scale(float scale) { |
| 128 DCHECK_GE(scale, 0.0f); | 132 DCHECK_GE(scale, 0.0f); |
| 129 DCHECK_EQ(type_, ET_GESTURE_PINCH_UPDATE); | 133 DCHECK_EQ(type_, ET_GESTURE_PINCH_UPDATE); |
| 130 data.scale = scale; | 134 data_.scale = scale; |
| 135 } |
| 136 |
| 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; |
| 140 } |
| 141 |
| 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; |
| 131 } | 145 } |
| 132 | 146 |
| 133 private: | 147 private: |
| 134 EventType type_; | 148 EventType type_; |
| 135 union Details { | 149 union Details { |
| 136 Details(); | 150 Details(); |
| 137 struct { // SCROLL start details. | 151 struct { // SCROLL start details. |
| 138 // Distance that caused the scroll to start. Generally redundant with | 152 // Distance that caused the scroll to start. Generally redundant with |
| 139 // the x/y values from the first scroll_update. | 153 // the x/y values from the first scroll_update. |
| 140 float x_hint; | 154 float x_hint; |
| 141 float y_hint; | 155 float y_hint; |
| 142 } scroll_begin; | 156 } scroll_begin; |
| 143 | 157 |
| 144 struct { // SCROLL delta. | 158 struct { // SCROLL delta. |
| 145 float x; | 159 float x; |
| 146 float y; | 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; |
| 147 } scroll_update; | 164 } scroll_update; |
| 148 | 165 |
| 149 float scale; // PINCH scale. | 166 float scale; // PINCH scale. |
| 150 | 167 |
| 151 struct { // FLING velocity. | 168 struct { // FLING velocity. |
| 152 float x; | 169 float x; |
| 153 float y; | 170 float y; |
| 154 } fling_velocity; | 171 } fling_velocity; |
| 155 | 172 |
| 156 // Dimensions of the first finger's enclosing rectangle for | 173 // Dimensions of the first finger's enclosing rectangle for |
| 157 // TWO_FINGER_TAP. | 174 // TWO_FINGER_TAP. |
| 158 struct { | 175 struct { |
| 159 float width; | 176 float width; |
| 160 float height; | 177 float height; |
| 161 } first_finger_enclosing_rectangle; | 178 } first_finger_enclosing_rectangle; |
| 162 | 179 |
| 163 struct { // SWIPE direction. | 180 struct { // SWIPE direction. |
| 164 bool left; | 181 bool left; |
| 165 bool right; | 182 bool right; |
| 166 bool up; | 183 bool up; |
| 167 bool down; | 184 bool down; |
| 168 } swipe; | 185 } swipe; |
| 169 | 186 |
| 170 // Tap information must be set for ET_GESTURE_TAP, | 187 // Tap information must be set for ET_GESTURE_TAP, |
| 171 // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events. | 188 // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events. |
| 172 int tap_count; // TAP repeat count. | 189 int tap_count; // TAP repeat count. |
| 173 } data; | 190 } data_; |
| 174 | 191 |
| 175 int touch_points_; // Number of active touch points in the gesture. | 192 int touch_points_; // Number of active touch points in the gesture. |
| 176 | 193 |
| 177 // Bounding box is an axis-aligned rectangle that contains all the | 194 // Bounding box is an axis-aligned rectangle that contains all the |
| 178 // enclosing rectangles of the touch-points in the gesture. | 195 // enclosing rectangles of the touch-points in the gesture. |
| 179 gfx::RectF bounding_box_; | 196 gfx::RectF bounding_box_; |
| 180 | 197 |
| 181 // The touch id of the oldest touch contributing to the gesture. | 198 // The touch id of the oldest touch contributing to the gesture. |
| 182 int oldest_touch_id_; | 199 int oldest_touch_id_; |
| 183 }; | 200 }; |
| 184 | 201 |
| 185 } // namespace ui | 202 } // namespace ui |
| 186 | 203 |
| 187 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ | 204 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ |
| OLD | NEW |