Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: ui/base/gestures/gesture_types.h

Issue 10837329: gesture: Include velocity in scroll-update gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 GestureSequence;
16 class TouchEvent; 17 class TouchEvent;
17 18
18 struct UI_EXPORT GestureEventDetails { 19 struct UI_EXPORT GestureEventDetails {
19 public: 20 public:
20 GestureEventDetails(EventType type, float delta_x, float delta_y); 21 GestureEventDetails(EventType type, float delta_x, float delta_y);
21 22
22 EventType type() const { return type_; } 23 EventType type() const { return type_; }
23 24
24 int touch_points() const { return touch_points_; } 25 int touch_points() const { return 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; }
29 28
30 float scroll_x() const { 29 float scroll_x() const {
31 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); 30 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
32 return data.scroll.x; 31 return data.scroll.x;
33 } 32 }
33
34 float scroll_y() const { 34 float scroll_y() const {
35 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); 35 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
36 return data.scroll.y; 36 return data.scroll.y;
37 } 37 }
38 38
39 float velocity_x() const { 39 float velocity_x() const {
40 CHECK_EQ(ui::ET_SCROLL_FLING_START, type_); 40 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
41 return data.velocity.x; 41 type_ == ui::ET_SCROLL_FLING_START);
42 return type_ == ui::ET_GESTURE_SCROLL_UPDATE ? data.scroll.velocity_x :
43 data.velocity.x;
42 } 44 }
45
43 float velocity_y() const { 46 float velocity_y() const {
44 CHECK_EQ(ui::ET_SCROLL_FLING_START, type_); 47 CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
45 return data.velocity.y; 48 type_ == ui::ET_SCROLL_FLING_START);
49 return type_ == ui::ET_GESTURE_SCROLL_UPDATE ? data.scroll.velocity_y :
50 data.velocity.y;
46 } 51 }
47 52
48 int touch_id() const { 53 int touch_id() const {
49 CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_); 54 CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_);
50 return data.touch_id; 55 return data.touch_id;
51 } 56 }
52 57
53 float scale() const { 58 float scale() const {
54 CHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_); 59 CHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_);
55 return data.scale; 60 return data.scale;
56 } 61 }
57 62
58 bool swipe_left() const { 63 bool swipe_left() const {
59 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); 64 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
60 return data.swipe.left; 65 return data.swipe.left;
61 } 66 }
67
62 bool swipe_right() const { 68 bool swipe_right() const {
63 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); 69 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
64 return data.swipe.right; 70 return data.swipe.right;
65 } 71 }
72
66 bool swipe_up() const { 73 bool swipe_up() const {
67 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); 74 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
68 return data.swipe.up; 75 return data.swipe.up;
69 } 76 }
77
70 bool swipe_down() const { 78 bool swipe_down() const {
71 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); 79 CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
72 return data.swipe.down; 80 return data.swipe.down;
73 } 81 }
74 82
75 int tap_count() const { 83 int tap_count() const {
76 CHECK_EQ(ui::ET_GESTURE_TAP, type_); 84 CHECK_EQ(ui::ET_GESTURE_TAP, type_);
77 return data.tap_count; 85 return data.tap_count;
78 } 86 }
79 87
80 private: 88 private:
89 friend class GestureSequence;
rjkroege 2012/08/20 14:52:17 grumble.
sadrul 2012/08/20 15:48:34 This is mostly to allow only GestureSequence to be
90
91 void set_touch_points(int touch_points) { touch_points_ = touch_points; }
92 void set_bounding_box(const gfx::Rect& box) { bounding_box_ = box; }
93 void SetScrollVelocity(float velocity_x, float velocity_y);
94
81 ui::EventType type_; 95 ui::EventType type_;
82 union { 96 union {
83 struct { // SCROLL delta. 97 struct { // SCROLL delta.
84 float x; 98 float x;
85 float y; 99 float y;
100 float velocity_x;
101 float velocity_y;
86 } scroll; 102 } scroll;
87 103
88 float scale; // PINCH scale. 104 float scale; // PINCH scale.
89 105
90 struct { // FLING velocity. 106 struct { // FLING velocity.
91 float x; 107 float x;
92 float y; 108 float y;
93 } velocity; 109 } velocity;
rjkroege 2012/08/20 14:52:17 it would be nice to align these fields with the un
sadrul 2012/08/20 15:48:34 I think these match the change in WebGestuerEvent
94 110
95 int touch_id; // LONG_PRESS touch-id. 111 int touch_id; // LONG_PRESS touch-id.
96 112
97 struct { // SWIPE direction. 113 struct { // SWIPE direction.
98 bool left; 114 bool left;
99 bool right; 115 bool right;
100 bool up; 116 bool up;
101 bool down; 117 bool down;
102 } swipe; 118 } swipe;
103 119
104 int tap_count; // TAP repeat count. 120 int tap_count; // TAP repeat count.
105
106 struct {
107 float delta_x;
108 float delta_y;
109 } generic;
110 } data; 121 } data;
111 122
112 int touch_points_; // Number of active touch points in the gesture. 123 int touch_points_; // Number of active touch points in the gesture.
113 124
114 // Bounding box is an axis-aligned rectangle that contains all the 125 // Bounding box is an axis-aligned rectangle that contains all the
115 // enclosing rectangles of the touch-points in the gesture. 126 // enclosing rectangles of the touch-points in the gesture.
116 gfx::Rect bounding_box_; 127 gfx::Rect bounding_box_;
117 }; 128 };
118 129
119 // An abstract type for consumers of gesture-events created by the 130 // An abstract type for consumers of gesture-events created by the
(...skipping 25 matching lines...) Expand all
145 virtual ~GestureEventHelper() { 156 virtual ~GestureEventHelper() {
146 } 157 }
147 158
148 virtual bool DispatchLongPressGestureEvent(GestureEvent* event) = 0; 159 virtual bool DispatchLongPressGestureEvent(GestureEvent* event) = 0;
149 virtual bool DispatchCancelTouchEvent(TouchEvent* event) = 0; 160 virtual bool DispatchCancelTouchEvent(TouchEvent* event) = 0;
150 }; 161 };
151 162
152 } // namespace ui 163 } // namespace ui
153 164
154 #endif // UI_BASE_GESTURES_GESTURE_TYPES_H_ 165 #endif // UI_BASE_GESTURES_GESTURE_TYPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698