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

Side by Side Diff: views/touchui/gesture_recognizer.h

Issue 8364039: Initial views touchui GestureRecognizer support (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added gesture tests in view_unittest Created 9 years, 1 month 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
(Empty)
1 // Copyright (c) 2011 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.
4
5 #ifndef VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_
6 #define VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_
7 #pragma once
8
9 #include <map>
10 #include <vector>
11
12 #include "ui/gfx/point.h"
13 #include "views/touchui/gesture_manager.h"
14 #include "views/view.h"
rjkroege 2011/11/09 02:43:30 I would really prefer you to remove this dependenc
Gajen 2011/11/10 15:52:55 Done. New design implementation no longer required
15
16 namespace ui {
17 enum EventType;
18 }
19
20 namespace views {
21 class GestureManager;
22 class TouchEvent;
23 class GestureEvent;
24
25 // A GestureRecognizer recognizes gestures frome touch sequences.
26 //
27 class VIEWS_EXPORT GestureRecognizer : public GestureManager {
28 public:
29 // A GestureEvent wrapper for automatic memory management.
Ian Vollick 2011/11/08 20:07:54 You should use linked_ptr<GestureEvent> instead of
Gajen 2011/11/10 15:52:55 Done.
30 struct PassGestureEvent {
31 explicit PassGestureEvent(GestureEvent* event);
32 ~PassGestureEvent();
33
34 // Avoid double free in vector.
35 PassGestureEvent(const PassGestureEvent& event);
36 void operator=(const PassGestureEvent& event);
37
38 // Get the wrapper GestureEvent.
39 GestureEvent* GetGestureEvent() const { return event_; }
40
41 // GestureEvent* instance.
42 GestureEvent* event_;
43 };
44
45 // Gesture state.
46 enum GestureState {
47 GS_NO_GESTURE,
48 GS_PENDING_SYNTHETIC_CLICK,
49 GS_SCROLL,
50 };
51
52 // Touch state.
53 enum TouchState {
54 TS_RELEASED,
55 TS_PRESSED,
56 TS_MOVED,
57 TS_STATIONARY,
58 TS_CANCELLED,
59 TS_UNKNOWN,
60 };
61
62 // List of GestureEvent*
63 typedef std::vector<PassGestureEvent> Gestures;
64 typedef bool (GestureRecognizer::*GestureTransitionFunction)(
65 const TouchEvent&, Gestures*);
66
67 GestureRecognizer();
68 virtual ~GestureRecognizer();
69
70 static GestureRecognizer* GetInstance();
71
72 // Overriden from GestureManager.
73 virtual bool ProcessTouchEventForGesture(const TouchEvent& event,
74 View* source,
75 ui::TouchStatus status) OVERRIDE;
76
77 // Clears the GestureRecognizer to its initial state.
78 virtual void Reset();
79
80 // Accessor function.
81 GestureState GetState() { return state_; }
82
83 private:
84 // Invoked for each touch event that could contribute to the current gesture.
85 // Returns list of zero or more GestureEvents identified after processing
86 // TouchEvent.
87 // Caller would be responsible for freeing up Gestures.
88 Gestures* StartGestureRecognitionProcess(const TouchEvent& event,
rjkroege 2011/11/09 02:43:30 you've even done most of the work. :-)
Gajen 2011/11/10 15:52:55 Done.
89 bool touch_handled);
90
91 // Get equivalent TouchState from EventType |type|
92 // This is required in order to fit TouchState in 3 bits of Signature.
93 static TouchState TouchEventTypeToTouchState(ui::EventType type);
94
95 // Create a 32 bit signature to identify GestureTransitionFunction.
96 static unsigned int Signature(GestureState state,
97 unsigned int touch_id, ui::EventType type,
98 bool touch_handled);
99
100 // Creates a map of Singnatures and corresponding GestureTransitionFunction.
101 void AddEdgeFunction(GestureState state,
102 unsigned int touch_id,
103 ui::EventType type,
104 bool touch_handled,
105 GestureTransitionFunction function);
106
107 // Various statistical functions to manipulate gestures.
108 bool IsInClickTimeWindow();
109 bool IsInSecondClickTimeWindow();
110 bool IsInsideManhattanSquare(const TouchEvent& event);
111 bool IsSecondClickInsideManhattanSquare(const TouchEvent& event);
112 bool IsOverMinFlickSpeed();
113
114 // Functions to be called to add GestureEvents, after succesful recognition.
115 void AppendTapDownGestureEvent(const TouchEvent& event, Gestures* gestures);
116 void AppendClickGestureEvent(const TouchEvent& event, Gestures* gestures);
117 void AppendDoubleClickGestureEvent(const TouchEvent& event,
118 Gestures* gestures);
119 void AppendScrollGestureBegin(const TouchEvent& event, Gestures* gestures);
120 void AppendScrollGestureEnd(const TouchEvent& event,
121 Gestures* gestures,
122 float x_velocity, float y_velocity);
123 void AppendScrollGestureUpdate(const TouchEvent& event, Gestures* gestures);
124
125 void UpdateValues(const TouchEvent& event);
126 void SetState(const GestureState state ) { state_ = state; }
127
128 // Various GestureTransitionFunctions for a signature.
129 // There is, 1:many mapping from GestureTransitionFunction to Signature
130 // But a Signature have only one GestureTransitionFunction.
131 bool Click(const TouchEvent& event, Gestures* gestures);
132 bool IsClickOrScroll(const TouchEvent& event, Gestures* gestures);
Ian Vollick 2011/11/08 20:07:54 I think this should be InClickOrScroll to match In
Gajen 2011/11/10 15:52:55 Done.
133 bool InScroll(const TouchEvent& event, Gestures* gestures);
134 bool NoGesture(const TouchEvent& event, Gestures* gestures);
135 bool TouchDown(const TouchEvent& event, Gestures* gestures);
136 bool ScrollEnd(const TouchEvent& event, Gestures* gestures);
137
138 typedef std::map<int, GestureTransitionFunction> GestureTransitionFunctionMap;
139 GestureTransitionFunctionMap edge_functions_;
140
141 gfx::Point first_touch_position_;
142
143 double first_touch_time_;
144 GestureState state_;
145
146 double last_touch_time_;
147 double last_click_time_;
148 gfx::Point last_click_position_;
149 gfx::Point last_touch_position_;
150 float x_velocity_;
151 float y_velocity_;
152 int flags_;
153
154 DISALLOW_COPY_AND_ASSIGN(GestureRecognizer);
155 };
156
157 } // namespace views
158
159 #endif // VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698