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.
5 #include "cc/blink/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 "cc/blink/web_filter_animation_curve_impl.h"
11 #include "cc/blink/web_float_animation_curve_impl.h"
12 #include "cc/blink/web_scroll_offset_animation_curve_impl.h"
13 #include "cc/blink/web_transform_animation_curve_impl.h"
14 #include "third_party/WebKit/public/platform/WebCompositorAnimationCurve.h"
17 using cc::AnimationIdProvider
;
19 using blink::WebCompositorAnimation
;
20 using blink::WebCompositorAnimationCurve
;
24 WebCompositorAnimationImpl::WebCompositorAnimationImpl(
25 const WebCompositorAnimationCurve
& web_curve
,
26 TargetProperty target_property
,
30 animation_id
= AnimationIdProvider::NextAnimationId();
32 group_id
= AnimationIdProvider::NextGroupId();
34 WebCompositorAnimationCurve::AnimationCurveType curve_type
= web_curve
.type();
35 scoped_ptr
<cc::AnimationCurve
> curve
;
37 case WebCompositorAnimationCurve::AnimationCurveTypeFloat
: {
38 const WebFloatAnimationCurveImpl
* float_curve_impl
=
39 static_cast<const WebFloatAnimationCurveImpl
*>(&web_curve
);
40 curve
= float_curve_impl
->CloneToAnimationCurve();
43 case WebCompositorAnimationCurve::AnimationCurveTypeTransform
: {
44 const WebTransformAnimationCurveImpl
* transform_curve_impl
=
45 static_cast<const WebTransformAnimationCurveImpl
*>(&web_curve
);
46 curve
= transform_curve_impl
->CloneToAnimationCurve();
49 case WebCompositorAnimationCurve::AnimationCurveTypeFilter
: {
50 const WebFilterAnimationCurveImpl
* filter_curve_impl
=
51 static_cast<const WebFilterAnimationCurveImpl
*>(&web_curve
);
52 curve
= filter_curve_impl
->CloneToAnimationCurve();
55 case WebCompositorAnimationCurve::AnimationCurveTypeScrollOffset
: {
56 const WebScrollOffsetAnimationCurveImpl
* scroll_curve_impl
=
57 static_cast<const WebScrollOffsetAnimationCurveImpl
*>(&web_curve
);
58 curve
= scroll_curve_impl
->CloneToAnimationCurve();
62 animation_
= Animation::Create(
66 static_cast<cc::Animation::TargetProperty
>(target_property
));
69 WebCompositorAnimationImpl::~WebCompositorAnimationImpl() {
72 int WebCompositorAnimationImpl::id() {
73 return animation_
->id();
76 blink::WebCompositorAnimation::TargetProperty
77 WebCompositorAnimationImpl::targetProperty() const {
78 return static_cast<WebCompositorAnimationImpl::TargetProperty
>(
79 animation_
->target_property());
82 #if WEB_ANIMATION_SUPPORTS_FRACTIONAL_ITERATIONS
83 double WebCompositorAnimationImpl::iterations() const {
84 return animation_
->iterations();
87 void WebCompositorAnimationImpl::setIterations(double n
) {
88 animation_
->set_iterations(n
);
91 int WebCompositorAnimationImpl::iterations() const {
92 return animation_
->iterations();
95 void WebCompositorAnimationImpl::setIterations(int n
) {
96 animation_
->set_iterations(n
);
100 double WebCompositorAnimationImpl::startTime() const {
101 return (animation_
->start_time() - base::TimeTicks()).InSecondsF();
104 void WebCompositorAnimationImpl::setStartTime(double monotonic_time
) {
105 animation_
->set_start_time(base::TimeTicks::FromInternalValue(
106 monotonic_time
* base::Time::kMicrosecondsPerSecond
));
109 double WebCompositorAnimationImpl::timeOffset() const {
110 return animation_
->time_offset().InSecondsF();
113 void WebCompositorAnimationImpl::setTimeOffset(double monotonic_time
) {
114 animation_
->set_time_offset(base::TimeDelta::FromSecondsD(monotonic_time
));
117 #if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION
118 blink::WebCompositorAnimation::Direction
WebCompositorAnimationImpl::direction()
120 switch (animation_
->direction()) {
121 case cc::Animation::Normal
:
122 return DirectionNormal
;
123 case cc::Animation::Reverse
:
124 return DirectionReverse
;
125 case cc::Animation::Alternate
:
126 return DirectionAlternate
;
127 case cc::Animation::AlternateReverse
:
128 return DirectionAlternateReverse
;
132 return DirectionNormal
;
135 void WebCompositorAnimationImpl::setDirection(Direction direction
) {
137 case DirectionNormal
:
138 animation_
->set_direction(cc::Animation::Normal
);
140 case DirectionReverse
:
141 animation_
->set_direction(cc::Animation::Reverse
);
143 case DirectionAlternate
:
144 animation_
->set_direction(cc::Animation::Alternate
);
146 case DirectionAlternateReverse
:
147 animation_
->set_direction(cc::Animation::AlternateReverse
);
152 bool WebCompositorAnimationImpl::alternatesDirection() const {
153 return animation_
->direction() == cc::Animation::Alternate
;
156 void WebCompositorAnimationImpl::setAlternatesDirection(bool alternates
) {
158 animation_
->set_direction(cc::Animation::Alternate
);
160 animation_
->set_direction(cc::Animation::Normal
);
164 double WebCompositorAnimationImpl::playbackRate() const {
165 return animation_
->playback_rate();
168 void WebCompositorAnimationImpl::setPlaybackRate(double playback_rate
) {
169 animation_
->set_playback_rate(playback_rate
);
172 scoped_ptr
<cc::Animation
> WebCompositorAnimationImpl::PassAnimation() {
173 animation_
->set_needs_synchronized_start_time(true);
174 return animation_
.Pass();
177 } // namespace cc_blink