Home | History | Annotate | Download | only in gesture_detection
      1 // Copyright 2014 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 UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_STATE_H_
      6 #define UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_STATE_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "ui/events/gesture_detection/bitset_32.h"
     10 #include "ui/events/gesture_detection/gesture_detection_export.h"
     11 #include "ui/events/gesture_detection/velocity_tracker.h"
     12 
     13 namespace ui {
     14 
     15 class MotionEvent;
     16 
     17 // Port of VelocityTrackerState from Android
     18 // * platform/frameworks/base/core/jni/android_view_VelocityTracker.cpp
     19 // * Change-Id: I3517881b87b47dcc209d80dbd0ac6b5cf29a766f
     20 // * Please update the Change-Id as upstream Android changes are pulled.
     21 class GESTURE_DETECTION_EXPORT VelocityTrackerState {
     22  public:
     23   VelocityTrackerState();
     24   explicit VelocityTrackerState(VelocityTracker::Strategy strategy);
     25   ~VelocityTrackerState();
     26 
     27   void Clear();
     28   void AddMovement(const MotionEvent& event);
     29   void ComputeCurrentVelocity(int32_t units, float max_velocity);
     30   float GetXVelocity(int32_t id) const;
     31   float GetYVelocity(int32_t id) const;
     32 
     33  private:
     34   struct Velocity {
     35     float vx, vy;
     36   };
     37 
     38   void GetVelocity(int32_t id, float* out_vx, float* out_vy) const;
     39 
     40   VelocityTracker velocity_tracker_;
     41   int32_t active_pointer_id_;
     42   BitSet32 calculated_id_bits_;
     43   Velocity calculated_velocity_[VelocityTracker::MAX_POINTERS];
     44 
     45   DISALLOW_COPY_AND_ASSIGN(VelocityTrackerState);
     46 };
     47 
     48 }  // namespace ui
     49 
     50 #endif  // UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_STATE_H_
     51