Returning scoped_ptr instead of raw pointer in QuicInfoToValue in net/
[chromium-blink-merge.git] / cc / blink / web_animation_impl.cc
blob705c33a9bf85d18ffef0d43ed0cecd4a2ea02c6c
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"
16 using cc::Animation;
17 using cc::AnimationIdProvider;
19 using blink::WebCompositorAnimation;
20 using blink::WebCompositorAnimationCurve;
22 namespace cc_blink {
24 WebCompositorAnimationImpl::WebCompositorAnimationImpl(
25 const WebCompositorAnimationCurve& web_curve,
26 TargetProperty target_property,
27 int animation_id,
28 int group_id) {
29 if (!animation_id)
30 animation_id = AnimationIdProvider::NextAnimationId();
31 if (!group_id)
32 group_id = AnimationIdProvider::NextGroupId();
34 WebCompositorAnimationCurve::AnimationCurveType curve_type = web_curve.type();
35 scoped_ptr<cc::AnimationCurve> curve;
36 switch (curve_type) {
37 case WebCompositorAnimationCurve::AnimationCurveTypeFloat: {
38 const WebFloatAnimationCurveImpl* float_curve_impl =
39 static_cast<const WebFloatAnimationCurveImpl*>(&web_curve);
40 curve = float_curve_impl->CloneToAnimationCurve();
41 break;
43 case WebCompositorAnimationCurve::AnimationCurveTypeTransform: {
44 const WebTransformAnimationCurveImpl* transform_curve_impl =
45 static_cast<const WebTransformAnimationCurveImpl*>(&web_curve);
46 curve = transform_curve_impl->CloneToAnimationCurve();
47 break;
49 case WebCompositorAnimationCurve::AnimationCurveTypeFilter: {
50 const WebFilterAnimationCurveImpl* filter_curve_impl =
51 static_cast<const WebFilterAnimationCurveImpl*>(&web_curve);
52 curve = filter_curve_impl->CloneToAnimationCurve();
53 break;
55 case WebCompositorAnimationCurve::AnimationCurveTypeScrollOffset: {
56 const WebScrollOffsetAnimationCurveImpl* scroll_curve_impl =
57 static_cast<const WebScrollOffsetAnimationCurveImpl*>(&web_curve);
58 curve = scroll_curve_impl->CloneToAnimationCurve();
59 break;
62 animation_ = Animation::Create(
63 curve.Pass(),
64 animation_id,
65 group_id,
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()
120 const {
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;
130 default:
131 NOTREACHED();
133 return DirectionNormal;
136 void WebCompositorAnimationImpl::setDirection(Direction direction) {
137 switch (direction) {
138 case DirectionNormal:
139 animation_->set_direction(cc::Animation::DIRECTION_NORMAL);
140 break;
141 case DirectionReverse:
142 animation_->set_direction(cc::Animation::DIRECTION_REVERSE);
143 break;
144 case DirectionAlternate:
145 animation_->set_direction(cc::Animation::DIRECTION_ALTERNATE);
146 break;
147 case DirectionAlternateReverse:
148 animation_->set_direction(cc::Animation::DIRECTION_ALTERNATE_REVERSE);
149 break;
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()
162 const {
163 switch (animation_->fill_mode()) {
164 case cc::Animation::FILL_MODE_NONE:
165 return FillModeNone;
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:
171 return FillModeBoth;
172 default:
173 NOTREACHED();
175 return FillModeNone;
178 void WebCompositorAnimationImpl::setFillMode(FillMode fill_mode) {
179 switch (fill_mode) {
180 case FillModeNone:
181 animation_->set_fill_mode(cc::Animation::FILL_MODE_NONE);
182 break;
183 case FillModeForwards:
184 animation_->set_fill_mode(cc::Animation::FILL_MODE_FORWARDS);
185 break;
186 case FillModeBackwards:
187 animation_->set_fill_mode(cc::Animation::FILL_MODE_BACKWARDS);
188 break;
189 case FillModeBoth:
190 animation_->set_fill_mode(cc::Animation::FILL_MODE_BOTH);
191 break;
195 scoped_ptr<cc::Animation> WebCompositorAnimationImpl::PassAnimation() {
196 animation_->set_needs_synchronized_start_time(true);
197 return animation_.Pass();
200 } // namespace cc_blink