| 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" |
| 11 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
| 12 #include "ui/gfx/animation/tween.h" | 12 #include "ui/gfx/animation/tween.h" |
| 13 | 13 |
| 14 const double kDurationDivisor = 60.0; | 14 const double kDurationDivisor = 60.0; |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 | 17 |
| 18 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( | 18 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( |
| 19 gfx::Vector2dF target_value, | 19 const gfx::Vector2dF& target_value, |
| 20 scoped_ptr<TimingFunction> timing_function) { | 20 scoped_ptr<TimingFunction> timing_function) { |
| 21 return make_scoped_ptr( | 21 return make_scoped_ptr( |
| 22 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); | 22 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); |
| 23 } | 23 } |
| 24 | 24 |
| 25 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( | 25 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( |
| 26 gfx::Vector2dF target_value, | 26 const gfx::Vector2dF& target_value, |
| 27 scoped_ptr<TimingFunction> timing_function) | 27 scoped_ptr<TimingFunction> timing_function) |
| 28 : target_value_(target_value), | 28 : target_value_(target_value), |
| 29 duration_(0.0), | 29 duration_(0.0), |
| 30 timing_function_(timing_function.Pass()) {} | 30 timing_function_(timing_function.Pass()) {} |
| 31 | 31 |
| 32 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} | 32 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} |
| 33 | 33 |
| 34 void ScrollOffsetAnimationCurve::SetInitialValue(gfx::Vector2dF initial_value) { | 34 void ScrollOffsetAnimationCurve::SetInitialValue( |
| 35 const gfx::Vector2dF& initial_value) { |
| 35 initial_value_ = initial_value; | 36 initial_value_ = initial_value; |
| 36 | 37 |
| 37 // The duration of a scroll animation depends on the size of the scroll. | 38 // The duration of a scroll animation depends on the size of the scroll. |
| 38 // The exact relationship between the size and the duration isn't specified | 39 // The exact relationship between the size and the duration isn't specified |
| 39 // by the CSSOM View smooth scroll spec and is instead left up to user agents | 40 // by the CSSOM View smooth scroll spec and is instead left up to user agents |
| 40 // to decide. The calculation performed here will very likely be further | 41 // to decide. The calculation performed here will very likely be further |
| 41 // tweaked before the smooth scroll API ships. | 42 // tweaked before the smooth scroll API ships. |
| 42 float delta_x = std::abs(target_value_.x() - initial_value_.x()); | 43 float delta_x = std::abs(target_value_.x() - initial_value_.x()); |
| 43 float delta_y = std::abs(target_value_.y() - initial_value_.y()); | 44 float delta_y = std::abs(target_value_.y() - initial_value_.y()); |
| 44 float max_delta = std::max(delta_x, delta_y); | 45 float max_delta = std::max(delta_x, delta_y); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 71 scoped_ptr<TimingFunction> timing_function( | 72 scoped_ptr<TimingFunction> timing_function( |
| 72 static_cast<TimingFunction*>(timing_function_->Clone().release())); | 73 static_cast<TimingFunction*>(timing_function_->Clone().release())); |
| 73 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = | 74 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = |
| 74 Create(target_value_, timing_function.Pass()); | 75 Create(target_value_, timing_function.Pass()); |
| 75 curve_clone->initial_value_ = initial_value_; | 76 curve_clone->initial_value_ = initial_value_; |
| 76 curve_clone->duration_ = duration_; | 77 curve_clone->duration_ = duration_; |
| 77 return curve_clone.PassAs<AnimationCurve>(); | 78 return curve_clone.PassAs<AnimationCurve>(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 } // namespace cc | 81 } // namespace cc |
| OLD | NEW |