1 // Copyright 2014 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.
4
5 #include "content/renderer/compositor_bindings/web_float_animation_curve_impl.h"
6
7 #include "cc/animation/animation_curve.h"
8 #include "cc/animation/keyframed_animation_curve.h"
9 #include "cc/animation/timing_function.h"
10 #include "content/renderer/compositor_bindings/web_animation_curve_common.h"
11
12 using blink::WebFloatKeyframe;
13
14 namespace content {
15
WebFloatAnimationCurveImpl()16 WebFloatAnimationCurveImpl::WebFloatAnimationCurveImpl()
17 : curve_(cc::KeyframedFloatAnimationCurve::Create()) {
18 }
19
~WebFloatAnimationCurveImpl()20 WebFloatAnimationCurveImpl::~WebFloatAnimationCurveImpl() {
21 }
22
23 blink::WebAnimationCurve::AnimationCurveType
type() const24 WebFloatAnimationCurveImpl::type() const {
25 return blink::WebAnimationCurve::AnimationCurveTypeFloat;
26 }
27
add(const WebFloatKeyframe & keyframe)28 void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe) {
29 add(keyframe, TimingFunctionTypeEase);
30 }
31
add(const WebFloatKeyframe & keyframe,TimingFunctionType type)32 void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe,
33 TimingFunctionType type) {
34 curve_->AddKeyframe(cc::FloatKeyframe::Create(
35 keyframe.time, keyframe.value, CreateTimingFunction(type)));
36 }
37
add(const WebFloatKeyframe & keyframe,double x1,double y1,double x2,double y2)38 void WebFloatAnimationCurveImpl::add(const WebFloatKeyframe& keyframe,
39 double x1,
40 double y1,
41 double x2,
42 double y2) {
43 curve_->AddKeyframe(cc::FloatKeyframe::Create(
44 keyframe.time,
45 keyframe.value,
46 cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2)
47 .PassAs<cc::TimingFunction>()));
48 }
49
getValue(double time) const50 float WebFloatAnimationCurveImpl::getValue(double time) const {
51 return curve_->GetValue(time);
52 }
53
54 scoped_ptr<cc::AnimationCurve>
CloneToAnimationCurve() const55 WebFloatAnimationCurveImpl::CloneToAnimationCurve() const {
56 return curve_->Clone();
57 }
58
59 } // namespace content
60
61