Remove --disable-app-shims.
[chromium-blink-merge.git] / cc / animation / scroll_offset_animation_curve.cc
bloba7283b8b5c601aca4a6f3dfac4e269b167c17966
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
3 // found in the LICENSE file.
5 #include "cc/animation/scroll_offset_animation_curve.h"
7 #include <algorithm>
8 #include <cmath>
10 #include "base/logging.h"
11 #include "cc/animation/timing_function.h"
12 #include "ui/gfx/animation/tween.h"
14 const double kDurationDivisor = 60.0;
16 namespace cc {
18 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create(
19 const gfx::Vector2dF& target_value,
20 scoped_ptr<TimingFunction> timing_function) {
21 return make_scoped_ptr(
22 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass()));
25 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
26 const gfx::Vector2dF& target_value,
27 scoped_ptr<TimingFunction> timing_function)
28 : target_value_(target_value), timing_function_(timing_function.Pass()) {
31 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {}
33 void ScrollOffsetAnimationCurve::SetInitialValue(
34 const gfx::Vector2dF& initial_value) {
35 initial_value_ = initial_value;
37 // 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 // 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 // tweaked before the smooth scroll API ships.
42 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 max_delta = std::max(delta_x, delta_y);
45 duration_ = base::TimeDelta::FromMicroseconds(
46 (std::sqrt(max_delta) / kDurationDivisor) *
47 base::Time::kMicrosecondsPerSecond);
50 gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(double t) const {
51 double duration = duration_.InSecondsF();
53 if (t <= 0)
54 return initial_value_;
56 if (t >= duration)
57 return target_value_;
59 double progress = (timing_function_->GetValue(t / duration));
60 return gfx::Vector2dF(gfx::Tween::FloatValueBetween(
61 progress, initial_value_.x(), target_value_.x()),
62 gfx::Tween::FloatValueBetween(
63 progress, initial_value_.y(), target_value_.y()));
66 double ScrollOffsetAnimationCurve::Duration() const {
67 return duration_.InSecondsF();
70 AnimationCurve::CurveType ScrollOffsetAnimationCurve::Type() const {
71 return ScrollOffset;
74 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const {
75 scoped_ptr<TimingFunction> timing_function(
76 static_cast<TimingFunction*>(timing_function_->Clone().release()));
77 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone =
78 Create(target_value_, timing_function.Pass());
79 curve_clone->initial_value_ = initial_value_;
80 curve_clone->duration_ = duration_;
81 return curve_clone.PassAs<AnimationCurve>();
84 } // namespace cc