Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / cc / input / snap_fling_curve.h
1 // Copyright 2018 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 CC_INPUT_SNAP_FLING_CURVE_H_
6 #define CC_INPUT_SNAP_FLING_CURVE_H_
7
8 #include "base/time/time.h"
9 #include "cc/cc_export.h"
10 #include "ui/gfx/geometry/rect_f.h"
11 #include "ui/gfx/geometry/vector2d_f.h"
12
13 namespace cc {
14
15 // The curve for the snap fling animation. The curve would generate a geometric
16 // sequence of deltas to be scrolled at each frame.
17 class CC_EXPORT SnapFlingCurve {
18  public:
19   // Creates the curve based on the start offset, target offset, and the first
20   // inertial GSU's time_stamp.
21   SnapFlingCurve(const gfx::Vector2dF& start_offset,
22                  const gfx::Vector2dF& target_offset,
23                  base::TimeTicks first_gsu_time);
24
25   virtual ~SnapFlingCurve();
26
27   // Estimate the total distance that will be scrolled given the first GSU's
28   // delta
29   static gfx::Vector2dF EstimateDisplacement(const gfx::Vector2dF& first_delta);
30
31   // Returns the delta that should be scrolled at |time|.
32   virtual gfx::Vector2dF GetScrollDelta(base::TimeTicks time);
33
34   // Updates |current_displacement_|. This sync is necessary because the node
35   // might be scrolled by other calls and the scrolls might be clamped.
36   void UpdateCurrentOffset(const gfx::Vector2dF& current_offset);
37
38   // Returns true if the scroll has arrived at the snap destination.
39   virtual bool IsFinished() const;
40
41   base::TimeDelta duration() const { return duration_; }
42
43  private:
44   // Returns the curve's current distance at |current_time|.
45   double GetCurrentCurveDistance(base::TimeDelta current_time);
46
47   // The initial scroll offset of the scroller.
48   const gfx::Vector2dF start_offset_;
49
50   // The total displacement to the snap position.
51   const gfx::Vector2dF total_displacement_;
52   // 1D representation of |total_displacement_|.
53   const double total_distance_;
54
55   // The current displacement that has been scrolled.
56   gfx::Vector2dF current_displacement_;
57
58   // The timestamp of the first GSU.
59   const base::TimeTicks start_time_;
60
61   // The number of deltas in the curve's geometric sequence.
62   const double total_frames_;
63   // The first delta that defines the curve's geometric sequence.
64   const double first_delta_;
65   // The total milliseconds needed to finish the curve.
66   const base::TimeDelta duration_;
67
68   bool is_finished_ = false;
69
70   // |total_displacement_.x| / |total_distance_|
71   double ratio_x_;
72   // |total_displacement_.y| / |total_distance_|
73   double ratio_y_;
74 };
75
76 }  // namespace cc
77
78 #endif  // CC_INPUT_SNAP_FLING_CURVE_H_