Chromium Code Reviews| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 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 | 211 // accounted for when the animation was created. The new duration should |
| 212 // also take the delay into account. | 212 // also take the delay into account. |
| 213 if (total_animation_duration_.is_zero()) { | 213 if (total_animation_duration_.is_zero()) { |
|
skobes
2016/09/12 22:45:46
I think this block is redundant now?
ymalik
2016/09/12 23:35:05
Yes, you're right.
| |
| 214 DCHECK_LE(t, 0); | 214 DCHECK_LE(t, 0); |
| 215 total_animation_duration_ = | 215 total_animation_duration_ = |
| 216 SegmentDuration(new_target.DeltaFrom(initial_value_), | 216 SegmentDuration(new_target.DeltaFrom(initial_value_), |
| 217 duration_behavior_, base::TimeDelta::FromSecondsD(-t)); | 217 duration_behavior_, base::TimeDelta::FromSecondsD(-t)); |
| 218 target_value_ = new_target; | 218 target_value_ = new_target; |
| 219 return; | 219 return; |
| 220 } | 220 } |
| 221 | 221 |
| 222 base::TimeDelta delayed_by = base::TimeDelta::FromSecondsD( | 222 base::TimeDelta delayed_by = base::TimeDelta::FromSecondsD( |
| 223 std::max(0.0, last_retarget_.InSecondsF() - t)); | 223 std::max(0.0, last_retarget_.InSecondsF() - t)); |
| 224 t = std::max(t, last_retarget_.InSecondsF()); | 224 t = std::max(t, last_retarget_.InSecondsF()); |
| 225 | 225 |
| 226 gfx::ScrollOffset current_position = | 226 gfx::ScrollOffset current_position = |
| 227 GetValue(base::TimeDelta::FromSecondsD(t)); | 227 GetValue(base::TimeDelta::FromSecondsD(t)); |
| 228 gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_); | 228 gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_); |
| 229 gfx::Vector2dF new_delta = new_target.DeltaFrom(current_position); | 229 gfx::Vector2dF new_delta = new_target.DeltaFrom(current_position); |
| 230 | 230 |
| 231 // The last segement was of zero duration. | |
| 232 if ((total_animation_duration_ - last_retarget_).is_zero()) { | |
| 233 DCHECK_EQ(t, last_retarget_.InSecondsF()); | |
| 234 total_animation_duration_ = | |
| 235 SegmentDuration(new_delta, duration_behavior_, base::TimeDelta()); | |
|
skobes
2016/09/12 22:45:46
Pass delayed_by here?
ymalik
2016/09/12 23:35:05
Done.
| |
| 236 target_value_ = new_target; | |
| 237 return; | |
| 238 } | |
| 239 | |
| 231 double old_duration = | 240 double old_duration = |
| 232 (total_animation_duration_ - last_retarget_).InSecondsF(); | 241 (total_animation_duration_ - last_retarget_).InSecondsF(); |
| 233 double old_normalized_velocity = timing_function_->Velocity( | 242 double old_normalized_velocity = timing_function_->Velocity( |
| 234 (t - last_retarget_.InSecondsF()) / old_duration); | 243 (t - last_retarget_.InSecondsF()) / old_duration); |
| 235 | 244 |
| 236 // Use the velocity-based duration bound when it is less than the constant | 245 // Use the velocity-based duration bound when it is less than the constant |
| 237 // segment duration. This minimizes the "rubber-band" bouncing effect when | 246 // segment duration. This minimizes the "rubber-band" bouncing effect when |
| 238 // old_normalized_velocity is large and new_delta is small. | 247 // old_normalized_velocity is large and new_delta is small. |
| 239 double new_duration = std::min( | 248 double new_duration = std::min( |
| 240 SegmentDuration(new_delta, duration_behavior_, delayed_by).InSecondsF(), | 249 SegmentDuration(new_delta, duration_behavior_, delayed_by).InSecondsF(), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 256 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); | 265 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); |
| 257 | 266 |
| 258 initial_value_ = current_position; | 267 initial_value_ = current_position; |
| 259 target_value_ = new_target; | 268 target_value_ = new_target; |
| 260 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); | 269 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); |
| 261 last_retarget_ = base::TimeDelta::FromSecondsD(t); | 270 last_retarget_ = base::TimeDelta::FromSecondsD(t); |
| 262 timing_function_ = EaseOutWithInitialVelocity(new_normalized_velocity); | 271 timing_function_ = EaseOutWithInitialVelocity(new_normalized_velocity); |
| 263 } | 272 } |
| 264 | 273 |
| 265 } // namespace cc | 274 } // namespace cc |
| OLD | NEW |