| 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 20 matching lines...) Expand all Loading... |
| 31 (std::sqrt(MaximumDimension(delta)) / kDurationDivisor) * | 31 (std::sqrt(MaximumDimension(delta)) / kDurationDivisor) * |
| 32 base::Time::kMicrosecondsPerSecond); | 32 base::Time::kMicrosecondsPerSecond); |
| 33 } | 33 } |
| 34 | 34 |
| 35 static scoped_ptr<TimingFunction> EaseOutWithInitialVelocity(double velocity) { | 35 static scoped_ptr<TimingFunction> EaseOutWithInitialVelocity(double velocity) { |
| 36 // Based on EaseInOutTimingFunction::Create with first control point rotated. | 36 // Based on EaseInOutTimingFunction::Create with first control point rotated. |
| 37 const double r2 = 0.42 * 0.42; | 37 const double r2 = 0.42 * 0.42; |
| 38 const double v2 = velocity * velocity; | 38 const double v2 = velocity * velocity; |
| 39 const double x1 = std::sqrt(r2 / (v2 + 1)); | 39 const double x1 = std::sqrt(r2 / (v2 + 1)); |
| 40 const double y1 = std::sqrt(r2 * v2 / (v2 + 1)); | 40 const double y1 = std::sqrt(r2 * v2 / (v2 + 1)); |
| 41 return CubicBezierTimingFunction::Create(x1, y1, 0.58, 1); | 41 return CubicBezierTimingFunction::Create(x1, y1, 0.58, 1) |
| 42 .PassAs<TimingFunction>(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 } // namespace | 45 } // namespace |
| 45 | 46 |
| 46 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( | 47 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( |
| 47 const gfx::Vector2dF& target_value, | 48 const gfx::Vector2dF& target_value, |
| 48 scoped_ptr<TimingFunction> timing_function) { | 49 scoped_ptr<TimingFunction> timing_function) { |
| 49 return make_scoped_ptr( | 50 return make_scoped_ptr( |
| 50 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); | 51 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); |
| 51 } | 52 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 91 } |
| 91 | 92 |
| 92 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { | 93 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { |
| 93 scoped_ptr<TimingFunction> timing_function( | 94 scoped_ptr<TimingFunction> timing_function( |
| 94 static_cast<TimingFunction*>(timing_function_->Clone().release())); | 95 static_cast<TimingFunction*>(timing_function_->Clone().release())); |
| 95 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = | 96 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = |
| 96 Create(target_value_, timing_function.Pass()); | 97 Create(target_value_, timing_function.Pass()); |
| 97 curve_clone->initial_value_ = initial_value_; | 98 curve_clone->initial_value_ = initial_value_; |
| 98 curve_clone->total_animation_duration_ = total_animation_duration_; | 99 curve_clone->total_animation_duration_ = total_animation_duration_; |
| 99 curve_clone->last_retarget_ = last_retarget_; | 100 curve_clone->last_retarget_ = last_retarget_; |
| 100 return curve_clone.Pass(); | 101 return curve_clone.PassAs<AnimationCurve>(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void ScrollOffsetAnimationCurve::UpdateTarget( | 104 void ScrollOffsetAnimationCurve::UpdateTarget( |
| 104 double t, | 105 double t, |
| 105 const gfx::Vector2dF& new_target) { | 106 const gfx::Vector2dF& new_target) { |
| 106 gfx::Vector2dF current_position = GetValue(t); | 107 gfx::Vector2dF current_position = GetValue(t); |
| 107 gfx::Vector2dF old_delta = target_value_ - initial_value_; | 108 gfx::Vector2dF old_delta = target_value_ - initial_value_; |
| 108 gfx::Vector2dF new_delta = new_target - current_position; | 109 gfx::Vector2dF new_delta = new_target - current_position; |
| 109 | 110 |
| 110 double old_duration = | 111 double old_duration = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 122 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); | 123 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); |
| 123 | 124 |
| 124 initial_value_ = current_position; | 125 initial_value_ = current_position; |
| 125 target_value_ = new_target; | 126 target_value_ = new_target; |
| 126 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); | 127 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); |
| 127 last_retarget_ = base::TimeDelta::FromSecondsD(t); | 128 last_retarget_ = base::TimeDelta::FromSecondsD(t); |
| 128 timing_function_ = EaseOutWithInitialVelocity(new_velocity); | 129 timing_function_ = EaseOutWithInitialVelocity(new_velocity); |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace cc | 132 } // namespace cc |
| OLD | NEW |