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 "cc/blink/web_transform_animation_curve_impl.h"
6
7#include "cc/animation/keyframed_animation_curve.h"
8#include "cc/animation/timing_function.h"
9#include "cc/animation/transform_operations.h"
10#include "cc/blink/web_animation_curve_common.h"
11#include "cc/blink/web_transform_operations_impl.h"
12
13using blink::WebTransformKeyframe;
14
15namespace cc_blink {
16
17WebTransformAnimationCurveImpl::WebTransformAnimationCurveImpl()
18    : curve_(cc::KeyframedTransformAnimationCurve::Create()) {
19}
20
21WebTransformAnimationCurveImpl::~WebTransformAnimationCurveImpl() {
22}
23
24blink::WebCompositorAnimationCurve::AnimationCurveType
25WebTransformAnimationCurveImpl::type() const {
26  return WebCompositorAnimationCurve::AnimationCurveTypeTransform;
27}
28
29void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe) {
30  add(keyframe, TimingFunctionTypeEase);
31}
32
33void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe,
34                                         TimingFunctionType type) {
35  const cc::TransformOperations& transform_operations =
36      static_cast<const WebTransformOperationsImpl&>(keyframe.value())
37          .AsTransformOperations();
38  curve_->AddKeyframe(cc::TransformKeyframe::Create(
39      keyframe.time(), transform_operations, CreateTimingFunction(type)));
40}
41
42void WebTransformAnimationCurveImpl::add(const WebTransformKeyframe& keyframe,
43                                         double x1,
44                                         double y1,
45                                         double x2,
46                                         double y2) {
47  const cc::TransformOperations& transform_operations =
48      static_cast<const WebTransformOperationsImpl&>(keyframe.value())
49          .AsTransformOperations();
50  curve_->AddKeyframe(cc::TransformKeyframe::Create(
51      keyframe.time(),
52      transform_operations,
53      cc::CubicBezierTimingFunction::Create(x1, y1, x2, y2)
54          .PassAs<cc::TimingFunction>()));
55}
56
57scoped_ptr<cc::AnimationCurve>
58WebTransformAnimationCurveImpl::CloneToAnimationCurve() const {
59  return curve_->Clone();
60}
61
62}  // namespace cc_blink
63