blob: 175b4af476b3a233fb69f4e03794c11723618e6e [file] [log] [blame]
[email protected]87ecde92013-11-25 19:30:241// Copyright 2013 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_ANIMATION_SCROLL_OFFSET_ANIMATION_CURVE_H_
6#define CC_ANIMATION_SCROLL_OFFSET_ANIMATION_CURVE_H_
7
danakj60bc3bc2016-04-09 00:24:488#include <memory>
9
avi02a4d172015-12-21 06:14:3610#include "base/macros.h"
[email protected]ac22516a2014-05-15 17:31:3611#include "base/time/time.h"
[email protected]87ecde92013-11-25 19:30:2412#include "cc/animation/animation_curve.h"
13#include "cc/base/cc_export.h"
miletusf57925d2014-10-01 19:38:1314#include "ui/gfx/geometry/scroll_offset.h"
[email protected]87ecde92013-11-25 19:30:2415
16namespace cc {
17
18class TimingFunction;
19
20class CC_EXPORT ScrollOffsetAnimationCurve : public AnimationCurve {
21 public:
skobese07af432016-01-14 21:06:3022 enum class DurationBehavior { DELTA_BASED, CONSTANT, INVERSE_DELTA };
danakj60bc3bc2016-04-09 00:24:4823 static std::unique_ptr<ScrollOffsetAnimationCurve> Create(
miletusf57925d2014-10-01 19:38:1324 const gfx::ScrollOffset& target_value,
danakj60bc3bc2016-04-09 00:24:4825 std::unique_ptr<TimingFunction> timing_function,
skobes46aad142015-10-27 15:05:5026 DurationBehavior = DurationBehavior::DELTA_BASED);
[email protected]87ecde92013-11-25 19:30:2427
ymalikddfc3522016-09-05 18:40:3728 static base::TimeDelta SegmentDuration(const gfx::Vector2dF& delta,
29 DurationBehavior behavior,
30 base::TimeDelta delayed_by);
31
dcheng716bedf2014-10-21 09:51:0832 ~ScrollOffsetAnimationCurve() override;
[email protected]87ecde92013-11-25 19:30:2433
ymalikddfc3522016-09-05 18:40:3734 void SetInitialValue(const gfx::ScrollOffset& initial_value,
35 base::TimeDelta delayed_by = base::TimeDelta());
ymalik8c4e04362015-12-07 07:57:3636 bool HasSetInitialValue() const;
behara.ms591d77f92014-11-18 16:01:4037 gfx::ScrollOffset GetValue(base::TimeDelta t) const;
miletusf57925d2014-10-01 19:38:1338 gfx::ScrollOffset target_value() const { return target_value_; }
39 void UpdateTarget(double t, const gfx::ScrollOffset& new_target);
ymalikf3a9e63572016-05-20 01:31:0740 void ApplyAdjustment(const gfx::Vector2dF& adjustment);
[email protected]87ecde92013-11-25 19:30:2441
42 // AnimationCurve implementation
behara.ms71ff07f32014-11-12 05:09:0843 base::TimeDelta Duration() const override;
dcheng716bedf2014-10-21 09:51:0844 CurveType Type() const override;
danakj60bc3bc2016-04-09 00:24:4845 std::unique_ptr<AnimationCurve> Clone() const override;
46 std::unique_ptr<ScrollOffsetAnimationCurve>
47 CloneToScrollOffsetAnimationCurve() const;
[email protected]87ecde92013-11-25 19:30:2448
49 private:
miletusf57925d2014-10-01 19:38:1350 ScrollOffsetAnimationCurve(const gfx::ScrollOffset& target_value,
danakj60bc3bc2016-04-09 00:24:4851 std::unique_ptr<TimingFunction> timing_function,
skobes46aad142015-10-27 15:05:5052 DurationBehavior);
[email protected]87ecde92013-11-25 19:30:2453
miletusf57925d2014-10-01 19:38:1354 gfx::ScrollOffset initial_value_;
55 gfx::ScrollOffset target_value_;
[email protected]7a7d5be2014-07-18 22:37:2656 base::TimeDelta total_animation_duration_;
57
58 // Time from animation start to most recent UpdateTarget.
59 base::TimeDelta last_retarget_;
[email protected]87ecde92013-11-25 19:30:2460
danakj60bc3bc2016-04-09 00:24:4861 std::unique_ptr<TimingFunction> timing_function_;
skobes46aad142015-10-27 15:05:5062 DurationBehavior duration_behavior_;
[email protected]87ecde92013-11-25 19:30:2463
ymalik8c4e04362015-12-07 07:57:3664 bool has_set_initial_value_;
65
[email protected]87ecde92013-11-25 19:30:2466 DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimationCurve);
67};
68
69} // namespace cc
70
71#endif // CC_ANIMATION_SCROLL_OFFSET_ANIMATION_CURVE_H_