2 * Copyright (C) 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "CSSPropertyAnimation.h"
33 #include "AnimationBase.h"
34 #include "CSSComputedStyleDeclaration.h"
35 #include "CSSCrossfadeValue.h"
36 #include "CSSFilterImageValue.h"
37 #include "CSSImageGeneratorValue.h"
38 #include "CSSImageValue.h"
39 #include "CSSPrimitiveValue.h"
40 #include "CSSPropertyNames.h"
41 #include "CachedImage.h"
42 #include "ClipPathOperation.h"
43 #include "FloatConversion.h"
44 #include "IdentityTransformOperation.h"
45 #include "Matrix3DTransformOperation.h"
46 #include "MatrixTransformOperation.h"
47 #include "RenderBox.h"
48 #include "RenderStyle.h"
49 #include "StyleCachedImage.h"
50 #include "StyleGeneratedImage.h"
51 #include "StylePropertyShorthand.h"
52 #include "StyleResolver.h"
54 #include <wtf/MathExtras.h>
55 #include <wtf/Noncopyable.h>
56 #include <wtf/RefCounted.h>
60 static inline int blendFunc(const AnimationBase*, int from, int to, double progress)
62 return blend(from, to, progress);
65 static inline unsigned blendFunc(const AnimationBase*, unsigned from, unsigned to, double progress)
67 return blend(from, to, progress);
70 static inline double blendFunc(const AnimationBase*, double from, double to, double progress)
72 return blend(from, to, progress);
75 static inline float blendFunc(const AnimationBase*, float from, float to, double progress)
77 return narrowPrecisionToFloat(from + (to - from) * progress);
80 static inline Color blendFunc(const AnimationBase*, const Color& from, const Color& to, double progress)
82 return blend(from, to, progress);
85 static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress)
87 return to.blend(from, narrowPrecisionToFloat(progress));
90 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress)
92 return LengthSize(blendFunc(anim, from.width(), to.width(), progress),
93 blendFunc(anim, from.height(), to.height(), progress));
96 static inline ShadowStyle blendFunc(const AnimationBase* anim, ShadowStyle from, ShadowStyle to, double progress)
101 double fromVal = from == Normal ? 1 : 0;
102 double toVal = to == Normal ? 1 : 0;
103 double result = blendFunc(anim, fromVal, toVal, progress);
104 return result > 0 ? Normal : Inset;
107 static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
110 if (from->style() != to->style())
111 return adoptPtr(new ShadowData(*to));
113 return adoptPtr(new ShadowData(blend(from->location(), to->location(), progress),
114 blend(from->radius(), to->radius(), progress),
115 blend(from->spread(), to->spread(), progress),
116 blendFunc(anim, from->style(), to->style(), progress),
117 from->isWebkitBoxShadow(),
118 blend(from->color(), to->color(), progress)));
121 static inline TransformOperations blendFunc(const AnimationBase* anim, const TransformOperations& from, const TransformOperations& to, double progress)
123 if (anim->isTransformFunctionListValid())
124 return to.blendByMatchingOperations(from, progress);
125 return to.blendByUsingMatrixInterpolation(from, progress, anim->renderer()->isBox() ? toRenderBox(anim->renderer())->borderBoxRect().size() : LayoutSize());
128 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, ClipPathOperation* from, ClipPathOperation* to, double progress)
133 // Other clip-path operations than BasicShapes can not be animated.
134 if (from->type() != ClipPathOperation::SHAPE || to->type() != ClipPathOperation::SHAPE)
137 const BasicShape* fromShape = static_cast<ShapeClipPathOperation*>(from)->basicShape();
138 const BasicShape* toShape = static_cast<ShapeClipPathOperation*>(to)->basicShape();
140 if (!fromShape->canBlend(toShape))
143 return ShapeClipPathOperation::create(toShape->blend(fromShape, progress));
146 #if ENABLE(CSS_SHAPES)
147 static inline PassRefPtr<ShapeValue> blendFunc(const AnimationBase*, ShapeValue* from, ShapeValue* to, double progress)
149 // FIXME Bug 102723: Shape-inside should be able to animate a value of 'outside-shape' when shape-outside is set to a BasicShape
150 if (from->type() != ShapeValue::Shape || to->type() != ShapeValue::Shape)
153 const BasicShape* fromShape = from->shape();
154 const BasicShape* toShape = to->shape();
156 if (!fromShape->canBlend(toShape))
159 return ShapeValue::createShapeValue(toShape->blend(fromShape, progress));
163 #if ENABLE(CSS_FILTERS)
164 static inline PassRefPtr<FilterOperation> blendFunc(const AnimationBase* anim, FilterOperation* fromOp, FilterOperation* toOp, double progress, bool blendToPassthrough = false)
167 if (toOp->blendingNeedsRendererSize()) {
168 LayoutSize size = anim->renderer()->isBox() ? toRenderBox(anim->renderer())->borderBoxRect().size() : LayoutSize();
169 return toOp->blend(fromOp, progress, size, blendToPassthrough);
171 return toOp->blend(fromOp, progress, blendToPassthrough);
174 static inline FilterOperations blendFilterOperations(const AnimationBase* anim, const FilterOperations& from, const FilterOperations& to, double progress)
176 FilterOperations result;
177 size_t fromSize = from.operations().size();
178 size_t toSize = to.operations().size();
179 size_t size = std::max(fromSize, toSize);
180 for (size_t i = 0; i < size; i++) {
181 RefPtr<FilterOperation> fromOp = (i < fromSize) ? from.operations()[i].get() : 0;
182 RefPtr<FilterOperation> toOp = (i < toSize) ? to.operations()[i].get() : 0;
183 RefPtr<FilterOperation> blendedOp = toOp ? blendFunc(anim, fromOp.get(), toOp.get(), progress) : (fromOp ? blendFunc(anim, 0, fromOp.get(), progress, true) : 0);
185 result.operations().append(blendedOp);
187 RefPtr<FilterOperation> identityOp = PassthroughFilterOperation::create();
189 result.operations().append(toOp ? toOp : identityOp);
191 result.operations().append(fromOp ? fromOp : identityOp);
197 static inline FilterOperations blendFunc(const AnimationBase* anim, const FilterOperations& from, const FilterOperations& to, double progress)
199 FilterOperations result;
201 // If we have a filter function list, use that to do a per-function animation.
202 if (anim->filterFunctionListsMatch())
203 result = blendFilterOperations(anim, from, to, progress);
205 // If the filter function lists don't match, we could try to cross-fade, but don't yet have a way to represent that in CSS.
206 // For now we'll just fail to animate.
213 static inline PassRefPtr<StyleImage> blendFilter(const AnimationBase* anim, CachedImage* image, const FilterOperations& from, const FilterOperations& to, double progress)
216 FilterOperations filterResult = blendFilterOperations(anim, from, to, progress);
218 RefPtr<StyleCachedImage> styledImage = StyleCachedImage::create(image);
219 auto imageValue = CSSImageValue::create(image->url(), styledImage.get());
220 RefPtr<CSSValue> filterValue = ComputedStyleExtractor::valueForFilter(anim->renderer(), &anim->renderer()->style(), filterResult, DoNotAdjustPixelValues);
221 RefPtr<CSSFilterImageValue> result = CSSFilterImageValue::create(std::move(imageValue), filterValue);
222 result->setFilterOperations(filterResult);
224 return StyleGeneratedImage::create(*result);
226 #endif // ENABLE(CSS_FILTERS)
228 static inline EVisibility blendFunc(const AnimationBase* anim, EVisibility from, EVisibility to, double progress)
230 // Any non-zero result means we consider the object to be visible. Only at 0 do we consider the object to be
231 // invisible. The invisible value we use (HIDDEN vs. COLLAPSE) depends on the specified from/to values.
232 double fromVal = from == VISIBLE ? 1. : 0.;
233 double toVal = to == VISIBLE ? 1. : 0.;
234 if (fromVal == toVal)
236 double result = blendFunc(anim, fromVal, toVal, progress);
237 return result > 0. ? VISIBLE : (to != VISIBLE ? to : from);
240 static inline LengthBox blendFunc(const AnimationBase* anim, const LengthBox& from, const LengthBox& to, double progress)
242 LengthBox result(blendFunc(anim, from.top(), to.top(), progress),
243 blendFunc(anim, from.right(), to.right(), progress),
244 blendFunc(anim, from.bottom(), to.bottom(), progress),
245 blendFunc(anim, from.left(), to.left(), progress));
250 static inline SVGLength blendFunc(const AnimationBase*, const SVGLength& from, const SVGLength& to, double progress)
252 return to.blend(from, narrowPrecisionToFloat(progress));
254 static inline Vector<SVGLength> blendFunc(const AnimationBase*, const Vector<SVGLength>& from, const Vector<SVGLength>& to, double progress)
256 size_t fromLength = from.size();
257 size_t toLength = to.size();
259 return !progress ? from : to;
261 return progress == 1 ? from : to;
262 size_t resultLength = fromLength;
263 if (fromLength != toLength) {
264 if (!remainder(std::max(fromLength, toLength), std::min(fromLength, toLength)))
265 resultLength = std::max(fromLength, toLength);
267 resultLength = fromLength * toLength;
269 Vector<SVGLength> result(resultLength);
270 for (size_t i = 0; i < resultLength; ++i)
271 result[i] = to[i % toLength].blend(from[i % fromLength], narrowPrecisionToFloat(progress));
276 static inline PassRefPtr<StyleImage> crossfadeBlend(const AnimationBase*, StyleCachedImage* fromStyleImage, StyleCachedImage* toStyleImage, double progress)
278 // If progress is at one of the extremes, we want getComputedStyle to show the image,
279 // not a completed cross-fade, so we hand back one of the existing images.
281 return fromStyleImage;
285 auto fromImageValue = CSSImageValue::create(fromStyleImage->cachedImage()->url(), fromStyleImage);
286 auto toImageValue = CSSImageValue::create(toStyleImage->cachedImage()->url(), toStyleImage);
287 RefPtr<CSSCrossfadeValue> crossfadeValue = CSSCrossfadeValue::create(std::move(fromImageValue), std::move(toImageValue));
289 crossfadeValue->setPercentage(CSSPrimitiveValue::create(progress, CSSPrimitiveValue::CSS_NUMBER));
291 return StyleGeneratedImage::create(*crossfadeValue);
294 static inline PassRefPtr<StyleImage> blendFunc(const AnimationBase* anim, StyleImage* from, StyleImage* to, double progress)
299 // Animation between two generated images. Cross fade for all other cases.
300 if (from->isGeneratedImage() && to->isGeneratedImage()) {
301 CSSImageGeneratorValue& fromGenerated = toStyleGeneratedImage(from)->imageValue();
302 CSSImageGeneratorValue& toGenerated = toStyleGeneratedImage(to)->imageValue();
304 #if ENABLE(CSS_FILTERS)
305 if (fromGenerated.isFilterImageValue() && toGenerated.isFilterImageValue()) {
306 // Animation of generated images just possible if input images are equal.
307 // Otherwise fall back to cross fade animation.
308 CSSFilterImageValue& fromFilter = toCSSFilterImageValue(fromGenerated);
309 CSSFilterImageValue& toFilter = toCSSFilterImageValue(toGenerated);
310 if (fromFilter.equalInputImages(toFilter) && fromFilter.cachedImage())
311 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), toFilter.filterOperations(), progress);
315 if (fromGenerated.isCrossfadeValue() && toGenerated.isCrossfadeValue()) {
316 CSSCrossfadeValue& fromCrossfade = toCSSCrossfadeValue(fromGenerated);
317 CSSCrossfadeValue& toCrossfade = toCSSCrossfadeValue(toGenerated);
318 if (fromCrossfade.equalInputImages(toCrossfade))
319 return StyleGeneratedImage::create(*toCrossfade.blend(fromCrossfade, progress));
322 // FIXME: Add support for animation between two *gradient() functions.
323 // https://bugs.webkit.org/show_bug.cgi?id=119956
324 #if ENABLE(CSS_FILTERS)
325 } else if (from->isGeneratedImage() && to->isCachedImage()) {
326 CSSImageGeneratorValue& fromGenerated = toStyleGeneratedImage(from)->imageValue();
327 if (fromGenerated.isFilterImageValue()) {
328 CSSFilterImageValue& fromFilter = toCSSFilterImageValue(fromGenerated);
329 if (fromFilter.cachedImage() && static_cast<StyleCachedImage*>(to)->cachedImage() == fromFilter.cachedImage())
330 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), FilterOperations(), progress);
332 // FIXME: Add interpolation between cross-fade and image source.
333 } else if (from->isCachedImage() && to->isGeneratedImage()) {
334 CSSImageGeneratorValue& toGenerated = toStyleGeneratedImage(to)->imageValue();
335 if (toGenerated.isFilterImageValue()) {
336 CSSFilterImageValue& toFilter = toCSSFilterImageValue(toGenerated);
337 if (toFilter.cachedImage() && static_cast<StyleCachedImage*>(from)->cachedImage() == toFilter.cachedImage())
338 return blendFilter(anim, toFilter.cachedImage(), FilterOperations(), toFilter.filterOperations(), progress);
341 // FIXME: Add interpolation between image source and cross-fade.
344 // FIXME: Add support cross fade between cached and generated images.
345 // https://bugs.webkit.org/show_bug.cgi?id=78293
346 if (from->isCachedImage() && to->isCachedImage())
347 return crossfadeBlend(anim, static_cast<StyleCachedImage*>(from), static_cast<StyleCachedImage*>(to), progress);
352 static inline NinePieceImage blendFunc(const AnimationBase* anim, const NinePieceImage& from, const NinePieceImage& to, double progress)
354 if (!from.hasImage() || !to.hasImage())
357 // FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content.
359 if (from.imageSlices() != to.imageSlices() || from.borderSlices() != to.borderSlices() || from.outset() != to.outset() || from.fill() != to.fill() || from.horizontalRule() != to.horizontalRule() || from.verticalRule() != to.verticalRule())
362 if (from.image()->imageSize(anim->renderer(), 1.0) != to.image()->imageSize(anim->renderer(), 1.0))
365 RefPtr<StyleImage> newContentImage = blendFunc(anim, from.image(), to.image(), progress);
367 return NinePieceImage(newContentImage, from.imageSlices(), from.fill(), from.borderSlices(), from.outset(), from.horizontalRule(), from.verticalRule());
370 class AnimationPropertyWrapperBase {
371 WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase);
372 WTF_MAKE_FAST_ALLOCATED;
374 AnimationPropertyWrapperBase(CSSPropertyID prop)
379 virtual ~AnimationPropertyWrapperBase() { }
381 virtual bool isShorthandWrapper() const { return false; }
382 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const = 0;
383 virtual void blend(const AnimationBase*, RenderStyle*, const RenderStyle*, const RenderStyle*, double) const = 0;
385 CSSPropertyID property() const { return m_prop; }
387 #if USE(ACCELERATED_COMPOSITING)
388 virtual bool animationIsAccelerated() const { return false; }
392 CSSPropertyID m_prop;
395 template <typename T>
396 class PropertyWrapperGetter : public AnimationPropertyWrapperBase {
398 PropertyWrapperGetter(CSSPropertyID prop, T (RenderStyle::*getter)() const)
399 : AnimationPropertyWrapperBase(prop)
404 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
406 // If the style pointers are the same, don't bother doing the test.
407 // If either is null, return false. If both are null, return true.
408 if ((!a && !b) || a == b)
412 return (a->*m_getter)() == (b->*m_getter)();
416 T (RenderStyle::*m_getter)() const;
419 template <typename T>
420 class PropertyWrapper : public PropertyWrapperGetter<T> {
422 PropertyWrapper(CSSPropertyID prop, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
423 : PropertyWrapperGetter<T>(prop, getter)
428 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
430 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T>::m_getter)(), (b->*PropertyWrapperGetter<T>::m_getter)(), progress));
434 void (RenderStyle::*m_setter)(T);
437 template <typename T>
438 class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> {
440 RefCountedPropertyWrapper(CSSPropertyID prop, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<T>))
441 : PropertyWrapperGetter<T*>(prop, getter)
446 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
448 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T*>::m_getter)(), (b->*PropertyWrapperGetter<T*>::m_getter)(), progress));
452 void (RenderStyle::*m_setter)(PassRefPtr<T>);
455 template <typename T>
456 class LengthPropertyWrapper : public PropertyWrapperGetter<const T&> {
458 LengthPropertyWrapper(CSSPropertyID prop, const T& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
459 : PropertyWrapperGetter<const T&>(prop, getter)
464 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
466 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<const T&>::m_getter)(), (b->*PropertyWrapperGetter<const T&>::m_getter)(), progress));
470 void (RenderStyle::*m_setter)(T);
473 class PropertyWrapperClipPath : public RefCountedPropertyWrapper<ClipPathOperation> {
475 PropertyWrapperClipPath(CSSPropertyID prop, ClipPathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ClipPathOperation>))
476 : RefCountedPropertyWrapper<ClipPathOperation>(prop, getter, setter)
481 #if ENABLE(CSS_SHAPES)
482 class PropertyWrapperShape : public RefCountedPropertyWrapper<ShapeValue> {
484 PropertyWrapperShape(CSSPropertyID prop, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ShapeValue>))
485 : RefCountedPropertyWrapper<ShapeValue>(prop, getter, setter)
491 class StyleImagePropertyWrapper : public RefCountedPropertyWrapper<StyleImage> {
493 StyleImagePropertyWrapper(CSSPropertyID prop, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<StyleImage>))
494 : RefCountedPropertyWrapper<StyleImage>(prop, getter, setter)
498 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
500 // If the style pointers are the same, don't bother doing the test.
501 // If either is null, return false. If both are null, return true.
507 StyleImage* imageA = (a->*m_getter)();
508 StyleImage* imageB = (b->*m_getter)();
509 return StyleImage::imagesEquivalent(imageA, imageB);
513 class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
515 PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
516 : PropertyWrapperGetter<Color>(prop, getter)
521 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
523 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_getter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
527 void (RenderStyle::*m_setter)(const Color&);
531 #if USE(ACCELERATED_COMPOSITING)
532 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
534 PropertyWrapperAcceleratedOpacity()
535 : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)
539 virtual bool animationIsAccelerated() const { return true; }
541 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
543 float fromOpacity = a->opacity();
545 // This makes sure we put the object being animated into a RenderLayer during the animation
546 dst->setOpacity(blendFunc(anim, (fromOpacity == 1) ? 0.999999f : fromOpacity, b->opacity(), progress));
550 class PropertyWrapperAcceleratedTransform : public PropertyWrapper<const TransformOperations&> {
552 PropertyWrapperAcceleratedTransform()
553 : PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform)
557 virtual bool animationIsAccelerated() const { return true; }
559 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
561 dst->setTransform(blendFunc(anim, a->transform(), b->transform(), progress));
565 #if ENABLE(CSS_FILTERS)
566 class PropertyWrapperAcceleratedFilter : public PropertyWrapper<const FilterOperations&> {
568 PropertyWrapperAcceleratedFilter()
569 : PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter)
573 virtual bool animationIsAccelerated() const { return true; }
575 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
577 dst->setFilter(blendFunc(anim, a->filter(), b->filter(), progress));
581 #endif // USE(ACCELERATED_COMPOSITING)
583 static inline size_t shadowListLength(const ShadowData* shadow)
586 for (count = 0; shadow; shadow = shadow->next())
591 static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow)
593 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (IntPoint(), 0, 0, Normal, false, Color::transparent));
594 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (IntPoint(), 0, 0, Inset, false, Color::transparent));
596 DEFINE_STATIC_LOCAL(ShadowData, defaultWebKitBoxShadowData, (IntPoint(), 0, 0, Normal, true, Color::transparent));
597 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetWebKitBoxShadowData, (IntPoint(), 0, 0, Inset, true, Color::transparent));
602 if (otherShadow->style() == Inset)
603 return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData : &defaultInsetShadowData;
605 return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData : &defaultShadowData;
608 class PropertyWrapperShadow : public AnimationPropertyWrapperBase {
610 PropertyWrapperShadow(CSSPropertyID prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassOwnPtr<ShadowData>, bool))
611 : AnimationPropertyWrapperBase(prop)
617 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
619 const ShadowData* shadowA = (a->*m_getter)();
620 const ShadowData* shadowB = (b->*m_getter)();
624 if (!shadowA && !shadowB)
627 // end of just one of the lists
628 if (!shadowA || !shadowB)
631 if (*shadowA != *shadowB)
634 shadowA = shadowA->next();
635 shadowB = shadowB->next();
641 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
643 const ShadowData* shadowA = (a->*m_getter)();
644 const ShadowData* shadowB = (b->*m_getter)();
646 int fromLength = shadowListLength(shadowA);
647 int toLength = shadowListLength(shadowB);
649 if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) {
650 (dst->*m_setter)(blendSimpleOrMatchedShadowLists(anim, progress, shadowA, shadowB), false);
654 (dst->*m_setter)(blendMismatchedShadowLists(anim, progress, shadowA, shadowB, fromLength, toLength), false);
658 PassOwnPtr<ShadowData> blendSimpleOrMatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB) const
660 OwnPtr<ShadowData> newShadowData;
661 ShadowData* lastShadow = 0;
663 while (shadowA || shadowB) {
664 const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB);
665 const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA);
667 OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
668 ShadowData* blendedShadowPtr = blendedShadow.get();
671 newShadowData = blendedShadow.release();
673 lastShadow->setNext(blendedShadow.release());
675 lastShadow = blendedShadowPtr;
677 shadowA = shadowA ? shadowA->next() : 0;
678 shadowB = shadowB ? shadowB->next() : 0;
681 return newShadowData.release();
684 PassOwnPtr<ShadowData> blendMismatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength) const
686 // The shadows in ShadowData are stored in reverse order, so when animating mismatched lists,
687 // reverse them and match from the end.
688 Vector<const ShadowData*, 4> fromShadows(fromLength);
689 for (int i = fromLength - 1; i >= 0; --i) {
690 fromShadows[i] = shadowA;
691 shadowA = shadowA->next();
694 Vector<const ShadowData*, 4> toShadows(toLength);
695 for (int i = toLength - 1; i >= 0; --i) {
696 toShadows[i] = shadowB;
697 shadowB = shadowB->next();
700 OwnPtr<ShadowData> newShadowData;
702 int maxLength = std::max(fromLength, toLength);
703 for (int i = 0; i < maxLength; ++i) {
704 const ShadowData* fromShadow = i < fromLength ? fromShadows[i] : 0;
705 const ShadowData* toShadow = i < toLength ? toShadows[i] : 0;
707 const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow);
708 const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow);
710 OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
711 // Insert at the start of the list to preserve the order.
712 blendedShadow->setNext(newShadowData.release());
713 newShadowData = blendedShadow.release();
716 return newShadowData.release();
719 const ShadowData* (RenderStyle::*m_getter)() const;
720 void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
723 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
725 PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
726 : AnimationPropertyWrapperBase(prop)
732 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
734 Color fromColor = (a->*m_getter)();
735 Color toColor = (b->*m_getter)();
737 if (!fromColor.isValid() && !toColor.isValid())
740 if (!fromColor.isValid())
741 fromColor = a->color();
742 if (!toColor.isValid())
743 toColor = b->color();
745 return fromColor == toColor;
748 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
750 Color fromColor = (a->*m_getter)();
751 Color toColor = (b->*m_getter)();
753 if (!fromColor.isValid() && !toColor.isValid())
756 if (!fromColor.isValid())
757 fromColor = a->color();
758 if (!toColor.isValid())
759 toColor = b->color();
760 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
764 Color (RenderStyle::*m_getter)() const;
765 void (RenderStyle::*m_setter)(const Color&);
769 enum MaybeInvalidColorTag { MaybeInvalidColor };
770 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
772 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
773 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
774 : AnimationPropertyWrapperBase(prop)
775 , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter)))
776 , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter, visitedSetter)))
779 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
780 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
781 : AnimationPropertyWrapperBase(prop)
782 , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter)))
783 , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, visitedGetter, visitedSetter)))
786 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
788 return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
790 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
792 m_wrapper->blend(anim, dst, a, b, progress);
793 m_visitedWrapper->blend(anim, dst, a, b, progress);
797 OwnPtr<AnimationPropertyWrapperBase> m_wrapper;
798 OwnPtr<AnimationPropertyWrapperBase> m_visitedWrapper;
801 // Wrapper base class for an animatable property in a FillLayer
802 class FillLayerAnimationPropertyWrapperBase {
804 FillLayerAnimationPropertyWrapperBase()
808 virtual ~FillLayerAnimationPropertyWrapperBase() { }
810 virtual bool equals(const FillLayer*, const FillLayer*) const = 0;
811 virtual void blend(const AnimationBase*, FillLayer*, const FillLayer*, const FillLayer*, double) const = 0;
814 template <typename T>
815 class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase {
816 WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter);
818 FillLayerPropertyWrapperGetter(T (FillLayer::*getter)() const)
823 virtual bool equals(const FillLayer* a, const FillLayer* b) const
825 // If the style pointers are the same, don't bother doing the test.
826 // If either is null, return false. If both are null, return true.
827 if ((!a && !b) || a == b)
831 return (a->*m_getter)() == (b->*m_getter)();
835 T (FillLayer::*m_getter)() const;
838 template <typename T>
839 class FillLayerPropertyWrapper : public FillLayerPropertyWrapperGetter<const T&> {
841 FillLayerPropertyWrapper(const T& (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
842 : FillLayerPropertyWrapperGetter<const T&>(getter)
847 virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
849 (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), progress));
853 void (FillLayer::*m_setter)(T);
856 template <typename T>
857 class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> {
859 FillLayerRefCountedPropertyWrapper(T* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<T>))
860 : FillLayerPropertyWrapperGetter<T*>(getter)
865 virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
867 (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), progress));
871 void (FillLayer::*m_setter)(PassRefPtr<T>);
874 class FillLayerStyleImagePropertyWrapper : public FillLayerRefCountedPropertyWrapper<StyleImage> {
876 FillLayerStyleImagePropertyWrapper(StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<StyleImage>))
877 : FillLayerRefCountedPropertyWrapper<StyleImage>(getter, setter)
881 virtual bool equals(const FillLayer* a, const FillLayer* b) const
883 // If the style pointers are the same, don't bother doing the test.
884 // If either is null, return false. If both are null, return true.
890 StyleImage* imageA = (a->*m_getter)();
891 StyleImage* imageB = (b->*m_getter)();
892 return StyleImage::imagesEquivalent(imageA, imageB);
896 class FillLayersPropertyWrapper : public AnimationPropertyWrapperBase {
898 typedef const FillLayer* (RenderStyle::*LayersGetter)() const;
899 typedef FillLayer* (RenderStyle::*LayersAccessor)();
901 FillLayersPropertyWrapper(CSSPropertyID prop, LayersGetter getter, LayersAccessor accessor)
902 : AnimationPropertyWrapperBase(prop)
903 , m_layersGetter(getter)
904 , m_layersAccessor(accessor)
907 case CSSPropertyBackgroundPositionX:
908 case CSSPropertyWebkitMaskPositionX:
909 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::xPosition, &FillLayer::setXPosition);
911 case CSSPropertyBackgroundPositionY:
912 case CSSPropertyWebkitMaskPositionY:
913 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::yPosition, &FillLayer::setYPosition);
915 case CSSPropertyBackgroundSize:
916 case CSSPropertyWebkitBackgroundSize:
917 case CSSPropertyWebkitMaskSize:
918 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<LengthSize>(&FillLayer::sizeLength, &FillLayer::setSizeLength);
920 case CSSPropertyBackgroundImage:
921 m_fillLayerPropertyWrapper = new FillLayerStyleImagePropertyWrapper(&FillLayer::image, &FillLayer::setImage);
928 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
930 const FillLayer* fromLayer = (a->*m_layersGetter)();
931 const FillLayer* toLayer = (b->*m_layersGetter)();
933 while (fromLayer && toLayer) {
934 if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer))
937 fromLayer = fromLayer->next();
938 toLayer = toLayer->next();
944 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
946 const FillLayer* aLayer = (a->*m_layersGetter)();
947 const FillLayer* bLayer = (b->*m_layersGetter)();
948 FillLayer* dstLayer = (dst->*m_layersAccessor)();
950 while (aLayer && bLayer && dstLayer) {
951 m_fillLayerPropertyWrapper->blend(anim, dstLayer, aLayer, bLayer, progress);
952 aLayer = aLayer->next();
953 bLayer = bLayer->next();
954 dstLayer = dstLayer->next();
959 FillLayerAnimationPropertyWrapperBase* m_fillLayerPropertyWrapper;
961 LayersGetter m_layersGetter;
962 LayersAccessor m_layersAccessor;
965 class ShorthandPropertyWrapper : public AnimationPropertyWrapperBase {
967 ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers)
968 : AnimationPropertyWrapperBase(property)
970 m_propertyWrappers.swap(longhandWrappers);
973 virtual bool isShorthandWrapper() const { return true; }
975 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
977 Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
978 for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it) {
979 if (!(*it)->equals(a, b))
985 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
987 Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
988 for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it)
989 (*it)->blend(anim, dst, a, b, progress);
992 const Vector<AnimationPropertyWrapperBase*> propertyWrappers() const { return m_propertyWrappers; }
995 Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
998 class PropertyWrapperFlex : public AnimationPropertyWrapperBase {
1000 PropertyWrapperFlex() : AnimationPropertyWrapperBase(CSSPropertyWebkitFlex)
1004 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1006 // If the style pointers are the same, don't bother doing the test.
1007 // If either is null, return false. If both are null, return true.
1008 if ((!a && !b) || a == b)
1013 return a->flexBasis() == b->flexBasis() && a->flexGrow() == b->flexGrow() && a->flexShrink() == b->flexShrink();
1016 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1018 dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progress));
1019 dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress));
1020 dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), progress));
1025 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
1027 PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (RenderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
1028 : AnimationPropertyWrapperBase(prop)
1029 , m_paintTypeGetter(paintTypeGetter)
1035 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1037 if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
1040 // We only support animations between SVGPaints that are pure Color values.
1041 // For everything else we must return true for this method, otherwise
1042 // we will try to animate between values forever.
1043 if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) {
1044 Color fromColor = (a->*m_getter)();
1045 Color toColor = (b->*m_getter)();
1047 if (!fromColor.isValid() && !toColor.isValid())
1050 if (!fromColor.isValid())
1051 fromColor = Color();
1052 if (!toColor.isValid())
1055 return fromColor == toColor;
1060 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1062 if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
1063 || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
1066 Color fromColor = (a->*m_getter)();
1067 Color toColor = (b->*m_getter)();
1069 if (!fromColor.isValid() && !toColor.isValid())
1072 if (!fromColor.isValid())
1073 fromColor = Color();
1074 if (!toColor.isValid())
1076 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
1080 const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
1081 Color (RenderStyle::*m_getter)() const;
1082 void (RenderStyle::*m_setter)(const Color&);
1086 class CSSPropertyAnimationWrapperMap {
1088 static CSSPropertyAnimationWrapperMap& instance()
1090 // FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last AnimationController is destroyed?
1091 DEFINE_STATIC_LOCAL(OwnPtr<CSSPropertyAnimationWrapperMap>, map, ());
1093 map = adoptPtr(new CSSPropertyAnimationWrapperMap);
1097 AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID)
1099 if (propertyID < firstCSSProperty || propertyID > lastCSSProperty)
1102 unsigned wrapperIndex = indexFromPropertyID(propertyID);
1103 if (wrapperIndex == cInvalidPropertyWrapperIndex)
1106 return m_propertyWrappers[wrapperIndex].get();
1109 AnimationPropertyWrapperBase* wrapperForIndex(unsigned index)
1111 ASSERT(index < m_propertyWrappers.size());
1112 return m_propertyWrappers[index].get();
1117 return m_propertyWrappers.size();
1121 CSSPropertyAnimationWrapperMap();
1122 unsigned char& indexFromPropertyID(CSSPropertyID propertyID)
1124 return m_propertyToIdMap[propertyID - firstCSSProperty];
1127 Vector<OwnPtr<AnimationPropertyWrapperBase>> m_propertyWrappers;
1128 unsigned char m_propertyToIdMap[numCSSProperties];
1130 static const unsigned char cInvalidPropertyWrapperIndex = UCHAR_MAX;
1133 CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap()
1135 // build the list of property wrappers to do the comparisons and blends
1136 AnimationPropertyWrapperBase* animatableLonghandPropertyWrappers[] = {
1137 new LengthPropertyWrapper<Length>(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft),
1138 new LengthPropertyWrapper<Length>(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight),
1139 new LengthPropertyWrapper<Length>(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop),
1140 new LengthPropertyWrapper<Length>(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom),
1142 new LengthPropertyWrapper<Length>(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth),
1143 new LengthPropertyWrapper<Length>(CSSPropertyMinWidth, &RenderStyle::minWidth, &RenderStyle::setMinWidth),
1144 new LengthPropertyWrapper<Length>(CSSPropertyMaxWidth, &RenderStyle::maxWidth, &RenderStyle::setMaxWidth),
1146 new LengthPropertyWrapper<Length>(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight),
1147 new LengthPropertyWrapper<Length>(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight),
1148 new LengthPropertyWrapper<Length>(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight),
1150 new PropertyWrapperFlex(),
1152 new PropertyWrapper<unsigned>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth),
1153 new PropertyWrapper<unsigned>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth),
1154 new PropertyWrapper<unsigned>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth),
1155 new PropertyWrapper<unsigned>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth),
1156 new LengthPropertyWrapper<Length>(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft),
1157 new LengthPropertyWrapper<Length>(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight),
1158 new LengthPropertyWrapper<Length>(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop),
1159 new LengthPropertyWrapper<Length>(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom),
1160 new LengthPropertyWrapper<Length>(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft),
1161 new LengthPropertyWrapper<Length>(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight),
1162 new LengthPropertyWrapper<Length>(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop),
1163 new LengthPropertyWrapper<Length>(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom),
1164 new PropertyWrapperVisitedAffectedColor(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::visitedLinkColor, &RenderStyle::setVisitedLinkColor),
1166 new PropertyWrapperVisitedAffectedColor(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor),
1168 new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1169 new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage),
1170 new StyleImagePropertyWrapper(CSSPropertyWebkitMaskImage, &RenderStyle::maskImage, &RenderStyle::setMaskImage),
1172 new StyleImagePropertyWrapper(CSSPropertyBorderImageSource, &RenderStyle::borderImageSource, &RenderStyle::setBorderImageSource),
1173 new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageSlice, &RenderStyle::borderImageSlices, &RenderStyle::setBorderImageSlices),
1174 new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageWidth, &RenderStyle::borderImageWidth, &RenderStyle::setBorderImageWidth),
1175 new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageOutset, &RenderStyle::borderImageOutset, &RenderStyle::setBorderImageOutset),
1177 new StyleImagePropertyWrapper(CSSPropertyWebkitMaskBoxImageSource, &RenderStyle::maskBoxImageSource, &RenderStyle::setMaskBoxImageSource),
1178 new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage),
1180 new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionX, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1181 new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionY, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1182 new FillLayersPropertyWrapper(CSSPropertyBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1183 new FillLayersPropertyWrapper(CSSPropertyWebkitBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1185 new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1186 new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1187 new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1189 new PropertyWrapper<float>(CSSPropertyFontSize,
1190 // Must pass a specified size to setFontSize if Text Autosizing is enabled, but a computed size
1191 // if text zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1192 // FIXME: Find some way to assert that text zoom isn't activated when Text Autosizing is compiled in.
1193 #if ENABLE(TEXT_AUTOSIZING)
1194 &RenderStyle::specifiedFontSize,
1196 &RenderStyle::computedFontSize,
1198 &RenderStyle::setFontSize),
1199 new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth),
1200 new PropertyWrapper<float>(CSSPropertyWebkitColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap),
1201 new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount),
1202 new PropertyWrapper<float>(CSSPropertyWebkitColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth),
1203 new PropertyWrapper<short>(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing),
1204 new PropertyWrapper<short>(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing),
1205 new PropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::zIndex, &RenderStyle::setZIndex),
1206 new PropertyWrapper<short>(CSSPropertyOrphans, &RenderStyle::orphans, &RenderStyle::setOrphans),
1207 new PropertyWrapper<short>(CSSPropertyWidows, &RenderStyle::widows, &RenderStyle::setWidows),
1208 new LengthPropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight),
1209 new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset),
1210 new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth),
1211 new PropertyWrapper<int>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing),
1212 new PropertyWrapper<int>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing),
1213 new LengthPropertyWrapper<Length>(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent),
1215 new PropertyWrapper<float>(CSSPropertyWebkitPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective),
1216 new LengthPropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX),
1217 new LengthPropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY),
1218 new LengthPropertyWrapper<Length>(CSSPropertyWebkitTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX),
1219 new LengthPropertyWrapper<Length>(CSSPropertyWebkitTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY),
1220 new PropertyWrapper<float>(CSSPropertyWebkitTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ),
1221 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius),
1222 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius),
1223 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius),
1224 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius),
1225 new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility),
1226 new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoomWithoutReturnValue),
1228 new LengthPropertyWrapper<LengthBox>(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip),
1230 #if USE(ACCELERATED_COMPOSITING)
1231 new PropertyWrapperAcceleratedOpacity(),
1232 new PropertyWrapperAcceleratedTransform(),
1233 #if ENABLE(CSS_FILTERS)
1234 new PropertyWrapperAcceleratedFilter(),
1237 new PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity),
1238 new PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform),
1239 #if ENABLE(CSS_FILTERS)
1240 new PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter),
1244 new PropertyWrapperClipPath(CSSPropertyWebkitClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath),
1246 #if ENABLE(CSS_SHAPES)
1247 new PropertyWrapperShape(CSSPropertyWebkitShapeInside, &RenderStyle::shapeInside, &RenderStyle::setShapeInside),
1248 new PropertyWrapperShape(CSSPropertyWebkitShapeOutside, &RenderStyle::shapeOutside, &RenderStyle::setShapeOutside),
1249 new LengthPropertyWrapper<Length>(CSSPropertyWebkitShapeMargin, &RenderStyle::shapeMargin, &RenderStyle::setShapeMargin),
1250 new PropertyWrapper<float>(CSSPropertyWebkitShapeImageThreshold, &RenderStyle::shapeImageThreshold, &RenderStyle::setShapeImageThreshold),
1253 new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitColumnRuleColor, MaybeInvalidColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor, &RenderStyle::visitedLinkColumnRuleColor, &RenderStyle::setVisitedLinkColumnRuleColor),
1254 new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextStrokeColor, MaybeInvalidColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor, &RenderStyle::visitedLinkTextStrokeColor, &RenderStyle::setVisitedLinkTextStrokeColor),
1255 new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextFillColor, MaybeInvalidColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor, &RenderStyle::visitedLinkTextFillColor, &RenderStyle::setVisitedLinkTextFillColor),
1256 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderLeftColor, MaybeInvalidColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor, &RenderStyle::visitedLinkBorderLeftColor, &RenderStyle::setVisitedLinkBorderLeftColor),
1257 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderRightColor, MaybeInvalidColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor, &RenderStyle::visitedLinkBorderRightColor, &RenderStyle::setVisitedLinkBorderRightColor),
1258 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderTopColor, MaybeInvalidColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor, &RenderStyle::visitedLinkBorderTopColor, &RenderStyle::setVisitedLinkBorderTopColor),
1259 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderBottomColor, MaybeInvalidColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor, &RenderStyle::visitedLinkBorderBottomColor, &RenderStyle::setVisitedLinkBorderBottomColor),
1260 new PropertyWrapperVisitedAffectedColor(CSSPropertyOutlineColor, MaybeInvalidColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::visitedLinkOutlineColor, &RenderStyle::setVisitedLinkOutlineColor),
1262 new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1263 new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1264 new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow),
1267 new PropertyWrapperSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor),
1268 new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity),
1270 new PropertyWrapperSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor),
1271 new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity),
1272 new PropertyWrapper<SVGLength>(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth),
1273 new PropertyWrapper< Vector<SVGLength>>(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray),
1274 new PropertyWrapper<SVGLength>(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset),
1275 new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit),
1277 new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity),
1278 new PropertyWrapperMaybeInvalidColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor),
1280 new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity),
1281 new PropertyWrapperMaybeInvalidColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor),
1283 new PropertyWrapperMaybeInvalidColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor),
1285 new PropertyWrapper<SVGLength>(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue),
1286 new PropertyWrapper<SVGLength>(CSSPropertyKerning, &RenderStyle::kerning, &RenderStyle::setKerning),
1289 const unsigned animatableLonghandPropertiesCount = WTF_ARRAY_LENGTH(animatableLonghandPropertyWrappers);
1291 static const CSSPropertyID animatableShorthandProperties[] = {
1292 CSSPropertyBackground, // for background-color, background-position, background-image
1293 CSSPropertyBackgroundPosition,
1294 CSSPropertyFont, // for font-size, font-weight
1295 CSSPropertyWebkitMask, // for mask-position
1296 CSSPropertyWebkitMaskPosition,
1297 CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft,
1298 CSSPropertyBorderColor,
1299 CSSPropertyBorderRadius,
1300 CSSPropertyBorderWidth,
1302 CSSPropertyBorderImage,
1303 CSSPropertyBorderSpacing,
1304 CSSPropertyListStyle, // for list-style-image
1308 CSSPropertyWebkitTextStroke,
1309 CSSPropertyWebkitColumnRule,
1310 CSSPropertyWebkitBorderRadius,
1311 CSSPropertyWebkitTransformOrigin
1313 const unsigned animatableShorthandPropertiesCount = WTF_ARRAY_LENGTH(animatableShorthandProperties);
1317 // CSSPropertyVerticalAlign
1319 // Compound properties that have components that should be animatable:
1321 // CSSPropertyWebkitColumns
1322 // CSSPropertyWebkitBoxReflect
1324 // Make sure unused slots have a value
1325 for (int i = 0; i < numCSSProperties; ++i)
1326 m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex;
1328 COMPILE_ASSERT(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount < UCHAR_MAX, numberOfAnimatablePropertiesMustBeLessThanUCharMax);
1329 m_propertyWrappers.reserveInitialCapacity(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount);
1331 // First we put the non-shorthand property wrappers into the map, so the shorthand-building
1332 // code can find them.
1334 for (unsigned i = 0; i < animatableLonghandPropertiesCount; ++i) {
1335 AnimationPropertyWrapperBase* wrapper = animatableLonghandPropertyWrappers[i];
1336 m_propertyWrappers.uncheckedAppend(adoptPtr(wrapper));
1337 indexFromPropertyID(wrapper->property()) = i;
1340 for (size_t i = 0; i < animatableShorthandPropertiesCount; ++i) {
1341 CSSPropertyID propertyID = animatableShorthandProperties[i];
1342 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
1343 if (!shorthand.length())
1346 Vector<AnimationPropertyWrapperBase*> longhandWrappers;
1347 longhandWrappers.reserveInitialCapacity(shorthand.length());
1348 const CSSPropertyID* properties = shorthand.properties();
1349 for (unsigned j = 0; j < shorthand.length(); ++j) {
1350 unsigned wrapperIndex = indexFromPropertyID(properties[j]);
1351 if (wrapperIndex == cInvalidPropertyWrapperIndex)
1353 ASSERT(m_propertyWrappers[wrapperIndex]);
1354 longhandWrappers.uncheckedAppend(m_propertyWrappers[wrapperIndex].get());
1357 m_propertyWrappers.uncheckedAppend(adoptPtr(new ShorthandPropertyWrapper(propertyID, longhandWrappers)));
1358 indexFromPropertyID(propertyID) = animatableLonghandPropertiesCount + i;
1362 static bool gatherEnclosingShorthandProperties(CSSPropertyID property, AnimationPropertyWrapperBase* wrapper, HashSet<CSSPropertyID>& propertySet)
1364 if (!wrapper->isShorthandWrapper())
1367 ShorthandPropertyWrapper* shorthandWrapper = static_cast<ShorthandPropertyWrapper*>(wrapper);
1369 bool contained = false;
1370 for (size_t i = 0; i < shorthandWrapper->propertyWrappers().size(); ++i) {
1371 AnimationPropertyWrapperBase* currWrapper = shorthandWrapper->propertyWrappers()[i];
1373 if (gatherEnclosingShorthandProperties(property, currWrapper, propertySet) || currWrapper->property() == property)
1378 propertySet.add(wrapper->property());
1383 // Returns true if we need to start animation timers
1384 bool CSSPropertyAnimation::blendProperties(const AnimationBase* anim, CSSPropertyID prop, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress)
1386 ASSERT(prop != CSSPropertyInvalid);
1388 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1390 wrapper->blend(anim, dst, a, b, progress);
1391 #if USE(ACCELERATED_COMPOSITING)
1392 return !wrapper->animationIsAccelerated() || !anim->isAccelerated();
1401 #if USE(ACCELERATED_COMPOSITING)
1402 bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(CSSPropertyID prop)
1404 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1405 return wrapper ? wrapper->animationIsAccelerated() : false;
1409 // Note: this is inefficient. It's only called from pauseTransitionAtTime().
1410 HashSet<CSSPropertyID> CSSPropertyAnimation::animatableShorthandsAffectingProperty(CSSPropertyID property)
1412 CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1414 HashSet<CSSPropertyID> foundProperties;
1415 for (unsigned i = 0; i < map.size(); ++i)
1416 gatherEnclosingShorthandProperties(property, map.wrapperForIndex(i), foundProperties);
1418 return foundProperties;
1421 bool CSSPropertyAnimation::propertiesEqual(CSSPropertyID prop, const RenderStyle* a, const RenderStyle* b)
1423 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1425 return wrapper->equals(a, b);
1429 CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, bool& isShorthand)
1431 CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1433 if (i < 0 || static_cast<unsigned>(i) >= map.size())
1434 return CSSPropertyInvalid;
1436 AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i);
1437 isShorthand = wrapper->isShorthandWrapper();
1438 return wrapper->property();
1441 int CSSPropertyAnimation::getNumProperties()
1443 return CSSPropertyAnimationWrapperMap::instance().size();