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

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: Wired gesture events into RootView and commandline switch enable-gesture 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"
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.
30 struct PassGestureEvent {
31 explicit PassGestureEvent(GestureEvent* event);
32 ~PassGestureEvent();
33
34 // Get the wrapper GestureEvent.
35 GestureEvent* GetGestureEvent() { return event_; }
36
37 // GestureEvent* instance.
38 GestureEvent* event_;
39 };
40
41 // Gesture state.
42 enum GestureState {
43 GS_NO_GESTURE,
44 GS_PENDING_SYNTHETIC_CLICK,
45 GS_SCROLL,
46 };
47
48 // Touch state.
49 enum TouchState {
50 TS_RELEASED,
51 TS_PRESSED,
52 TS_MOVED,
53 TS_STATIONARY,
54 TS_CANCELLED,
55 TS_UNKNOWN,
56 };
57
58 // List of GestureEvent*
59 typedef std::vector<PassGestureEvent> Gestures;
60 typedef bool (GestureRecognizer::*GestureTransitionFunction)(
61 const TouchEvent&, Gestures*);
62
63 GestureRecognizer();
64 virtual ~GestureRecognizer();
65
66 static GestureRecognizer* GetInstance();
67
68 // Overriden from GestureManager.
69 virtual bool ProcessTouchEventForGesture(const TouchEvent& event,
70 View* source,
71 ui::TouchStatus status) OVERRIDE;
72
73 // Clears the GestureRecognizer to it's initial state.
rjkroege 2011/11/01 18:42:22 wrong its. though you probably copied it from me.
Gajen 2011/11/02 12:59:35 Didn't Get, do u mean its Return type "virtual" sh
rjkroege 2011/11/04 17:19:28 the word "it's" is incorrect grammatically. The wo
Gajen 2011/11/08 08:11:44 Done.
74 virtual void Reset();
75
76 // Accessor function.
77 GestureState GetState() { return state_; }
78
79 private:
80 // Invoked for each touch event that could contribute to the current gesture.
81 // Returns list of zero or more GestureEvents identified after processing
82 // TouchEvent.
83 // Caller would be responsible for freeing up Gestures.
84 Gestures* StartGestureRecognitionProcess(const TouchEvent& event,
85 bool touch_handled);
86
87 // Get equivalent TouchState from EventType |type|
88 // This is required in order to fit TouchState in 3 bits of Signature.
89 static TouchState TouchEventTypeToTouchState(ui::EventType type);
90
91 // Create a 32 bit signature to identify GestureTransitionFunction.
92 static unsigned int Signature(GestureState state,
93 unsigned int touch_id, ui::EventType type,
94 bool touch_handled);
95
96 // Creates a map of Singnatures and corresponding GestureTransitionFunction.
97 void AddEdgeFunction(GestureState state,
98 unsigned int touch_id,
99 ui::EventType type,
100 bool touch_handled,
101 GestureTransitionFunction function);
102
103 // Various statistical functions to manipulate gestures.
104 bool IsInClickTimeWindow();
105 bool IsInSecondClickTimeWindow();
106 bool IsInsideManhattanSquare(const TouchEvent& event);
107 bool IsSecondClickInsideManhattanSquare(const TouchEvent& event);
108 bool IsOverMinFlickSpeed();
109
110 // Functions to be called to add GestureEvents, after succesful recognition.
111 void AppendTapDownGestureEvent(const TouchEvent& event, Gestures* gestures);
112 void AppendClickGestureEvent(const TouchEvent& event, Gestures* gestures);
113 void AppendDoubleClickGestureEvent(const TouchEvent& event,
114 Gestures* gestures);
115 void AppendScrollGestureBegin(const TouchEvent& event, Gestures* gestures);
116 void AppendScrollGestureEnd(const TouchEvent& event,
117 Gestures* gestures,
118 float x_velocity, float y_velocity);
119 void AppendScrollGestureUpdate(const TouchEvent& event, Gestures* gestures);
120
121 void UpdateValues(const TouchEvent& event);
122 void SetState(const GestureState state ) { state_ = state; }
123
124 // Various GestureTransitionFunctions for a signature.
125 // There is, 1:many mapping from GestureTransitionFunction to Signature
126 // But a Signature have only one GestureTransitionFunction.
127 bool Click(const TouchEvent& event, Gestures* gestures);
128 bool IsClickOrScroll(const TouchEvent& event, Gestures* gestures);
129 bool InScroll(const TouchEvent& event, Gestures* gestures);
130 bool NoGesture(const TouchEvent& event, Gestures* gestures);
131 bool TouchDown(const TouchEvent& event, Gestures* gestures);
132 bool ScrollEnd(const TouchEvent& event, Gestures* gestures);
133
134 typedef std::map<int, GestureTransitionFunction> GestureTransitionFunctionMap;
135 GestureTransitionFunctionMap edge_functions_;
136
137 gfx::Point first_touch_position_;
138
139 double first_touch_time_;
140 GestureState state_;
141
142 double last_touch_time_;
143 double last_click_time_;
144 gfx::Point last_click_position_;
145 gfx::Point last_touch_position_;
146 float x_velocity_;
147 float y_velocity_;
148 int flags_;
149
150 DISALLOW_COPY_AND_ASSIGN(GestureRecognizer);
151 };
152
153 } // namespace views
154
155 #endif // VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698