1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_STATE_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_STATE_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/basictypes.h"
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/events/gesture_detection/bitset_32.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/events/gesture_detection/gesture_detection_export.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/events/gesture_detection/velocity_tracker.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace ui {
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class MotionEvent;
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Port of VelocityTrackerState from Android
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// * platform/frameworks/base/core/jni/android_view_VelocityTracker.cpp
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// * Change-Id: I3517881b87b47dcc209d80dbd0ac6b5cf29a766f
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// * Please update the Change-Id as upstream Android changes are pulled.
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class GESTURE_DETECTION_EXPORT VelocityTrackerState {
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VelocityTrackerState();
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  explicit VelocityTrackerState(VelocityTracker::Strategy strategy);
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ~VelocityTrackerState();
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void Clear();
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void AddMovement(const MotionEvent& event);
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void ComputeCurrentVelocity(int32_t units, float max_velocity);
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  float GetXVelocity(int32_t id) const;
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  float GetYVelocity(int32_t id) const;
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  struct Velocity {
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    float vx, vy;
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  };
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void GetVelocity(int32_t id, float* out_vx, float* out_vy) const;
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VelocityTracker velocity_tracker_;
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  int32_t active_pointer_id_;
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BitSet32 calculated_id_bits_;
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Velocity calculated_velocity_[VelocityTracker::MAX_POINTERS];
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(VelocityTrackerState);
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace ui
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // UI_EVENTS_GESTURE_DETECTION_VELOCITY_TRACKER_STATE_H_
51