OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_BASE_GESTURES_GESTURE_TYPES_H_ | 5 #ifndef UI_BASE_GESTURES_GESTURE_TYPES_H_ |
6 #define UI_BASE_GESTURES_GESTURE_TYPES_H_ | 6 #define UI_BASE_GESTURES_GESTURE_TYPES_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "ui/base/events.h" | 10 #include "ui/base/events.h" |
11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 class GestureEvent; | 15 class GestureEvent; |
16 class TouchEvent; | 16 class TouchEvent; |
17 | 17 |
18 struct UI_EXPORT GestureEventDetails { | 18 struct UI_EXPORT GestureEventDetails { |
19 public: | 19 public: |
20 GestureEventDetails(EventType type, float delta_x, float delta_y); | 20 GestureEventDetails(EventType type, float delta_x, float delta_y); |
21 | 21 |
22 EventType type() const { return type_; } | 22 EventType type() const { return type_; } |
23 | 23 |
24 int touch_points() const { return touch_points_; } | 24 int touch_points() const { return touch_points_; } |
25 void set_touch_points(int touch_points) { touch_points_ = touch_points; } | 25 void set_touch_points(int touch_points) { touch_points_ = touch_points; } |
26 | 26 |
27 const gfx::Rect& bounding_box() const { return bounding_box_; } | 27 const gfx::Rect& bounding_box() const { return bounding_box_; } |
28 void set_bounding_box(const gfx::Rect& box) { bounding_box_ = box; } | 28 void set_bounding_box(const gfx::Rect& box) { bounding_box_ = box; } |
29 | 29 |
| 30 void SetScrollVelocity(float velocity_x, float velocity_y); |
| 31 |
30 float scroll_x() const { | 32 float scroll_x() const { |
31 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); | 33 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); |
32 return data.scroll.x; | 34 return data.scroll_update.x; |
33 } | 35 } |
| 36 |
34 float scroll_y() const { | 37 float scroll_y() const { |
35 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); | 38 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); |
36 return data.scroll.y; | 39 return data.scroll_update.y; |
37 } | 40 } |
38 | 41 |
39 float velocity_x() const { | 42 float velocity_x() const { |
40 CHECK_EQ(ui::ET_SCROLL_FLING_START, type_); | 43 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || |
41 return data.velocity.x; | 44 type_ == ui::ET_SCROLL_FLING_START); |
| 45 return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.x : |
| 46 data.scroll_update.velocity_x; |
42 } | 47 } |
| 48 |
43 float velocity_y() const { | 49 float velocity_y() const { |
44 CHECK_EQ(ui::ET_SCROLL_FLING_START, type_); | 50 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || |
45 return data.velocity.y; | 51 type_ == ui::ET_SCROLL_FLING_START); |
| 52 return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.y : |
| 53 data.scroll_update.velocity_y; |
46 } | 54 } |
47 | 55 |
48 int touch_id() const { | 56 int touch_id() const { |
49 CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_); | 57 CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_); |
50 return data.touch_id; | 58 return data.touch_id; |
51 } | 59 } |
52 | 60 |
53 float scale() const { | 61 float scale() const { |
54 CHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_); | 62 CHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_); |
55 return data.scale; | 63 return data.scale; |
56 } | 64 } |
57 | 65 |
58 bool swipe_left() const { | 66 bool swipe_left() const { |
59 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); | 67 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); |
60 return data.swipe.left; | 68 return data.swipe.left; |
61 } | 69 } |
| 70 |
62 bool swipe_right() const { | 71 bool swipe_right() const { |
63 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); | 72 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); |
64 return data.swipe.right; | 73 return data.swipe.right; |
65 } | 74 } |
| 75 |
66 bool swipe_up() const { | 76 bool swipe_up() const { |
67 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); | 77 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); |
68 return data.swipe.up; | 78 return data.swipe.up; |
69 } | 79 } |
| 80 |
70 bool swipe_down() const { | 81 bool swipe_down() const { |
71 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); | 82 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); |
72 return data.swipe.down; | 83 return data.swipe.down; |
73 } | 84 } |
74 | 85 |
75 int tap_count() const { | 86 int tap_count() const { |
76 CHECK_EQ(ui::ET_GESTURE_TAP, type_); | 87 CHECK_EQ(ui::ET_GESTURE_TAP, type_); |
77 return data.tap_count; | 88 return data.tap_count; |
78 } | 89 } |
79 | 90 |
80 private: | 91 private: |
81 ui::EventType type_; | 92 ui::EventType type_; |
82 union { | 93 union { |
83 struct { // SCROLL delta. | 94 struct { // SCROLL delta. |
84 float x; | 95 float x; |
85 float y; | 96 float y; |
86 } scroll; | 97 float velocity_x; |
| 98 float velocity_y; |
| 99 } scroll_update; |
87 | 100 |
88 float scale; // PINCH scale. | 101 float scale; // PINCH scale. |
89 | 102 |
90 struct { // FLING velocity. | 103 struct { // FLING velocity. |
91 float x; | 104 float x; |
92 float y; | 105 float y; |
93 } velocity; | 106 } fling_velocity; |
94 | 107 |
95 int touch_id; // LONG_PRESS touch-id. | 108 int touch_id; // LONG_PRESS touch-id. |
96 | 109 |
97 struct { // SWIPE direction. | 110 struct { // SWIPE direction. |
98 bool left; | 111 bool left; |
99 bool right; | 112 bool right; |
100 bool up; | 113 bool up; |
101 bool down; | 114 bool down; |
102 } swipe; | 115 } swipe; |
103 | 116 |
104 int tap_count; // TAP repeat count. | 117 int tap_count; // TAP repeat count. |
105 | |
106 struct { | |
107 float delta_x; | |
108 float delta_y; | |
109 } generic; | |
110 } data; | 118 } data; |
111 | 119 |
112 int touch_points_; // Number of active touch points in the gesture. | 120 int touch_points_; // Number of active touch points in the gesture. |
113 | 121 |
114 // Bounding box is an axis-aligned rectangle that contains all the | 122 // Bounding box is an axis-aligned rectangle that contains all the |
115 // enclosing rectangles of the touch-points in the gesture. | 123 // enclosing rectangles of the touch-points in the gesture. |
116 gfx::Rect bounding_box_; | 124 gfx::Rect bounding_box_; |
117 }; | 125 }; |
118 | 126 |
119 // An abstract type for consumers of gesture-events created by the | 127 // An abstract type for consumers of gesture-events created by the |
(...skipping 25 matching lines...) Expand all Loading... |
145 virtual ~GestureEventHelper() { | 153 virtual ~GestureEventHelper() { |
146 } | 154 } |
147 | 155 |
148 virtual bool DispatchLongPressGestureEvent(GestureEvent* event) = 0; | 156 virtual bool DispatchLongPressGestureEvent(GestureEvent* event) = 0; |
149 virtual bool DispatchCancelTouchEvent(TouchEvent* event) = 0; | 157 virtual bool DispatchCancelTouchEvent(TouchEvent* event) = 0; |
150 }; | 158 }; |
151 | 159 |
152 } // namespace ui | 160 } // namespace ui |
153 | 161 |
154 #endif // UI_BASE_GESTURES_GESTURE_TYPES_H_ | 162 #endif // UI_BASE_GESTURES_GESTURE_TYPES_H_ |
OLD | NEW |