Chromium Code Reviews| Index: views/touchui/gesture_recognizer.h |
| diff --git a/views/touchui/gesture_recognizer.h b/views/touchui/gesture_recognizer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..569dce313211bb6e875879ccb903e0e7391311c3 |
| --- /dev/null |
| +++ b/views/touchui/gesture_recognizer.h |
| @@ -0,0 +1,140 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_ |
| +#define VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_ |
| +#pragma once |
| + |
| +#include <map> |
| +#include <vector> |
| + |
| +#include "base/memory/linked_ptr.h" |
| +#include "base/memory/singleton.h" |
| +#include "ui/base/events.h" |
| +#include "ui/gfx/point.h" |
| +#include "views/views_export.h" |
| + |
| +namespace views { |
| +class GestureManager; |
| +class TouchEvent; |
| +class GestureEvent; |
| + |
| +// A GestureRecognizer recognizes gestures from touch sequences. |
| +class VIEWS_EXPORT GestureRecognizer { |
| + public: |
| + // Gesture state. |
| + enum GestureState { |
| + GS_NO_GESTURE, |
| + GS_PENDING_SYNTHETIC_CLICK, |
| + GS_SCROLL, |
| + }; |
| + |
| + // Touch state. |
| + enum TouchState { |
|
sadrul
2011/11/18 19:01:50
Let's move the comment from line 68 to here to exp
Gajen
2011/11/21 15:56:50
Done.
|
| + TS_RELEASED, |
| + TS_PRESSED, |
| + TS_MOVED, |
| + TS_STATIONARY, |
| + TS_CANCELLED, |
| + TS_UNKNOWN, |
| + }; |
| + |
| + // List of GestureEvent*. |
| + typedef std::vector<linked_ptr<GestureEvent> > Gestures; |
| + |
| + GestureRecognizer(); |
| + virtual ~GestureRecognizer(); |
| + |
| + static GestureRecognizer* GetInstance(); |
| + |
| + // Invoked for each touch event that could contribute to the current gesture. |
| + // Returns list of zero or more GestureEvents identified after processing |
| + // TouchEvent. |
| + // Caller would be responsible for freeing up Gestures. |
| + virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event, |
| + ui::TouchStatus status); |
| + |
| + // Clears the GestureRecognizer to its initial state. |
| + virtual void Reset(); |
| + |
| + // Accessor function. |
| + GestureState GetState() { return state_; } |
|
sadrul
2011/11/18 19:01:50
Simple accessors are usually like this:
GestureSt
Gajen
2011/11/21 15:56:50
Done.
|
| + |
| + private: |
| + friend struct DefaultSingletonTraits<GestureRecognizer>; |
| + |
| + // Get equivalent TouchState from EventType |type| |
| + // This is required in order to fit TouchState in 3 bits of Signature. |
| + static TouchState TouchEventTypeToTouchState(ui::EventType type); |
| + |
| + // Create a 32 bit signature to identify GestureTransitionFunction. |
| + static unsigned int Signature(GestureState state, |
| + unsigned int touch_id, ui::EventType type, |
| + bool touch_handled); |
| + |
| + // Various statistical functions to manipulate gestures. |
| + bool IsInClickTimeWindow(); |
| + bool IsInSecondClickTimeWindow(); |
| + bool IsInsideManhattanSquare(const TouchEvent& event); |
| + bool IsSecondClickInsideManhattanSquare(const TouchEvent& event); |
| + bool IsOverMinFlickSpeed(); |
| + |
| + // Functions to be called to add GestureEvents, after succesful recognition. |
| + void AppendTapDownGestureEvent(const TouchEvent& event, Gestures* gestures); |
| + void AppendClickGestureEvent(const TouchEvent& event, Gestures* gestures); |
| + void AppendDoubleClickGestureEvent(const TouchEvent& event, |
| + Gestures* gestures); |
| + void AppendScrollGestureBegin(const TouchEvent& event, Gestures* gestures); |
| + void AppendScrollGestureEnd(const TouchEvent& event, |
| + Gestures* gestures, |
| + float x_velocity, float y_velocity); |
| + void AppendScrollGestureUpdate(const TouchEvent& event, Gestures* gestures); |
| + |
| + void UpdateValues(const TouchEvent& event); |
| + void SetState(const GestureState state ) { state_ = state; } |
| + |
| + // Various GestureTransitionFunctions for a signature. |
| + // There is, 1:many mapping from GestureTransitionFunction to Signature |
| + // But a Signature have only one GestureTransitionFunction. |
| + bool Click(const TouchEvent& event, Gestures* gestures); |
| + bool InClickOrScroll(const TouchEvent& event, Gestures* gestures); |
| + bool InScroll(const TouchEvent& event, Gestures* gestures); |
| + bool NoGesture(const TouchEvent& event, Gestures* gestures); |
| + bool TouchDown(const TouchEvent& event, Gestures* gestures); |
| + bool ScrollEnd(const TouchEvent& event, Gestures* gestures); |
| + |
| + // Location of first touch event in a touch sequence. |
| + gfx::Point first_touch_position_; |
| + |
| + // Time of first touch event in a touch sequence. |
| + double first_touch_time_; |
| + |
| + // Current state of gesture recognizer. |
| + GestureState state_; |
| + |
| + // Time of current touch event in a touch sequence. |
| + double last_touch_time_; |
| + |
| + // Time of click gesture. |
| + double last_click_time_; |
| + |
| + // Location of click gesture. |
| + gfx::Point last_click_position_; |
| + |
| + // Location of current touch event in a touch sequence. |
| + gfx::Point last_touch_position_; |
| + |
| + // Velocity in x and y direction. |
| + float x_velocity_; |
| + float y_velocity_; |
| + |
| + // Event flags. |
| + int flags_; |
|
sadrul
2011/11/18 19:01:50
Are these ui::EventFlags?
Gajen
2011/11/21 15:56:50
Yes, and updated comments too.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(GestureRecognizer); |
| +}; |
| + |
| +} // namespace views |
| + |
| +#endif // VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_ |