summaryrefslogtreecommitdiffstats
path: root/ui/events/gestures/fling_curve.h
blob: 18a69d3070eb957fedae9bb142c577f7f0724edf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 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 UI_EVENTS_GESTURES_FLING_CURVE_H_
#define UI_EVENTS_GESTURES_FLING_CURVE_H_

#include "base/macros.h"
#include "base/time/time.h"
#include "ui/events/events_base_export.h"
#include "ui/events/gesture_curve.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_f.h"

namespace ui {

// FlingCurve can be used to scroll a UI element suitable for touch screen-based
// flings.
class EVENTS_BASE_EXPORT FlingCurve : public GestureCurve {
 public:
  FlingCurve(const gfx::Vector2dF& velocity, base::TimeTicks start_timestamp);
  ~FlingCurve() override;

  // GestureCurve implementation.
  bool ComputeScrollOffset(base::TimeTicks time,
                           gfx::Vector2dF* offset,
                           gfx::Vector2dF* velocity) override;

  // In contrast to |ComputeScrollOffset()|, this method is stateful and
  // returns the *change* in scroll offset between successive calls.
  // Returns true as long as the curve is still active and requires additional
  // animation ticks.
  bool ComputeScrollDeltaAtTime(base::TimeTicks current, gfx::Vector2dF* delta);

 private:
  const float curve_duration_;
  const base::TimeTicks start_timestamp_;

  gfx::Vector2dF displacement_ratio_;
  gfx::Vector2dF cumulative_scroll_;
  base::TimeTicks previous_timestamp_;
  float time_offset_;
  float position_offset_;

  DISALLOW_COPY_AND_ASSIGN(FlingCurve);
};

}  // namespace ui

#endif  // UI_EVENTS_GESTURES_FLING_CURVE_H_