Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(737)

Side by Side Diff: content/renderer/compositor_bindings/web_animation_impl.cc

Issue 470983004: Move blink<->cc bindings to cc/blink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "content/renderer/compositor_bindings/web_animation_impl.h"
6
7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_id_provider.h"
10 #include "content/renderer/compositor_bindings/web_filter_animation_curve_impl.h "
11 #include "content/renderer/compositor_bindings/web_float_animation_curve_impl.h"
12 #include "content/renderer/compositor_bindings/web_scroll_offset_animation_curve _impl.h"
13 #include "content/renderer/compositor_bindings/web_transform_animation_curve_imp l.h"
14 #include "third_party/WebKit/public/platform/WebCompositorAnimation.h"
15
16 using cc::Animation;
17 using cc::AnimationIdProvider;
18
19 using blink::WebCompositorAnimation;
20 using blink::WebCompositorAnimationCurve;
21
22 namespace content {
23
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();
33
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;
42 }
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;
48 }
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;
54 }
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;
60 }
61 }
62 animation_ = Animation::Create(
63 curve.Pass(),
64 animation_id,
65 group_id,
66 static_cast<cc::Animation::TargetProperty>(target_property));
67 }
68
69 WebCompositorAnimationImpl::~WebCompositorAnimationImpl() {
70 }
71
72 int WebCompositorAnimationImpl::id() {
73 return animation_->id();
74 }
75
76 blink::WebCompositorAnimation::TargetProperty
77 WebCompositorAnimationImpl::targetProperty() const {
78 return static_cast<WebCompositorAnimationImpl::TargetProperty>(
79 animation_->target_property());
80 }
81
82 #if WEB_ANIMATION_SUPPORTS_FRACTIONAL_ITERATIONS
83 double WebCompositorAnimationImpl::iterations() const {
84 return animation_->iterations();
85 }
86
87 void WebCompositorAnimationImpl::setIterations(double n) {
88 animation_->set_iterations(n);
89 }
90 #else
91 int WebCompositorAnimationImpl::iterations() const {
92 return animation_->iterations();
93 }
94
95 void WebCompositorAnimationImpl::setIterations(int n) {
96 animation_->set_iterations(n);
97 }
98 #endif
99
100 double WebCompositorAnimationImpl::startTime() const {
101 return (animation_->start_time() - base::TimeTicks()).InSecondsF();
102 }
103
104 void WebCompositorAnimationImpl::setStartTime(double monotonic_time) {
105 animation_->set_start_time(base::TimeTicks::FromInternalValue(
106 monotonic_time * base::Time::kMicrosecondsPerSecond));
107 }
108
109 double WebCompositorAnimationImpl::timeOffset() const {
110 return animation_->time_offset().InSecondsF();
111 }
112
113 void WebCompositorAnimationImpl::setTimeOffset(double monotonic_time) {
114 animation_->set_time_offset(base::TimeDelta::FromSecondsD(monotonic_time));
115 }
116
117 #if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION
118 blink::WebCompositorAnimation::Direction WebCompositorAnimationImpl::direction()
119 const {
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;
129 default:
130 NOTREACHED();
131 }
132 return DirectionNormal;
133 }
134
135 void WebCompositorAnimationImpl::setDirection(Direction direction) {
136 switch (direction) {
137 case DirectionNormal:
138 animation_->set_direction(cc::Animation::Normal);
139 break;
140 case DirectionReverse:
141 animation_->set_direction(cc::Animation::Reverse);
142 break;
143 case DirectionAlternate:
144 animation_->set_direction(cc::Animation::Alternate);
145 break;
146 case DirectionAlternateReverse:
147 animation_->set_direction(cc::Animation::AlternateReverse);
148 break;
149 }
150 }
151 #else
152 bool WebCompositorAnimationImpl::alternatesDirection() const {
153 return animation_->direction() == cc::Animation::Alternate;
154 }
155
156 void WebCompositorAnimationImpl::setAlternatesDirection(bool alternates) {
157 if (alternates)
158 animation_->set_direction(cc::Animation::Alternate);
159 else
160 animation_->set_direction(cc::Animation::Normal);
161 }
162 #endif
163
164 scoped_ptr<cc::Animation> WebCompositorAnimationImpl::PassAnimation() {
165 animation_->set_needs_synchronized_start_time(true);
166 return animation_.Pass();
167 }
168
169 } // namespace content
170
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698