1 // Copyright 2012 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 "base/logging.h"
6 #include "cc/animation/timing_function.h"
10 TimingFunction::TimingFunction() {}
12 TimingFunction::~TimingFunction() {}
14 double TimingFunction::Duration() const {
18 scoped_ptr
<CubicBezierTimingFunction
> CubicBezierTimingFunction::Create(
19 double x1
, double y1
, double x2
, double y2
) {
20 return make_scoped_ptr(new CubicBezierTimingFunction(x1
, y1
, x2
, y2
));
23 CubicBezierTimingFunction::CubicBezierTimingFunction(double x1
,
27 : bezier_(x1
, y1
, x2
, y2
) {}
29 CubicBezierTimingFunction::~CubicBezierTimingFunction() {}
31 float CubicBezierTimingFunction::GetValue(double x
) const {
32 return static_cast<float>(bezier_
.Solve(x
));
35 scoped_ptr
<AnimationCurve
> CubicBezierTimingFunction::Clone() const {
36 return make_scoped_ptr(
37 new CubicBezierTimingFunction(*this)).PassAs
<AnimationCurve
>();
40 void CubicBezierTimingFunction::Range(float* min
, float* max
) const {
43 bezier_
.Range(&min_d
, &max_d
);
44 *min
= static_cast<float>(min_d
);
45 *max
= static_cast<float>(max_d
);
48 // These numbers come from
49 // http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag.
50 scoped_ptr
<TimingFunction
> EaseTimingFunction::Create() {
51 return CubicBezierTimingFunction::Create(
52 0.25, 0.1, 0.25, 1.0).PassAs
<TimingFunction
>();
55 scoped_ptr
<TimingFunction
> EaseInTimingFunction::Create() {
56 return CubicBezierTimingFunction::Create(
57 0.42, 0.0, 1.0, 1.0).PassAs
<TimingFunction
>();
60 scoped_ptr
<TimingFunction
> EaseOutTimingFunction::Create() {
61 return CubicBezierTimingFunction::Create(
62 0.0, 0.0, 0.58, 1.0).PassAs
<TimingFunction
>();
65 scoped_ptr
<TimingFunction
> EaseInOutTimingFunction::Create() {
66 return CubicBezierTimingFunction::Create(
67 0.42, 0.0, 0.58, 1).PassAs
<TimingFunction
>();