summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/widget/input/elastic_overscroll_controller_bezier.h
blob: d6dcf989295feef3f11416e9eef0d16d8370695a (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2020 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_INPUT_ELASTIC_OVERSCROLL_CONTROLLER_BEZIER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_INPUT_ELASTIC_OVERSCROLL_CONTROLLER_BEZIER_H_

#include "base/macros.h"
#include "cc/input/scroll_elasticity_helper.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/widget/input/elastic_overscroll_controller.h"
#include "ui/gfx/geometry/cubic_bezier.h"

#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "third_party/blink/public/platform/web_common.h"

namespace blink {
// Manages scroller stretch and rebounds when overscrolling. This controller
// uses a Bezier curve.
class PLATFORM_EXPORT ElasticOverscrollControllerBezier
    : public ElasticOverscrollController {
 public:
  explicit ElasticOverscrollControllerBezier(
      cc::ScrollElasticityHelper* helper);
  ~ElasticOverscrollControllerBezier() override = default;

  void DidEnterMomentumAnimatedState() override;
  gfx::Vector2d StretchAmountForTimeDelta(
      const base::TimeDelta& delta) const override;
  gfx::Vector2d StretchAmountForAccumulatedOverscroll(
      const gfx::Vector2dF& accumulated_overscroll) const override;
  gfx::Vector2d AccumulatedOverscrollForStretchAmount(
      const gfx::Vector2dF& delta) const override;
  gfx::Vector2dF OverscrollBoundary(const gfx::Size& scroller_bounds) const;
  double StretchAmountForForwardBounce(
      const gfx::CubicBezier bounce_forwards_curve,
      const base::TimeDelta& delta,
      const base::TimeDelta& bounce_forwards_duration,
      const double velocity,
      const double initial_stretch,
      const double bounce_forwards_distance) const;
  double StretchAmountForBackwardBounce(
      const gfx::CubicBezier bounce_backwards_curve,
      const base::TimeDelta& delta,
      const base::TimeDelta& bounce_backwards_duration,
      const double bounce_forwards_distance) const;

 private:
  FRIEND_TEST_ALL_PREFIXES(ElasticOverscrollControllerBezierTest,
                           VerifyInitialStretchDelta);
  FRIEND_TEST_ALL_PREFIXES(ElasticOverscrollControllerBezierTest,
                           VerifyForwardAnimationIsNotPlayed);

  // This is the velocity (in px/ms) of the fling at the moment the scroller
  // reaches its bounds. This is useful to tweak the Cubic Bezier curve for the
  // bounce animation that is about to get played.
  gfx::Vector2dF residual_velocity_;

  base::TimeDelta bounce_forwards_duration_x_;
  base::TimeDelta bounce_forwards_duration_y_;
  gfx::Vector2dF bounce_forwards_distance_;

  base::TimeDelta bounce_backwards_duration_x_;
  base::TimeDelta bounce_backwards_duration_y_;
  DISALLOW_COPY_AND_ASSIGN(ElasticOverscrollControllerBezier);
};

}  // namespace blink
#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_INPUT_ELASTIC_OVERSCROLL_CONTROLLER_BEZIER_H_