Roll leveldb to r78 / 1.15.
[chromium-blink-merge.git] / webkit / renderer / compositor_bindings / web_animation_impl.cc
blobdbcc184b268168ed8fed0b536ec1a63b547ee14d
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 "webkit/renderer/compositor_bindings/web_animation_impl.h"
7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_id_provider.h"
10 #include "third_party/WebKit/public/platform/WebAnimation.h"
11 #include "third_party/WebKit/public/platform/WebAnimationCurve.h"
12 #include "webkit/renderer/compositor_bindings/web_filter_animation_curve_impl.h"
13 #include "webkit/renderer/compositor_bindings/web_float_animation_curve_impl.h"
14 #include "webkit/renderer/compositor_bindings/web_transform_animation_curve_impl.h"
16 using cc::Animation;
17 using cc::AnimationIdProvider;
19 using blink::WebAnimation;
20 using blink::WebAnimationCurve;
22 namespace webkit {
24 WebAnimationImpl::WebAnimationImpl(const WebAnimationCurve& web_curve,
25 TargetProperty target_property,
26 int animation_id,
27 int group_id) {
28 if (!animation_id)
29 animation_id = AnimationIdProvider::NextAnimationId();
30 if (!group_id)
31 group_id = AnimationIdProvider::NextGroupId();
33 WebAnimationCurve::AnimationCurveType curve_type = web_curve.type();
34 scoped_ptr<cc::AnimationCurve> curve;
35 switch (curve_type) {
36 case WebAnimationCurve::AnimationCurveTypeFloat: {
37 const WebFloatAnimationCurveImpl* float_curve_impl =
38 static_cast<const WebFloatAnimationCurveImpl*>(&web_curve);
39 curve = float_curve_impl->CloneToAnimationCurve();
40 break;
42 case WebAnimationCurve::AnimationCurveTypeTransform: {
43 const WebTransformAnimationCurveImpl* transform_curve_impl =
44 static_cast<const WebTransformAnimationCurveImpl*>(&web_curve);
45 curve = transform_curve_impl->CloneToAnimationCurve();
46 break;
48 case WebAnimationCurve::AnimationCurveTypeFilter: {
49 const WebFilterAnimationCurveImpl* filter_curve_impl =
50 static_cast<const WebFilterAnimationCurveImpl*>(&web_curve);
51 curve = filter_curve_impl->CloneToAnimationCurve();
52 break;
55 animation_ = Animation::Create(
56 curve.Pass(),
57 animation_id,
58 group_id,
59 static_cast<cc::Animation::TargetProperty>(target_property));
62 WebAnimationImpl::~WebAnimationImpl() {}
64 int WebAnimationImpl::id() { return animation_->id(); }
66 blink::WebAnimation::TargetProperty WebAnimationImpl::targetProperty() const {
67 return static_cast<WebAnimationImpl::TargetProperty>(
68 animation_->target_property());
71 int WebAnimationImpl::iterations() const { return animation_->iterations(); }
73 void WebAnimationImpl::setIterations(int n) { animation_->set_iterations(n); }
75 double WebAnimationImpl::startTime() const { return animation_->start_time(); }
77 void WebAnimationImpl::setStartTime(double monotonic_time) {
78 animation_->set_start_time(monotonic_time);
81 double WebAnimationImpl::timeOffset() const {
82 return animation_->time_offset();
85 void WebAnimationImpl::setTimeOffset(double monotonic_time) {
86 animation_->set_time_offset(monotonic_time);
89 bool WebAnimationImpl::alternatesDirection() const {
90 return animation_->alternates_direction();
93 void WebAnimationImpl::setAlternatesDirection(bool alternates) {
94 animation_->set_alternates_direction(alternates);
97 scoped_ptr<cc::Animation> WebAnimationImpl::PassAnimation() {
98 animation_->set_needs_synchronized_start_time(true);
99 return animation_.Pass();
102 #define COMPILE_ASSERT_MATCHING_ENUMS(webkit_name, cc_name) \
103 COMPILE_ASSERT(static_cast<int>(webkit_name) == static_cast<int>(cc_name), \
104 mismatching_enums)
106 COMPILE_ASSERT_MATCHING_ENUMS(
107 WebAnimation::TargetPropertyTransform, Animation::Transform);
108 COMPILE_ASSERT_MATCHING_ENUMS(
109 WebAnimation::TargetPropertyOpacity, Animation::Opacity);
110 COMPILE_ASSERT_MATCHING_ENUMS(
111 WebAnimation::TargetPropertyFilter, Animation::Filter);
113 } // namespace webkit