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

Side by Side Diff: ui/aura/gestures/gesture_sequence.h

Issue 9104021: aura: Update GestureRecognizer to be able to process multi-point gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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_AURA_GESTURES_GESTURE_RECOGNIZER_AURA_H_ 5 #ifndef UI_AURA_GESTURES_GESTURE_SEQUENCE_H_
6 #define UI_AURA_GESTURES_GESTURE_RECOGNIZER_AURA_H_ 6 #define UI_AURA_GESTURES_GESTURE_SEQUENCE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include "ui/aura/gestures/gesture_point.h"
10 #include <queue>
11 #include <vector>
12
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/aura/aura_export.h"
16 #include "ui/aura/gestures/gesture_recognizer.h" 10 #include "ui/aura/gestures/gesture_recognizer.h"
17 #include "ui/base/events.h" 11 #include "ui/base/events.h"
18 #include "ui/gfx/point.h"
19 12
20 namespace aura { 13 namespace aura {
21 class TouchEvent; 14 class TouchEvent;
22 class GestureEvent; 15 class GestureEvent;
23 16
24 // A GestureSequence recognizes gestures from touch sequences. 17 // A GestureSequence recognizes gestures from touch sequences.
25 class AURA_EXPORT GestureSequence { 18 class GestureSequence {
26 public: 19 public:
27 // Gesture state.
28 enum GestureState {
29 GS_NO_GESTURE,
30 GS_PENDING_SYNTHETIC_CLICK,
31 GS_SCROLL,
32 };
33
34 // ui::EventType is mapped to TouchState so it can fit into 3 bits of 20 // ui::EventType is mapped to TouchState so it can fit into 3 bits of
35 // Signature. 21 // Signature.
36 enum TouchState { 22 enum TouchState {
37 TS_RELEASED, 23 TS_RELEASED,
38 TS_PRESSED, 24 TS_PRESSED,
39 TS_MOVED, 25 TS_MOVED,
40 TS_STATIONARY, 26 TS_STATIONARY,
41 TS_CANCELLED, 27 TS_CANCELLED,
42 TS_UNKNOWN, 28 TS_UNKNOWN,
43 }; 29 };
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // 3 bits for the |type|. 78 // 3 bits for the |type|.
93 // 1 bit for |touch_handled| 79 // 1 bit for |touch_handled|
94 // 12 bits for |touch_id| 80 // 12 bits for |touch_id|
95 // 15 bits for the |gesture_state|. 81 // 15 bits for the |gesture_state|.
96 static unsigned int Signature(GestureState state, 82 static unsigned int Signature(GestureState state,
97 unsigned int touch_id, ui::EventType type, 83 unsigned int touch_id, ui::EventType type,
98 bool touch_handled); 84 bool touch_handled);
99 85
100 void Reset(); 86 void Reset();
101 87
102 // Various statistical functions to manipulate gestures. 88 GesturePoint& GesturePointForEvent(const TouchEvent& event);
103 bool IsInClickTimeWindow();
104 bool IsInSecondClickTimeWindow();
105 bool IsInsideManhattanSquare(const TouchEvent& event);
106 bool IsSecondClickInsideManhattanSquare(const TouchEvent& event);
107 bool IsOverMinFlickSpeed();
108 89
109 // Functions to be called to add GestureEvents, after succesful recognition. 90 // Functions to be called to add GestureEvents, after succesful recognition.
110 void AppendTapDownGestureEvent(const TouchEvent& event, Gestures* gestures); 91
111 void AppendClickGestureEvent(const TouchEvent& event, Gestures* gestures); 92 // Tap gestures.
112 void AppendDoubleClickGestureEvent(const TouchEvent& event, 93 void AppendTapDownGestureEvent(const GesturePoint& point, Gestures* gestures);
94 void AppendClickGestureEvent(const GesturePoint& point, Gestures* gestures);
95 void AppendDoubleClickGestureEvent(const GesturePoint& point,
113 Gestures* gestures); 96 Gestures* gestures);
114 void AppendScrollGestureBegin(const TouchEvent& event, Gestures* gestures); 97 // Scroll gestures.
115 void AppendScrollGestureEnd(const TouchEvent& event, 98 void AppendScrollGestureBegin(const GesturePoint& point, Gestures* gestures);
99 void AppendScrollGestureEnd(const GesturePoint& point,
116 Gestures* gestures, 100 Gestures* gestures,
117 float x_velocity, float y_velocity); 101 float x_velocity, float y_velocity);
118 void AppendScrollGestureUpdate(const TouchEvent& event, Gestures* gestures); 102 void AppendScrollGestureUpdate(const GesturePoint& point, Gestures* gestures);
119 103
120 void UpdateValues(const TouchEvent& event); 104 void UpdateValues(const TouchEvent& event);
121 void SetState(const GestureState state ) { state_ = state; } 105 void SetState(const GestureState state ) { state_ = state; }
122 106
123 // Various GestureTransitionFunctions for a signature. 107 // Various GestureTransitionFunctions for a signature.
124 // There is, 1:many mapping from GestureTransitionFunction to Signature 108 // There is, 1:many mapping from GestureTransitionFunction to Signature
125 // But a Signature have only one GestureTransitionFunction. 109 // But a Signature have only one GestureTransitionFunction.
126 bool Click(const TouchEvent& event, Gestures* gestures); 110 bool Click(const TouchEvent& event,
127 bool InClickOrScroll(const TouchEvent& event, Gestures* gestures); 111 const GesturePoint& point,
128 bool InScroll(const TouchEvent& event, Gestures* gestures); 112 Gestures* gestures);
129 bool NoGesture(const TouchEvent& event, Gestures* gestures); 113 bool InClickOrScroll(const TouchEvent& event,
130 bool TouchDown(const TouchEvent& event, Gestures* gestures); 114 const GesturePoint& point,
131 bool ScrollEnd(const TouchEvent& event, Gestures* gestures); 115 Gestures* gestures);
132 116 bool InScroll(const TouchEvent& event,
133 // Location of first touch event in a touch sequence. 117 const GesturePoint& point,
134 gfx::Point first_touch_position_; 118 Gestures* gestures);
135 119 bool NoGesture(const TouchEvent& event,
136 // Time of first touch event in a touch sequence. 120 const GesturePoint& point,
137 double first_touch_time_; 121 Gestures* gestures);
122 bool TouchDown(const TouchEvent& event,
123 const GesturePoint& point,
124 Gestures* gestures);
125 bool ScrollEnd(const TouchEvent& event,
126 const GesturePoint& point,
127 Gestures* gestures);
138 128
139 // Current state of gesture recognizer. 129 // Current state of gesture recognizer.
140 GestureState state_; 130 GestureState state_;
141 131
142 // Time of current touch event in a touch sequence.
143 double last_touch_time_;
144
145 // Time of click gesture.
146 double last_click_time_;
147
148 // Location of click gesture. 132 // Location of click gesture.
149 gfx::Point last_click_position_; 133 gfx::Point last_click_position_;
150 134
151 // Location of current touch event in a touch sequence.
152 gfx::Point last_touch_position_;
153
154 // Velocity in x and y direction.
155 float x_velocity_;
156 float y_velocity_;
157
158 // ui::EventFlags. 135 // ui::EventFlags.
159 int flags_; 136 int flags_;
160 137
138 GesturePoint point_;
139
161 DISALLOW_COPY_AND_ASSIGN(GestureSequence); 140 DISALLOW_COPY_AND_ASSIGN(GestureSequence);
162 }; 141 };
163 142
164 class AURA_EXPORT GestureRecognizerAura : public GestureRecognizer {
165 public:
166 GestureRecognizerAura();
167 virtual ~GestureRecognizerAura();
168
169 private:
170 // Overridden from GestureRecognizer
171 virtual Gestures* ProcessTouchEventForGesture(
172 const TouchEvent& event,
173 ui::TouchStatus status) OVERRIDE;
174 virtual void QueueTouchEventForGesture(Window* window,
175 const TouchEvent& event) OVERRIDE;
176 virtual Gestures* AdvanceTouchQueue(Window* window, bool processed) OVERRIDE;
177 virtual void FlushTouchQueue(Window* window) OVERRIDE;
178
179 scoped_ptr<GestureSequence> default_sequence_;
180
181 typedef std::queue<TouchEvent*> TouchEventQueue;
182 std::map<Window*, TouchEventQueue*> event_queue_;
183 std::map<Window*, GestureSequence*> window_sequence_;
184
185 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerAura);
186 };
187
188 } // namespace aura 143 } // namespace aura
189 144
190 #endif // UI_AURA_GESTURES_GESTURE_RECOGNIZER_AURA_H_ 145 #endif // UI_AURA_GESTURES_GESTURE_SEQUENCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698