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

Unified Diff: content/browser/renderer_host/input/gestures/velocity_tracker.h

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/gestures/velocity_tracker.h
diff --git a/content/browser/renderer_host/input/gestures/velocity_tracker.h b/content/browser/renderer_host/input/gestures/velocity_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..b870ce89d1cda43251e7a293b871e5945638870e
--- /dev/null
+++ b/content/browser/renderer_host/input/gestures/velocity_tracker.h
@@ -0,0 +1,117 @@
+// Copyright 2014 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 CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURES_VELOCITY_TRACKER_H_
+#define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURES_VELOCITY_TRACKER_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "content/browser/renderer_host/input/gestures/bitset_32.h"
+
+namespace content {
+
+class MotionEvent;
+class VelocityTrackerStrategy;
+
+namespace {
+struct Estimator;
+}
+
+// Port of VelocityTracker from Android
+// * platform/frameworks/native/include/input/VelocityTracker.h
+// * Change-Id: I4983db61b53e28479fc90d9211fafff68f7f49a6
+// * Changes to this class should be cosmetic only, easing fork maintenance.
+class VelocityTracker {
+public:
+ struct Position {
+ float x, y;
+ };
+
+ enum {
+ MAX_POINTERS = 16,
+ MAX_POINTER_ID = 31
+ };
+
+ // Creates a velocity tracker using the default strategy for the platform.
+ VelocityTracker();
+
+ // Creates a velocity tracker using the specified strategy.
+ // If strategy is NULL, uses the default strategy for the platform.
+ explicit VelocityTracker(const char* strategy);
+
+ ~VelocityTracker();
+
+ // Resets the velocity tracker state.
+ void Clear();
+
+ // Adds movement information for all pointers in a MotionEvent, including
+ // historical samples.
+ void AddMovement(const MotionEvent& event);
+
+ // Gets the velocity of the specified pointer id in position units per second.
+ // Returns false and sets the velocity components to zero if there is
+ // insufficient movement information for the pointer.
+ bool GetVelocity(uint32_t id, float* outVx, float* outVy) const;
+
+ // Gets the active pointer id, or -1 if none.
+ inline int32_t GetActivePointerId() const { return active_pointer_id_; }
+
+ // Gets a bitset containing all pointer ids from the most recent movement.
+ inline BitSet32 GetCurrentPointerIdBits() const {
+ return current_pointer_id_bits_;
+ }
+
+ private:
+ // Resets the velocity tracker state for specific pointers.
+ // Call this method when some pointers have changed and may be reusing
+ // an id that was assigned to a different pointer earlier.
+ void ClearPointers(BitSet32 id_bits);
+
+ // Adds movement information for a set of pointers.
+ // The id_bits bitfield specifies the pointer ids of the pointers whose
+ // positions
+ // are included in the movement.
+ // The positions array contains position information for each pointer in order
+ // by
+ // increasing id. Its size should be equal to the number of one bits in
+ // id_bits.
+ void AddMovement(const base::TimeTicks& event_time,
+ BitSet32 id_bits,
+ const Position* positions);
+
+ // Gets an estimator for the recent movements of the specified pointer id.
+ // Returns false and clears the estimator if there is no information available
+ // about the pointer.
+ bool GetEstimator(uint32_t id, Estimator* out_estimator) const;
+
+ bool ConfigureStrategy(const char* strategy);
+
+ static VelocityTrackerStrategy* CreateStrategy(const char* strategy);
+
+ base::TimeTicks last_event_time_;
+ BitSet32 current_pointer_id_bits_;
+ int32_t active_pointer_id_;
+ scoped_ptr<VelocityTrackerStrategy> strategy_;
+};
+
+// Implements a particular velocity tracker algorithm.
+class VelocityTrackerStrategy {
+ public:
+ virtual ~VelocityTrackerStrategy() {}
+
+ virtual void Clear() = 0;
+ virtual void ClearPointers(BitSet32 id_bits) = 0;
+ virtual void AddMovement(const base::TimeTicks& event_time,
+ BitSet32 id_bits,
+ const VelocityTracker::Position* positions) = 0;
+ virtual bool GetEstimator(uint32_t id, Estimator* out_estimator) const = 0;
+
+ protected:
+ VelocityTrackerStrategy() {}
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURES_VELOCITY_TRACKER_H_

Powered by Google App Engine
This is Rietveld 408576698