| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/animation/scroll_offset_animation_curve.h" | 5 #include "cc/animation/scroll_offset_animation_curve.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 void ScrollOffsetAnimationCurve::UpdateTarget( | 201 void ScrollOffsetAnimationCurve::UpdateTarget( |
| 202 double t, | 202 double t, |
| 203 const gfx::ScrollOffset& new_target) { | 203 const gfx::ScrollOffset& new_target) { |
| 204 if (std::abs(MaximumDimension(target_value_.DeltaFrom(new_target))) < | 204 if (std::abs(MaximumDimension(target_value_.DeltaFrom(new_target))) < |
| 205 kEpsilon) { | 205 kEpsilon) { |
| 206 target_value_ = new_target; | 206 target_value_ = new_target; |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 // The total_animation_duration_ is zero because of the delay that we | |
| 211 // accounted for when the animation was created. The new duration should | |
| 212 // also take the delay into account. | |
| 213 if (total_animation_duration_.is_zero()) { | |
| 214 DCHECK_LE(t, 0); | |
| 215 total_animation_duration_ = | |
| 216 SegmentDuration(new_target.DeltaFrom(initial_value_), | |
| 217 duration_behavior_, base::TimeDelta::FromSecondsD(-t)); | |
| 218 target_value_ = new_target; | |
| 219 return; | |
| 220 } | |
| 221 | |
| 222 base::TimeDelta delayed_by = base::TimeDelta::FromSecondsD( | 210 base::TimeDelta delayed_by = base::TimeDelta::FromSecondsD( |
| 223 std::max(0.0, last_retarget_.InSecondsF() - t)); | 211 std::max(0.0, last_retarget_.InSecondsF() - t)); |
| 224 t = std::max(t, last_retarget_.InSecondsF()); | 212 t = std::max(t, last_retarget_.InSecondsF()); |
| 225 | 213 |
| 226 gfx::ScrollOffset current_position = | 214 gfx::ScrollOffset current_position = |
| 227 GetValue(base::TimeDelta::FromSecondsD(t)); | 215 GetValue(base::TimeDelta::FromSecondsD(t)); |
| 228 gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_); | 216 gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_); |
| 229 gfx::Vector2dF new_delta = new_target.DeltaFrom(current_position); | 217 gfx::Vector2dF new_delta = new_target.DeltaFrom(current_position); |
| 230 | 218 |
| 219 // The last segement was of zero duration. |
| 220 if ((total_animation_duration_ - last_retarget_).is_zero()) { |
| 221 DCHECK_EQ(t, last_retarget_.InSecondsF()); |
| 222 total_animation_duration_ = |
| 223 SegmentDuration(new_delta, duration_behavior_, delayed_by); |
| 224 target_value_ = new_target; |
| 225 return; |
| 226 } |
| 227 |
| 231 double old_duration = | 228 double old_duration = |
| 232 (total_animation_duration_ - last_retarget_).InSecondsF(); | 229 (total_animation_duration_ - last_retarget_).InSecondsF(); |
| 233 double old_normalized_velocity = timing_function_->Velocity( | 230 double old_normalized_velocity = timing_function_->Velocity( |
| 234 (t - last_retarget_.InSecondsF()) / old_duration); | 231 (t - last_retarget_.InSecondsF()) / old_duration); |
| 235 | 232 |
| 236 // Use the velocity-based duration bound when it is less than the constant | 233 // Use the velocity-based duration bound when it is less than the constant |
| 237 // segment duration. This minimizes the "rubber-band" bouncing effect when | 234 // segment duration. This minimizes the "rubber-band" bouncing effect when |
| 238 // old_normalized_velocity is large and new_delta is small. | 235 // old_normalized_velocity is large and new_delta is small. |
| 239 double new_duration = std::min( | 236 double new_duration = std::min( |
| 240 SegmentDuration(new_delta, duration_behavior_, delayed_by).InSecondsF(), | 237 SegmentDuration(new_delta, duration_behavior_, delayed_by).InSecondsF(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 256 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); | 253 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); |
| 257 | 254 |
| 258 initial_value_ = current_position; | 255 initial_value_ = current_position; |
| 259 target_value_ = new_target; | 256 target_value_ = new_target; |
| 260 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); | 257 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); |
| 261 last_retarget_ = base::TimeDelta::FromSecondsD(t); | 258 last_retarget_ = base::TimeDelta::FromSecondsD(t); |
| 262 timing_function_ = EaseOutWithInitialVelocity(new_normalized_velocity); | 259 timing_function_ = EaseOutWithInitialVelocity(new_normalized_velocity); |
| 263 } | 260 } |
| 264 | 261 |
| 265 } // namespace cc | 262 } // namespace cc |
| OLD | NEW |