velocity_tracker_state.h 1.6 KB

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