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>(); | |
43 } | 42 } |
44 | 43 |
45 } // namespace | 44 } // namespace |
46 | 45 |
47 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( | 46 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( |
48 const gfx::Vector2dF& target_value, | 47 const gfx::Vector2dF& target_value, |
49 scoped_ptr<TimingFunction> timing_function) { | 48 scoped_ptr<TimingFunction> timing_function) { |
50 return make_scoped_ptr( | 49 return make_scoped_ptr( |
51 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); | 50 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); |
52 } | 51 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 90 } |
92 | 91 |
93 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { | 92 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { |
94 scoped_ptr<TimingFunction> timing_function( | 93 scoped_ptr<TimingFunction> timing_function( |
95 static_cast<TimingFunction*>(timing_function_->Clone().release())); | 94 static_cast<TimingFunction*>(timing_function_->Clone().release())); |
96 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = | 95 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = |
97 Create(target_value_, timing_function.Pass()); | 96 Create(target_value_, timing_function.Pass()); |
98 curve_clone->initial_value_ = initial_value_; | 97 curve_clone->initial_value_ = initial_value_; |
99 curve_clone->total_animation_duration_ = total_animation_duration_; | 98 curve_clone->total_animation_duration_ = total_animation_duration_; |
100 curve_clone->last_retarget_ = last_retarget_; | 99 curve_clone->last_retarget_ = last_retarget_; |
101 return curve_clone.PassAs<AnimationCurve>(); | 100 return curve_clone.Pass(); |
102 } | 101 } |
103 | 102 |
104 void ScrollOffsetAnimationCurve::UpdateTarget( | 103 void ScrollOffsetAnimationCurve::UpdateTarget( |
105 double t, | 104 double t, |
106 const gfx::Vector2dF& new_target) { | 105 const gfx::Vector2dF& new_target) { |
107 gfx::Vector2dF current_position = GetValue(t); | 106 gfx::Vector2dF current_position = GetValue(t); |
108 gfx::Vector2dF old_delta = target_value_ - initial_value_; | 107 gfx::Vector2dF old_delta = target_value_ - initial_value_; |
109 gfx::Vector2dF new_delta = new_target - current_position; | 108 gfx::Vector2dF new_delta = new_target - current_position; |
110 | 109 |
111 double old_duration = | 110 double old_duration = |
(...skipping 11 matching lines...) Expand all Loading... |
123 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); | 122 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); |
124 | 123 |
125 initial_value_ = current_position; | 124 initial_value_ = current_position; |
126 target_value_ = new_target; | 125 target_value_ = new_target; |
127 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); | 126 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); |
128 last_retarget_ = base::TimeDelta::FromSecondsD(t); | 127 last_retarget_ = base::TimeDelta::FromSecondsD(t); |
129 timing_function_ = EaseOutWithInitialVelocity(new_velocity); | 128 timing_function_ = EaseOutWithInitialVelocity(new_velocity); |
130 } | 129 } |
131 | 130 |
132 } // namespace cc | 131 } // namespace cc |
OLD | NEW |