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

Unified 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 side-by-side diff with in-line comments
Download patch
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..c2e08312b5f1c781ea931440d656c66d69576204
--- /dev/null
+++ b/views/touchui/gesture_recognizer.h
@@ -0,0 +1,159 @@
+// 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 "ui/gfx/point.h"
+#include "views/touchui/gesture_manager.h"
+#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
+
+namespace ui {
+enum EventType;
+}
+
+namespace views {
+class GestureManager;
+class TouchEvent;
+class GestureEvent;
+
+// A GestureRecognizer recognizes gestures frome touch sequences.
+//
+class VIEWS_EXPORT GestureRecognizer : public GestureManager {
+ public:
+ // 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.
+ struct PassGestureEvent {
+ explicit PassGestureEvent(GestureEvent* event);
+ ~PassGestureEvent();
+
+ // Avoid double free in vector.
+ PassGestureEvent(const PassGestureEvent& event);
+ void operator=(const PassGestureEvent& event);
+
+ // Get the wrapper GestureEvent.
+ GestureEvent* GetGestureEvent() const { return event_; }
+
+ // GestureEvent* instance.
+ GestureEvent* event_;
+ };
+
+ // Gesture state.
+ enum GestureState {
+ GS_NO_GESTURE,
+ GS_PENDING_SYNTHETIC_CLICK,
+ GS_SCROLL,
+ };
+
+ // Touch state.
+ enum TouchState {
+ TS_RELEASED,
+ TS_PRESSED,
+ TS_MOVED,
+ TS_STATIONARY,
+ TS_CANCELLED,
+ TS_UNKNOWN,
+ };
+
+ // List of GestureEvent*
+ typedef std::vector<PassGestureEvent> Gestures;
+ typedef bool (GestureRecognizer::*GestureTransitionFunction)(
+ const TouchEvent&, Gestures*);
+
+ GestureRecognizer();
+ virtual ~GestureRecognizer();
+
+ static GestureRecognizer* GetInstance();
+
+ // Overriden from GestureManager.
+ virtual bool ProcessTouchEventForGesture(const TouchEvent& event,
+ View* source,
+ ui::TouchStatus status) OVERRIDE;
+
+ // Clears the GestureRecognizer to its initial state.
+ virtual void Reset();
+
+ // Accessor function.
+ GestureState GetState() { return state_; }
+
+ private:
+ // 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.
+ 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.
+ bool touch_handled);
+
+ // 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);
+
+ // Creates a map of Singnatures and corresponding GestureTransitionFunction.
+ void AddEdgeFunction(GestureState state,
+ unsigned int touch_id,
+ ui::EventType type,
+ bool touch_handled,
+ GestureTransitionFunction function);
+
+ // 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 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.
+ 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);
+
+ typedef std::map<int, GestureTransitionFunction> GestureTransitionFunctionMap;
+ GestureTransitionFunctionMap edge_functions_;
+
+ gfx::Point first_touch_position_;
+
+ double first_touch_time_;
+ GestureState state_;
+
+ double last_touch_time_;
+ double last_click_time_;
+ gfx::Point last_click_position_;
+ gfx::Point last_touch_position_;
+ float x_velocity_;
+ float y_velocity_;
+ int flags_;
+
+ DISALLOW_COPY_AND_ASSIGN(GestureRecognizer);
+};
+
+} // namespace views
+
+#endif // VIEWS_TOUCHUI_GESTURE_RECOGNIZER_H_

Powered by Google App Engine
This is Rietveld 408576698