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 int WebCompositorAnimationImpl::group() {
77 return animation_
->group();
80 blink::WebCompositorAnimation::TargetProperty
81 WebCompositorAnimationImpl::targetProperty() const {
82 return static_cast<WebCompositorAnimationImpl::TargetProperty
>(
83 animation_
->target_property());
86 double WebCompositorAnimationImpl::iterations() const {
87 return animation_
->iterations();
90 void WebCompositorAnimationImpl::setIterations(double n
) {
91 animation_
->set_iterations(n
);
94 double WebCompositorAnimationImpl::iterationStart() const {
95 return animation_
->iteration_start();
98 void WebCompositorAnimationImpl::setIterationStart(double iteration_start
) {
99 animation_
->set_iteration_start(iteration_start
);
102 double WebCompositorAnimationImpl::startTime() const {
103 return (animation_
->start_time() - base::TimeTicks()).InSecondsF();
106 void WebCompositorAnimationImpl::setStartTime(double monotonic_time
) {
107 animation_
->set_start_time(base::TimeTicks::FromInternalValue(
108 monotonic_time
* base::Time::kMicrosecondsPerSecond
));
111 double WebCompositorAnimationImpl::timeOffset() const {
112 return animation_
->time_offset().InSecondsF();
115 void WebCompositorAnimationImpl::setTimeOffset(double monotonic_time
) {
116 animation_
->set_time_offset(base::TimeDelta::FromSecondsD(monotonic_time
));
119 blink::WebCompositorAnimation::Direction
WebCompositorAnimationImpl::direction()
121 switch (animation_
->direction()) {
122 case cc::Animation::DIRECTION_NORMAL
:
123 return DirectionNormal
;
124 case cc::Animation::DIRECTION_REVERSE
:
125 return DirectionReverse
;
126 case cc::Animation::DIRECTION_ALTERNATE
:
127 return DirectionAlternate
;
128 case cc::Animation::DIRECTION_ALTERNATE_REVERSE
:
129 return DirectionAlternateReverse
;
133 return DirectionNormal
;
136 void WebCompositorAnimationImpl::setDirection(Direction direction
) {
138 case DirectionNormal
:
139 animation_
->set_direction(cc::Animation::DIRECTION_NORMAL
);
141 case DirectionReverse
:
142 animation_
->set_direction(cc::Animation::DIRECTION_REVERSE
);
144 case DirectionAlternate
:
145 animation_
->set_direction(cc::Animation::DIRECTION_ALTERNATE
);
147 case DirectionAlternateReverse
:
148 animation_
->set_direction(cc::Animation::DIRECTION_ALTERNATE_REVERSE
);
153 double WebCompositorAnimationImpl::playbackRate() const {
154 return animation_
->playback_rate();
157 void WebCompositorAnimationImpl::setPlaybackRate(double playback_rate
) {
158 animation_
->set_playback_rate(playback_rate
);
161 blink::WebCompositorAnimation::FillMode
WebCompositorAnimationImpl::fillMode()
163 switch (animation_
->fill_mode()) {
164 case cc::Animation::FILL_MODE_NONE
:
166 case cc::Animation::FILL_MODE_FORWARDS
:
167 return FillModeForwards
;
168 case cc::Animation::FILL_MODE_BACKWARDS
:
169 return FillModeBackwards
;
170 case cc::Animation::FILL_MODE_BOTH
:
178 void WebCompositorAnimationImpl::setFillMode(FillMode fill_mode
) {
181 animation_
->set_fill_mode(cc::Animation::FILL_MODE_NONE
);
183 case FillModeForwards
:
184 animation_
->set_fill_mode(cc::Animation::FILL_MODE_FORWARDS
);
186 case FillModeBackwards
:
187 animation_
->set_fill_mode(cc::Animation::FILL_MODE_BACKWARDS
);
190 animation_
->set_fill_mode(cc::Animation::FILL_MODE_BOTH
);
195 scoped_ptr
<cc::Animation
> WebCompositorAnimationImpl::PassAnimation() {
196 animation_
->set_needs_synchronized_start_time(true);
197 return animation_
.Pass();
200 } // namespace cc_blink