[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 1 | // 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 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | ac22516a | 2014-05-15 17:31:36 | [diff] [blame] | 11 | #include "base/time/time.h" |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 12 | #include "cc/animation/animation_curve.h" |
| 13 | #include "cc/base/cc_export.h" |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 14 | #include "ui/gfx/geometry/scroll_offset.h" |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 15 | |
| 16 | namespace cc { |
| 17 | |
| 18 | class TimingFunction; |
| 19 | |
| 20 | class CC_EXPORT ScrollOffsetAnimationCurve : public AnimationCurve { |
| 21 | public: |
skobes | e07af43 | 2016-01-14 21:06:30 | [diff] [blame] | 22 | enum class DurationBehavior { DELTA_BASED, CONSTANT, INVERSE_DELTA }; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 23 | static std::unique_ptr<ScrollOffsetAnimationCurve> Create( |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 24 | const gfx::ScrollOffset& target_value, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 25 | std::unique_ptr<TimingFunction> timing_function, |
skobes | 46aad14 | 2015-10-27 15:05:50 | [diff] [blame] | 26 | DurationBehavior = DurationBehavior::DELTA_BASED); |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 27 | |
ymalik | ddfc352 | 2016-09-05 18:40:37 | [diff] [blame] | 28 | static base::TimeDelta SegmentDuration(const gfx::Vector2dF& delta, |
| 29 | DurationBehavior behavior, |
| 30 | base::TimeDelta delayed_by); |
| 31 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 32 | ~ScrollOffsetAnimationCurve() override; |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 33 | |
ymalik | ddfc352 | 2016-09-05 18:40:37 | [diff] [blame] | 34 | void SetInitialValue(const gfx::ScrollOffset& initial_value, |
| 35 | base::TimeDelta delayed_by = base::TimeDelta()); |
ymalik | 8c4e0436 | 2015-12-07 07:57:36 | [diff] [blame] | 36 | bool HasSetInitialValue() const; |
behara.ms | 591d77f9 | 2014-11-18 16:01:40 | [diff] [blame] | 37 | gfx::ScrollOffset GetValue(base::TimeDelta t) const; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 38 | gfx::ScrollOffset target_value() const { return target_value_; } |
| 39 | void UpdateTarget(double t, const gfx::ScrollOffset& new_target); |
ymalik | f3a9e6357 | 2016-05-20 01:31:07 | [diff] [blame] | 40 | void ApplyAdjustment(const gfx::Vector2dF& adjustment); |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 41 | |
| 42 | // AnimationCurve implementation |
behara.ms | 71ff07f3 | 2014-11-12 05:09:08 | [diff] [blame] | 43 | base::TimeDelta Duration() const override; |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 44 | CurveType Type() const override; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 45 | std::unique_ptr<AnimationCurve> Clone() const override; |
| 46 | std::unique_ptr<ScrollOffsetAnimationCurve> |
| 47 | CloneToScrollOffsetAnimationCurve() const; |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 48 | |
| 49 | private: |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 50 | ScrollOffsetAnimationCurve(const gfx::ScrollOffset& target_value, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 51 | std::unique_ptr<TimingFunction> timing_function, |
skobes | 46aad14 | 2015-10-27 15:05:50 | [diff] [blame] | 52 | DurationBehavior); |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 53 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 54 | gfx::ScrollOffset initial_value_; |
| 55 | gfx::ScrollOffset target_value_; |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 56 | base::TimeDelta total_animation_duration_; |
| 57 | |
| 58 | // Time from animation start to most recent UpdateTarget. |
| 59 | base::TimeDelta last_retarget_; |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 60 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 61 | std::unique_ptr<TimingFunction> timing_function_; |
skobes | 46aad14 | 2015-10-27 15:05:50 | [diff] [blame] | 62 | DurationBehavior duration_behavior_; |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 63 | |
ymalik | 8c4e0436 | 2015-12-07 07:57:36 | [diff] [blame] | 64 | bool has_set_initial_value_; |
| 65 | |
[email protected] | 87ecde9 | 2013-11-25 19:30:24 | [diff] [blame] | 66 | DISALLOW_COPY_AND_ASSIGN(ScrollOffsetAnimationCurve); |
| 67 | }; |
| 68 | |
| 69 | } // namespace cc |
| 70 | |
| 71 | #endif // CC_ANIMATION_SCROLL_OFFSET_ANIMATION_CURVE_H_ |