OLD | NEW |
| (Empty) |
1 // Copyright 2012 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 "webkit/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 "third_party/WebKit/public/platform/WebAnimation.h" | |
11 #include "third_party/WebKit/public/platform/WebAnimationCurve.h" | |
12 #include "webkit/renderer/compositor_bindings/web_filter_animation_curve_impl.h" | |
13 #include "webkit/renderer/compositor_bindings/web_float_animation_curve_impl.h" | |
14 #include "webkit/renderer/compositor_bindings/web_scroll_offset_animation_curve_
impl.h" | |
15 #include "webkit/renderer/compositor_bindings/web_transform_animation_curve_impl
.h" | |
16 | |
17 using cc::Animation; | |
18 using cc::AnimationIdProvider; | |
19 | |
20 using blink::WebAnimation; | |
21 using blink::WebAnimationCurve; | |
22 | |
23 namespace webkit { | |
24 | |
25 WebAnimationImpl::WebAnimationImpl(const WebAnimationCurve& 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 WebAnimationCurve::AnimationCurveType curve_type = web_curve.type(); | |
35 scoped_ptr<cc::AnimationCurve> curve; | |
36 switch (curve_type) { | |
37 case WebAnimationCurve::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 WebAnimationCurve::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 WebAnimationCurve::AnimationCurveTypeFilter: { | |
50 const WebFilterAnimationCurveImpl* filter_curve_impl = | |
51 static_cast<const WebFilterAnimationCurveImpl*>(&web_curve); | |
52 curve = filter_curve_impl->CloneToAnimationCurve(); | |
53 break; | |
54 } | |
55 #if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED | |
56 case WebAnimationCurve::AnimationCurveTypeScrollOffset: { | |
57 const WebScrollOffsetAnimationCurveImpl* scroll_curve_impl = | |
58 static_cast<const WebScrollOffsetAnimationCurveImpl*>(&web_curve); | |
59 curve = scroll_curve_impl->CloneToAnimationCurve(); | |
60 break; | |
61 } | |
62 #endif | |
63 } | |
64 animation_ = Animation::Create( | |
65 curve.Pass(), | |
66 animation_id, | |
67 group_id, | |
68 static_cast<cc::Animation::TargetProperty>(target_property)); | |
69 } | |
70 | |
71 WebAnimationImpl::~WebAnimationImpl() {} | |
72 | |
73 int WebAnimationImpl::id() { return animation_->id(); } | |
74 | |
75 blink::WebAnimation::TargetProperty WebAnimationImpl::targetProperty() const { | |
76 return static_cast<WebAnimationImpl::TargetProperty>( | |
77 animation_->target_property()); | |
78 } | |
79 | |
80 int WebAnimationImpl::iterations() const { return animation_->iterations(); } | |
81 | |
82 void WebAnimationImpl::setIterations(int n) { animation_->set_iterations(n); } | |
83 | |
84 double WebAnimationImpl::startTime() const { | |
85 return (animation_->start_time() - base::TimeTicks()).InSecondsF(); | |
86 } | |
87 | |
88 void WebAnimationImpl::setStartTime(double monotonic_time) { | |
89 animation_->set_start_time(base::TimeTicks::FromInternalValue( | |
90 monotonic_time * base::Time::kMicrosecondsPerSecond)); | |
91 } | |
92 | |
93 double WebAnimationImpl::timeOffset() const { | |
94 return animation_->time_offset().InSecondsF(); | |
95 } | |
96 | |
97 void WebAnimationImpl::setTimeOffset(double monotonic_time) { | |
98 animation_->set_time_offset(base::TimeDelta::FromSecondsD(monotonic_time)); | |
99 } | |
100 | |
101 #if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION | |
102 blink::WebAnimation::Direction WebAnimationImpl::direction() const { | |
103 switch (animation_->direction()) { | |
104 case cc::Animation::Normal: | |
105 return DirectionNormal; | |
106 case cc::Animation::Reverse: | |
107 return DirectionReverse; | |
108 case cc::Animation::Alternate: | |
109 return DirectionAlternate; | |
110 case cc::Animation::AlternateReverse: | |
111 return DirectionAlternateReverse; | |
112 default: | |
113 NOTREACHED(); | |
114 } | |
115 return DirectionNormal; | |
116 } | |
117 | |
118 void WebAnimationImpl::setDirection(Direction direction) { | |
119 switch (direction) { | |
120 case DirectionNormal: | |
121 animation_->set_direction(cc::Animation::Normal); | |
122 break; | |
123 case DirectionReverse: | |
124 animation_->set_direction(cc::Animation::Reverse); | |
125 break; | |
126 case DirectionAlternate: | |
127 animation_->set_direction(cc::Animation::Alternate); | |
128 break; | |
129 case DirectionAlternateReverse: | |
130 animation_->set_direction(cc::Animation::AlternateReverse); | |
131 break; | |
132 } | |
133 } | |
134 #else | |
135 bool WebAnimationImpl::alternatesDirection() const { | |
136 return animation_->direction() == cc::Animation::Alternate; | |
137 } | |
138 | |
139 void WebAnimationImpl::setAlternatesDirection(bool alternates) { | |
140 if (alternates) | |
141 animation_->set_direction(cc::Animation::Alternate); | |
142 else | |
143 animation_->set_direction(cc::Animation::Normal); | |
144 } | |
145 #endif | |
146 | |
147 scoped_ptr<cc::Animation> WebAnimationImpl::PassAnimation() { | |
148 animation_->set_needs_synchronized_start_time(true); | |
149 return animation_.Pass(); | |
150 } | |
151 | |
152 #define COMPILE_ASSERT_MATCHING_ENUMS(webkit_name, cc_name) \ | |
153 COMPILE_ASSERT(static_cast<int>(webkit_name) == static_cast<int>(cc_name), \ | |
154 mismatching_enums) | |
155 | |
156 COMPILE_ASSERT_MATCHING_ENUMS( | |
157 WebAnimation::TargetPropertyTransform, Animation::Transform); | |
158 COMPILE_ASSERT_MATCHING_ENUMS( | |
159 WebAnimation::TargetPropertyOpacity, Animation::Opacity); | |
160 COMPILE_ASSERT_MATCHING_ENUMS( | |
161 WebAnimation::TargetPropertyFilter, Animation::Filter); | |
162 #if WEB_SCROLL_OFFSET_ANIMATION_CURVE_IS_DEFINED | |
163 COMPILE_ASSERT_MATCHING_ENUMS( | |
164 WebAnimation::TargetPropertyScrollOffset, Animation::ScrollOffset); | |
165 #endif | |
166 | |
167 } // namespace webkit | |
OLD | NEW |