Chromium Code Reviews| Index: cc/animation/scroll_offset_animation_curve.cc |
| diff --git a/cc/animation/scroll_offset_animation_curve.cc b/cc/animation/scroll_offset_animation_curve.cc |
| index b207994c092a327a70c753d99b7c93f4446bf4c2..56c3d7ad6c0196aabb64d33cbf470263f0073a02 100644 |
| --- a/cc/animation/scroll_offset_animation_curve.cc |
| +++ b/cc/animation/scroll_offset_animation_curve.cc |
| @@ -41,7 +41,8 @@ static float MaximumDimension(const gfx::Vector2dF& delta) { |
| } |
| static base::TimeDelta SegmentDuration(const gfx::Vector2dF& delta, |
| - DurationBehavior behavior) { |
| + DurationBehavior behavior, |
| + base::TimeDelta delayed_by) { |
| double duration = kConstantDuration; |
| switch (behavior) { |
| case DurationBehavior::CONSTANT: |
| @@ -60,8 +61,14 @@ static base::TimeDelta SegmentDuration(const gfx::Vector2dF& delta, |
| default: |
| NOTREACHED(); |
| } |
| - return base::TimeDelta::FromMicroseconds(duration / kDurationDivisor * |
| - base::Time::kMicrosecondsPerSecond); |
| + |
| + base::TimeDelta td = base::TimeDelta::FromMicroseconds( |
|
tdresser
2016/08/25 15:55:54
td -> time_delta
https://google.github.io/stylegu
ymalik
2016/08/29 14:52:05
Great, thanks!
|
| + duration / kDurationDivisor * base::Time::kMicrosecondsPerSecond); |
| + |
| + td = td - delayed_by; |
| + if (td >= base::TimeDelta()) |
|
tdresser
2016/08/25 15:55:54
operator> is comparing unsigned integers, so this
tdresser
2016/08/29 14:31:33
Whoops, nevermind, this looks fine.
ymalik
2016/08/29 14:52:05
Acknowledged.
|
| + return td; |
| + return base::TimeDelta(); |
| } |
| static std::unique_ptr<TimingFunction> EaseOutWithInitialVelocity( |
| @@ -98,11 +105,12 @@ ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( |
| ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} |
| void ScrollOffsetAnimationCurve::SetInitialValue( |
| - const gfx::ScrollOffset& initial_value) { |
| + const gfx::ScrollOffset& initial_value, |
| + base::TimeDelta delayed_by) { |
| initial_value_ = initial_value; |
| has_set_initial_value_ = true; |
| total_animation_duration_ = SegmentDuration( |
| - target_value_.DeltaFrom(initial_value_), duration_behavior_); |
| + target_value_.DeltaFrom(initial_value_), duration_behavior_, delayed_by); |
| } |
| bool ScrollOffsetAnimationCurve::HasSetInitialValue() const { |
| @@ -120,6 +128,9 @@ gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue( |
| base::TimeDelta duration = total_animation_duration_ - last_retarget_; |
| t -= last_retarget_; |
| + if (has_set_initial_value_ && duration == base::TimeDelta()) |
|
tdresser
2016/08/25 15:55:54
duration_.is_zero()
ymalik
2016/08/29 14:52:05
Done.
|
| + return target_value_; |
| + |
| if (t <= base::TimeDelta()) |
| return initial_value_; |
| @@ -194,6 +205,13 @@ void ScrollOffsetAnimationCurve::UpdateTarget( |
| target_value_ = new_target; |
| return; |
| } |
| + |
| + if (t == 0) { |
|
tdresser
2016/08/25 15:55:54
Should this be combined with the clause above?
ymalik
2016/08/29 14:52:05
I think this is more clear in communicating that t
tdresser
2016/08/29 15:28:28
Acknowledged.
|
| + // Just update the target since the animation hasn't started yet. |
| + target_value_ = new_target; |
| + return; |
| + } |
| + |
| gfx::ScrollOffset current_position = |
| GetValue(base::TimeDelta::FromSecondsD(t)); |
| gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_); |
| @@ -208,7 +226,8 @@ void ScrollOffsetAnimationCurve::UpdateTarget( |
| // segment duration. This minimizes the "rubber-band" bouncing effect when |
| // old_normalized_velocity is large and new_delta is small. |
| double new_duration = |
| - std::min(SegmentDuration(new_delta, duration_behavior_).InSecondsF(), |
| + std::min(SegmentDuration(new_delta, duration_behavior_, base::TimeDelta()) |
| + .InSecondsF(), |
| VelocityBasedDurationBound(old_delta, old_normalized_velocity, |
| old_duration, new_delta)); |