Adds initial key systems support for Chromecast.
[chromium-blink-merge.git] / cc / blink / web_animation_impl.cc
blob1f19937c15bc305dfaa2f8ddb60918b1ba4816d2
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 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);
90 #else
91 int WebCompositorAnimationImpl::iterations() const {
92 return animation_->iterations();
95 void WebCompositorAnimationImpl::setIterations(int n) {
96 animation_->set_iterations(n);
98 #endif
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 blink::WebCompositorAnimation::Direction WebCompositorAnimationImpl::direction()
118 const {
119 switch (animation_->direction()) {
120 case cc::Animation::Normal:
121 return DirectionNormal;
122 case cc::Animation::Reverse:
123 return DirectionReverse;
124 case cc::Animation::Alternate:
125 return DirectionAlternate;
126 case cc::Animation::AlternateReverse:
127 return DirectionAlternateReverse;
128 default:
129 NOTREACHED();
131 return DirectionNormal;
134 void WebCompositorAnimationImpl::setDirection(Direction direction) {
135 switch (direction) {
136 case DirectionNormal:
137 animation_->set_direction(cc::Animation::Normal);
138 break;
139 case DirectionReverse:
140 animation_->set_direction(cc::Animation::Reverse);
141 break;
142 case DirectionAlternate:
143 animation_->set_direction(cc::Animation::Alternate);
144 break;
145 case DirectionAlternateReverse:
146 animation_->set_direction(cc::Animation::AlternateReverse);
147 break;
151 double WebCompositorAnimationImpl::playbackRate() const {
152 return animation_->playback_rate();
155 void WebCompositorAnimationImpl::setPlaybackRate(double playback_rate) {
156 animation_->set_playback_rate(playback_rate);
159 scoped_ptr<cc::Animation> WebCompositorAnimationImpl::PassAnimation() {
160 animation_->set_needs_synchronized_start_time(true);
161 return animation_.Pass();
164 } // namespace cc_blink