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

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: Created 9 years, 2 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
(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/view.h"
14
15 namespace ui {
16 enum EventType;
17 }
18
19 namespace views {
20 class TouchEvent;
21 class GestureEvent;
22
23 // A GestureRecognizer recognizes gestures frome touch sequences.
24 //
25 class VIEWS_EXPORT GestureRecognizer {
26 public:
27 // Gesture state.
28 enum GestureState {
29 GS_NO_GESTURE,
30 GS_PENDING_SYNTHETIC_CLICK,
31 GS_SCROLL,
32 };
33
34 // Touch state.
35 enum TouchState {
36 TS_RELEASED,
37 TS_PRESSED,
38 TS_MOVED,
39 TS_STATIONARY,
40 TS_CANCELLED,
41 TS_UNKNOWN,
42 };
43
44 // List of GestureEvent*
45 typedef std::vector<GestureEvent* > Gestures;
46 typedef bool (GestureRecognizer::*GestureTransitionFunction)(
47 const TouchEvent&, Gestures*);
48
49 GestureRecognizer();
50 virtual ~GestureRecognizer();
51
52 // Invoked for each touch event that could contribute to the current gesture.
53 // Returns list of zero or more GestureEvents identified after processing
54 // TouchEvent.
55 // Caller would be responsible for freeing up Gestures.
56 virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event,
57 bool touch_handled);
58
59 // Clears the GestureRecognizer to it's initial state.
60 virtual void Reset();
61
62 // Accessor function.
63 GestureState GetState() { return state_; }
64
65 private:
66 // Get equivalent TouchState from EventType |type|
67 // This is required in order to fit TouchState in 3 bits of Signature.
68 static TouchState TouchEventTypeToTouchState(ui::EventType type);
69
70 // Create a 32 bit signature to identify GestureTransitionFunction.
71 static unsigned int Signature(GestureState state,
72 unsigned int touch_id, ui::EventType type,
73 bool touch_handled);
74
75 // Creates a map of Singnatures and corresponding GestureTransitionFunction.
76 void AddEdgeFunction(GestureState state,
77 unsigned int touch_id,
78 ui::EventType type,
79 bool touch_handled,
80 GestureTransitionFunction function);
81
82 // Various statistical functions to manipulate gestures.
83 bool IsInClickTimeWindow();
84 bool IsInSecondClickTimeWindow();
85 bool IsInsideManhattanSquare(const TouchEvent& event);
86 bool IsSecondClickInsideManhattanSquare(const TouchEvent& event);
87 bool IsOverMinFlickSpeed();
88
89 // Functions to be called to add GestureEvents, after succesful recognition.
90 void AppendTapDownGestureEvent(const TouchEvent& event, Gestures* gestures);
91 void AppendClickGestureEvent(const TouchEvent& event, Gestures* gestures);
92 void AppendDoubleClickGestureEvent(const TouchEvent& event,
93 Gestures* gestures);
94 void AppendScrollGestureBegin(const TouchEvent& event, Gestures* gestures);
95 void AppendScrollGestureEnd(const TouchEvent& event,
96 Gestures* gestures,
97 float x_velocity, float y_velocity);
98 void AppendScrollGestureUpdate(const TouchEvent& event, Gestures* gestures);
99
100 void UpdateValues(const TouchEvent& event);
101 void SetState(const GestureState state ) { state_ = state; }
102
103 // Various GestureTransitionFunctions for a signature.
104 // There is, 1:many mapping from GestureTransitionFunction to Signature
105 // But a Signature have only one GestureTransitionFunction.
106 bool Click(const TouchEvent& event, Gestures* gestures);
107 bool IsClickOrScroll(const TouchEvent& event, Gestures* gestures);
108 bool InScroll(const TouchEvent& event, Gestures* gestures);
109 bool NoGesture(const TouchEvent& event, Gestures* gestures);
110 bool TouchDown(const TouchEvent& event, Gestures* gestures);
111 bool ScrollEnd(const TouchEvent& event, Gestures* gestures);
112
113 typedef std::map<int, GestureTransitionFunction> GestureTransitionFunctionMap;
114 GestureTransitionFunctionMap edge_functions_;
115
116 gfx::Point first_touch_position_;
117
118 double first_touch_time_;
119 GestureState state_;
120
121 double last_touch_time_;
122 double last_click_time_;
123 gfx::Point last_click_position_;
124 gfx::Point last_touch_position_;
125 float x_velocity_;
126 float y_velocity_;
127 int flags_;
128
129 DISALLOW_COPY_AND_ASSIGN(GestureRecognizer);
130 };
131
132 } // namespace views
133
134 #endif // VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698