OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "public/platform/WebTransformOperations.h" | 49 #include "public/platform/WebTransformOperations.h" |
50 | 50 |
51 #include "wtf/OwnPtr.h" | 51 #include "wtf/OwnPtr.h" |
52 #include "wtf/text/CString.h" | 52 #include "wtf/text/CString.h" |
53 | 53 |
54 using namespace std; | 54 using namespace std; |
55 using namespace WebKit; | 55 using namespace WebKit; |
56 | 56 |
57 namespace WebCore { | 57 namespace WebCore { |
58 | 58 |
59 PassOwnPtr<WebTransformOperations> toWebTransformOperations(const TransformOpera
tions& transformOperations, const FloatSize& boxSize) | 59 PassOwnPtr<WebTransformOperations> toWebTransformOperations(const TransformOpera
tions& transformOperations, const FloatSize& boxSize, RenderView* renderView) |
60 { | 60 { |
61 // We need to do a deep copy the transformOperations may contain ref pointer
s to TransformOperation objects. | 61 // We need to do a deep copy the transformOperations may contain ref pointer
s to TransformOperation objects. |
62 OwnPtr<WebTransformOperations> webTransformOperations = adoptPtr(Platform::c
urrent()->compositorSupport()->createTransformOperations()); | 62 OwnPtr<WebTransformOperations> webTransformOperations = adoptPtr(Platform::c
urrent()->compositorSupport()->createTransformOperations()); |
63 if (!webTransformOperations) | 63 if (!webTransformOperations) |
64 return nullptr; | 64 return nullptr; |
65 for (size_t j = 0; j < transformOperations.size(); ++j) { | 65 for (size_t j = 0; j < transformOperations.size(); ++j) { |
66 TransformOperation::OperationType operationType = transformOperations.op
erations()[j]->getOperationType(); | 66 TransformOperation::OperationType operationType = transformOperations.op
erations()[j]->getOperationType(); |
67 switch (operationType) { | 67 switch (operationType) { |
68 case TransformOperation::ScaleX: | 68 case TransformOperation::ScaleX: |
69 case TransformOperation::ScaleY: | 69 case TransformOperation::ScaleY: |
70 case TransformOperation::ScaleZ: | 70 case TransformOperation::ScaleZ: |
71 case TransformOperation::Scale3D: | 71 case TransformOperation::Scale3D: |
72 case TransformOperation::Scale: { | 72 case TransformOperation::Scale: { |
73 ScaleTransformOperation* transform = static_cast<ScaleTransformOpera
tion*>(transformOperations.operations()[j].get()); | 73 ScaleTransformOperation* transform = static_cast<ScaleTransformOpera
tion*>(transformOperations.operations()[j].get()); |
74 webTransformOperations->appendScale(transform->x(), transform->y(),
transform->z()); | 74 webTransformOperations->appendScale(transform->x(), transform->y(),
transform->z()); |
75 break; | 75 break; |
76 } | 76 } |
77 case TransformOperation::TranslateX: | 77 case TransformOperation::TranslateX: |
78 case TransformOperation::TranslateY: | 78 case TransformOperation::TranslateY: |
79 case TransformOperation::TranslateZ: | 79 case TransformOperation::TranslateZ: |
80 case TransformOperation::Translate3D: | 80 case TransformOperation::Translate3D: |
81 case TransformOperation::Translate: { | 81 case TransformOperation::Translate: { |
82 TranslateTransformOperation* transform = static_cast<TranslateTransf
ormOperation*>(transformOperations.operations()[j].get()); | 82 TranslateTransformOperation* transform = static_cast<TranslateTransf
ormOperation*>(transformOperations.operations()[j].get()); |
83 webTransformOperations->appendTranslate(floatValueForLength(transfor
m->x(), boxSize.width()), floatValueForLength(transform->y(), boxSize.height()),
floatValueForLength(transform->z(), 1)); | 83 webTransformOperations->appendTranslate(floatValueForLength(transfor
m->x(), boxSize.width(), renderView), floatValueForLength(transform->y(), boxSiz
e.height(), renderView), floatValueForLength(transform->z(), 1, renderView)); |
84 break; | 84 break; |
85 } | 85 } |
86 case TransformOperation::RotateX: | 86 case TransformOperation::RotateX: |
87 case TransformOperation::RotateY: | 87 case TransformOperation::RotateY: |
88 case TransformOperation::Rotate3D: | 88 case TransformOperation::Rotate3D: |
89 case TransformOperation::Rotate: { | 89 case TransformOperation::Rotate: { |
90 RotateTransformOperation* transform = static_cast<RotateTransformOpe
ration*>(transformOperations.operations()[j].get()); | 90 RotateTransformOperation* transform = static_cast<RotateTransformOpe
ration*>(transformOperations.operations()[j].get()); |
91 webTransformOperations->appendRotate(transform->x(), transform->y(),
transform->z(), transform->angle()); | 91 webTransformOperations->appendRotate(transform->x(), transform->y(),
transform->z(), transform->angle()); |
92 break; | 92 break; |
93 } | 93 } |
(...skipping 16 matching lines...) Expand all Loading... |
110 webTransformOperations->appendMatrix(TransformSkMatrix44Conversions:
:convert(m)); | 110 webTransformOperations->appendMatrix(TransformSkMatrix44Conversions:
:convert(m)); |
111 break; | 111 break; |
112 } | 112 } |
113 case TransformOperation::Perspective: { | 113 case TransformOperation::Perspective: { |
114 PerspectiveTransformOperation* transform = static_cast<PerspectiveTr
ansformOperation*>(transformOperations.operations()[j].get()); | 114 PerspectiveTransformOperation* transform = static_cast<PerspectiveTr
ansformOperation*>(transformOperations.operations()[j].get()); |
115 webTransformOperations->appendPerspective(floatValueForLength(transf
orm->perspective(), 0)); | 115 webTransformOperations->appendPerspective(floatValueForLength(transf
orm->perspective(), 0)); |
116 break; | 116 break; |
117 } | 117 } |
118 case TransformOperation::Interpolated: { | 118 case TransformOperation::Interpolated: { |
119 TransformationMatrix m; | 119 TransformationMatrix m; |
120 transformOperations.operations()[j]->apply(m, boxSize); | 120 transformOperations.operations()[j]->apply(m, boxSize, renderView); |
121 webTransformOperations->appendMatrix(TransformSkMatrix44Conversions:
:convert(m)); | 121 webTransformOperations->appendMatrix(TransformSkMatrix44Conversions:
:convert(m)); |
122 break; | 122 break; |
123 } | 123 } |
124 case TransformOperation::Identity: | 124 case TransformOperation::Identity: |
125 webTransformOperations->appendIdentity(); | 125 webTransformOperations->appendIdentity(); |
126 break; | 126 break; |
127 case TransformOperation::None: | 127 case TransformOperation::None: |
128 // Do nothing. | 128 // Do nothing. |
129 break; | 129 break; |
130 } // switch | 130 } // switch |
131 } // for each operation | 131 } // for each operation |
132 | 132 |
133 return webTransformOperations.release(); | 133 return webTransformOperations.release(); |
134 } | 134 } |
135 | 135 |
136 template <class Value, class Keyframe, class Curve> | 136 template <class Value, class Keyframe, class Curve> |
137 bool appendKeyframeWithStandardTimingFunction(Curve* curve, double keyTime, cons
t Value* value, const Value* lastValue, WebKit::WebAnimationCurve::TimingFunctio
nType timingFunctionType, const FloatSize&) | 137 bool appendKeyframeWithStandardTimingFunction(Curve* curve, double keyTime, cons
t Value* value, const Value* lastValue, WebKit::WebAnimationCurve::TimingFunctio
nType timingFunctionType, const FloatSize&, RenderView* renderView) |
138 { | 138 { |
139 curve->add(Keyframe(keyTime, value->value()), timingFunctionType); | 139 curve->add(Keyframe(keyTime, value->value()), timingFunctionType); |
140 return true; | 140 return true; |
141 } | 141 } |
142 | 142 |
143 template <class Value, class Keyframe, class Curve> | 143 template <class Value, class Keyframe, class Curve> |
144 bool appendKeyframeWithCustomBezierTimingFunction(Curve* curve, double keyTime,
const Value* value, const Value* lastValue, double x1, double y1, double x2, dou
ble y2, const FloatSize&) | 144 bool appendKeyframeWithCustomBezierTimingFunction(Curve* curve, double keyTime,
const Value* value, const Value* lastValue, double x1, double y1, double x2, dou
ble y2, const FloatSize&, RenderView* renderView) |
145 { | 145 { |
146 curve->add(Keyframe(keyTime, value->value()), x1, y1, x2, y2); | 146 curve->add(Keyframe(keyTime, value->value()), x1, y1, x2, y2); |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 bool isRotationType(TransformOperation::OperationType transformType) | 150 bool isRotationType(TransformOperation::OperationType transformType) |
151 { | 151 { |
152 return transformType == TransformOperation::Rotate | 152 return transformType == TransformOperation::Rotate |
153 || transformType == TransformOperation::RotateX | 153 || transformType == TransformOperation::RotateX |
154 || transformType == TransformOperation::RotateY | 154 || transformType == TransformOperation::RotateY |
155 || transformType == TransformOperation::RotateZ | 155 || transformType == TransformOperation::RotateZ |
156 || transformType == TransformOperation::Rotate3D; | 156 || transformType == TransformOperation::Rotate3D; |
157 } | 157 } |
158 | 158 |
159 template <> | 159 template <> |
160 bool appendKeyframeWithStandardTimingFunction<TransformAnimationValue, WebTransf
ormKeyframe, WebTransformAnimationCurve>(WebTransformAnimationCurve* curve, doub
le keyTime, const TransformAnimationValue* value, const TransformAnimationValue*
lastValue, WebKit::WebAnimationCurve::TimingFunctionType timingFunctionType, co
nst FloatSize& boxSize) | 160 bool appendKeyframeWithStandardTimingFunction<TransformAnimationValue, WebTransf
ormKeyframe, WebTransformAnimationCurve>(WebTransformAnimationCurve* curve, doub
le keyTime, const TransformAnimationValue* value, const TransformAnimationValue*
lastValue, WebKit::WebAnimationCurve::TimingFunctionType timingFunctionType, co
nst FloatSize& boxSize, RenderView* renderView) |
161 { | 161 { |
162 bool canBlend = !lastValue; | 162 bool canBlend = !lastValue; |
163 OwnPtr<WebTransformOperations> operations(toWebTransformOperations(*value->v
alue(), boxSize)); | 163 OwnPtr<WebTransformOperations> operations(toWebTransformOperations(*value->v
alue(), boxSize, renderView)); |
164 if (!operations) | 164 if (!operations) |
165 return false; | 165 return false; |
166 if (!canBlend) { | 166 if (!canBlend) { |
167 OwnPtr<WebTransformOperations> lastOperations(toWebTransformOperations(*
lastValue->value(), boxSize)); | 167 OwnPtr<WebTransformOperations> lastOperations(toWebTransformOperations(*
lastValue->value(), boxSize, renderView)); |
168 if (!lastOperations) | 168 if (!lastOperations) |
169 return false; | 169 return false; |
170 canBlend = lastOperations->canBlendWith(*operations); | 170 canBlend = lastOperations->canBlendWith(*operations); |
171 } | 171 } |
172 if (canBlend) { | 172 if (canBlend) { |
173 curve->add(WebTransformKeyframe(keyTime, operations.leakPtr()), timingFu
nctionType); | 173 curve->add(WebTransformKeyframe(keyTime, operations.leakPtr()), timingFu
nctionType); |
174 return true; | 174 return true; |
175 } | 175 } |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 template <> | 179 template <> |
180 bool appendKeyframeWithCustomBezierTimingFunction<TransformAnimationValue, WebTr
ansformKeyframe, WebTransformAnimationCurve>(WebTransformAnimationCurve* curve,
double keyTime, const TransformAnimationValue* value, const TransformAnimationVa
lue* lastValue, double x1, double y1, double x2, double y2, const FloatSize& box
Size) | 180 bool appendKeyframeWithCustomBezierTimingFunction<TransformAnimationValue, WebTr
ansformKeyframe, WebTransformAnimationCurve>(WebTransformAnimationCurve* curve,
double keyTime, const TransformAnimationValue* value, const TransformAnimationVa
lue* lastValue, double x1, double y1, double x2, double y2, const FloatSize& box
Size, RenderView* renderView) |
181 { | 181 { |
182 bool canBlend = !lastValue; | 182 bool canBlend = !lastValue; |
183 OwnPtr<WebTransformOperations> operations(toWebTransformOperations(*value->v
alue(), boxSize)); | 183 OwnPtr<WebTransformOperations> operations(toWebTransformOperations(*value->v
alue(), boxSize, renderView)); |
184 if (!operations) | 184 if (!operations) |
185 return false; | 185 return false; |
186 if (!canBlend) { | 186 if (!canBlend) { |
187 OwnPtr<WebTransformOperations> lastOperations(toWebTransformOperations(*
lastValue->value(), boxSize)); | 187 OwnPtr<WebTransformOperations> lastOperations(toWebTransformOperations(*
lastValue->value(), boxSize, renderView)); |
188 if (!lastOperations) | 188 if (!lastOperations) |
189 return false; | 189 return false; |
190 canBlend = lastOperations->canBlendWith(*operations); | 190 canBlend = lastOperations->canBlendWith(*operations); |
191 } | 191 } |
192 if (canBlend) { | 192 if (canBlend) { |
193 curve->add(WebTransformKeyframe(keyTime, operations.leakPtr()), x1, y1,
x2, y2); | 193 curve->add(WebTransformKeyframe(keyTime, operations.leakPtr()), x1, y1,
x2, y2); |
194 return true; | 194 return true; |
195 } | 195 } |
196 return false; | 196 return false; |
197 } | 197 } |
198 | 198 |
199 template <class Value, class Keyframe, class Curve> | 199 template <class Value, class Keyframe, class Curve> |
200 PassOwnPtr<WebKit::WebAnimation> createWebAnimation(const KeyframeValueList& val
ueList, const CSSAnimationData* animation, int animationId, double timeOffset, C
urve* curve, WebKit::WebAnimation::TargetProperty targetProperty, const FloatSiz
e& boxSize) | 200 PassOwnPtr<WebKit::WebAnimation> createWebAnimation(const KeyframeValueList& val
ueList, const CSSAnimationData* animation, int animationId, double timeOffset, C
urve* curve, WebKit::WebAnimation::TargetProperty targetProperty, const FloatSiz
e& boxSize, RenderView* renderView) |
201 { | 201 { |
202 bool alternate = false; | 202 bool alternate = false; |
203 bool reverse = false; | 203 bool reverse = false; |
204 if (animation && animation->isDirectionSet()) { | 204 if (animation && animation->isDirectionSet()) { |
205 CSSAnimationData::AnimationDirection direction = animation->direction(); | 205 CSSAnimationData::AnimationDirection direction = animation->direction(); |
206 if (direction == CSSAnimationData::AnimationDirectionAlternate || direct
ion == CSSAnimationData::AnimationDirectionAlternateReverse) | 206 if (direction == CSSAnimationData::AnimationDirectionAlternate || direct
ion == CSSAnimationData::AnimationDirectionAlternateReverse) |
207 alternate = true; | 207 alternate = true; |
208 if (direction == CSSAnimationData::AnimationDirectionReverse || directio
n == CSSAnimationData::AnimationDirectionAlternateReverse) | 208 if (direction == CSSAnimationData::AnimationDirectionReverse || directio
n == CSSAnimationData::AnimationDirectionAlternateReverse) |
209 reverse = true; | 209 reverse = true; |
210 } | 210 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 | 253 |
254 double duration = (animation && animation->isDurationSet()) ? animation-
>duration() : 1; | 254 double duration = (animation && animation->isDurationSet()) ? animation-
>duration() : 1; |
255 double keyTime = originalValue->keyTime() * duration; | 255 double keyTime = originalValue->keyTime() * duration; |
256 | 256 |
257 if (reverse) | 257 if (reverse) |
258 keyTime = duration - keyTime; | 258 keyTime = duration - keyTime; |
259 | 259 |
260 bool addedKeyframe = false; | 260 bool addedKeyframe = false; |
261 if (isUsingCustomBezierTimingFunction) | 261 if (isUsingCustomBezierTimingFunction) |
262 addedKeyframe = appendKeyframeWithCustomBezierTimingFunction<Value,
Keyframe, Curve>(curve, keyTime, originalValue, lastOriginalValue, x1, y1, x2, y
2, boxSize); | 262 addedKeyframe = appendKeyframeWithCustomBezierTimingFunction<Value,
Keyframe, Curve>(curve, keyTime, originalValue, lastOriginalValue, x1, y1, x2, y
2, boxSize, renderView); |
263 else | 263 else |
264 addedKeyframe = appendKeyframeWithStandardTimingFunction<Value, Keyf
rame, Curve>(curve, keyTime, originalValue, lastOriginalValue, timingFunctionTyp
e, boxSize); | 264 addedKeyframe = appendKeyframeWithStandardTimingFunction<Value, Keyf
rame, Curve>(curve, keyTime, originalValue, lastOriginalValue, timingFunctionTyp
e, boxSize, renderView); |
265 if (!addedKeyframe) | 265 if (!addedKeyframe) |
266 return nullptr; | 266 return nullptr; |
267 } | 267 } |
268 | 268 |
269 OwnPtr<WebKit::WebAnimation> webAnimation = adoptPtr(Platform::current()->co
mpositorSupport()->createAnimation(*curve, targetProperty, animationId)); | 269 OwnPtr<WebKit::WebAnimation> webAnimation = adoptPtr(Platform::current()->co
mpositorSupport()->createAnimation(*curve, targetProperty, animationId)); |
270 | 270 |
271 int iterations = (animation && animation->isIterationCountSet()) ? animation
->iterationCount() : 1; | 271 int iterations = (animation && animation->isIterationCountSet()) ? animation
->iterationCount() : 1; |
272 webAnimation->setIterations(iterations); | 272 webAnimation->setIterations(iterations); |
273 webAnimation->setAlternatesDirection(alternate); | 273 webAnimation->setAlternatesDirection(alternate); |
274 | 274 |
275 // If timeOffset > 0, then the animation has started in the past. | 275 // If timeOffset > 0, then the animation has started in the past. |
276 webAnimation->setTimeOffset(timeOffset); | 276 webAnimation->setTimeOffset(timeOffset); |
277 | 277 |
278 return webAnimation.release(); | 278 return webAnimation.release(); |
279 } | 279 } |
280 | 280 |
281 PassOwnPtr<WebKit::WebAnimation> createWebAnimation(const KeyframeValueList& val
ues, const CSSAnimationData* animation, int animationId, double timeOffset, cons
t FloatSize& boxSize) | 281 PassOwnPtr<WebKit::WebAnimation> createWebAnimation(const KeyframeValueList& val
ues, const CSSAnimationData* animation, int animationId, double timeOffset, cons
t FloatSize& boxSize, RenderView* renderView) |
282 { | 282 { |
283 | 283 |
284 | 284 |
285 if (values.property() == AnimatedPropertyWebkitTransform) { | 285 if (values.property() == AnimatedPropertyWebkitTransform) { |
286 OwnPtr<WebTransformAnimationCurve> curve = adoptPtr(Platform::current()-
>compositorSupport()->createTransformAnimationCurve()); | 286 OwnPtr<WebTransformAnimationCurve> curve = adoptPtr(Platform::current()-
>compositorSupport()->createTransformAnimationCurve()); |
287 return createWebAnimation<TransformAnimationValue, WebTransformKeyframe,
WebTransformAnimationCurve>(values, animation, animationId, timeOffset, curve.g
et(), WebKit::WebAnimation::TargetPropertyTransform, FloatSize(boxSize)); | 287 return createWebAnimation<TransformAnimationValue, WebTransformKeyframe,
WebTransformAnimationCurve>(values, animation, animationId, timeOffset, curve.g
et(), WebKit::WebAnimation::TargetPropertyTransform, FloatSize(boxSize), renderV
iew); |
288 } | 288 } |
289 | 289 |
290 if (values.property() == AnimatedPropertyOpacity) { | 290 if (values.property() == AnimatedPropertyOpacity) { |
291 OwnPtr<WebFloatAnimationCurve> curve = adoptPtr(Platform::current()->com
positorSupport()->createFloatAnimationCurve()); | 291 OwnPtr<WebFloatAnimationCurve> curve = adoptPtr(Platform::current()->com
positorSupport()->createFloatAnimationCurve()); |
292 return createWebAnimation<FloatAnimationValue, WebFloatKeyframe, WebFloa
tAnimationCurve>(values, animation, animationId, timeOffset, curve.get(), WebKit
::WebAnimation::TargetPropertyOpacity, FloatSize()); | 292 return createWebAnimation<FloatAnimationValue, WebFloatKeyframe, WebFloa
tAnimationCurve>(values, animation, animationId, timeOffset, curve.get(), WebKit
::WebAnimation::TargetPropertyOpacity, FloatSize(), renderView); |
293 } | 293 } |
294 | 294 |
295 return nullptr; | 295 return nullptr; |
296 } | 296 } |
297 | 297 |
298 } // namespace WebCore | 298 } // namespace WebCore |
OLD | NEW |