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 IntSize blendFunc(const AnimationBase* anim, const IntSize& from, const IntSize& to, double progress)
98 return IntSize(blendFunc(anim, from.width(), to.width(), progress),
99 blendFunc(anim, from.height(), to.height(), progress));
102 static inline ShadowStyle blendFunc(const AnimationBase* anim, ShadowStyle from, ShadowStyle to, double progress)
107 double fromVal = from == Normal ? 1 : 0;
108 double toVal = to == Normal ? 1 : 0;
109 double result = blendFunc(anim, fromVal, toVal, progress);
110 return result > 0 ? Normal : Inset;
113 static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
116 if (from->style() != to->style())
117 return adoptPtr(new ShadowData(*to));
119 return adoptPtr(new ShadowData(blend(from->location(), to->location(), progress),
120 blend(from->radius(), to->radius(), progress),
121 blend(from->spread(), to->spread(), progress),
122 blendFunc(anim, from->style(), to->style(), progress),
123 from->isWebkitBoxShadow(),
124 blend(from->color(), to->color(), progress)));
127 static inline TransformOperations blendFunc(const AnimationBase* anim, const TransformOperations& from, const TransformOperations& to, double progress)
129 if (anim->isTransformFunctionListValid())
130 return to.blendByMatchingOperations(from, progress);
131 return to.blendByUsingMatrixInterpolation(from, progress, anim->renderer()->isBox() ? toRenderBox(anim->renderer())->borderBoxRect().size() : LayoutSize());
134 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, ClipPathOperation* from, ClipPathOperation* to, double progress)
139 // Other clip-path operations than BasicShapes can not be animated.
140 if (from->getOperationType() != ClipPathOperation::SHAPE || to->getOperationType() != ClipPathOperation::SHAPE)
143 const BasicShape* fromShape = static_cast<ShapeClipPathOperation*>(from)->basicShape();
144 const BasicShape* toShape = static_cast<ShapeClipPathOperation*>(to)->basicShape();
146 if (!fromShape->canBlend(toShape))
149 return ShapeClipPathOperation::create(toShape->blend(fromShape, progress));
152 #if ENABLE(CSS_SHAPES)
153 static inline PassRefPtr<ShapeValue> blendFunc(const AnimationBase*, ShapeValue* from, ShapeValue* to, double progress)
155 // FIXME Bug 102723: Shape-inside should be able to animate a value of 'outside-shape' when shape-outside is set to a BasicShape
156 if (from->type() != ShapeValue::Shape || to->type() != ShapeValue::Shape)
159 const BasicShape* fromShape = from->shape();
160 const BasicShape* toShape = to->shape();
162 if (!fromShape->canBlend(toShape))
165 return ShapeValue::createShapeValue(toShape->blend(fromShape, progress));
169 #if ENABLE(CSS_FILTERS)
170 static inline PassRefPtr<FilterOperation> blendFunc(const AnimationBase* anim, FilterOperation* fromOp, FilterOperation* toOp, double progress, bool blendToPassthrough = false)
173 if (toOp->blendingNeedsRendererSize()) {
174 LayoutSize size = anim->renderer()->isBox() ? toRenderBox(anim->renderer())->borderBoxRect().size() : LayoutSize();
175 return toOp->blend(fromOp, progress, size, blendToPassthrough);
177 return toOp->blend(fromOp, progress, blendToPassthrough);
180 static inline FilterOperations blendFilterOperations(const AnimationBase* anim, const FilterOperations& from, const FilterOperations& to, double progress)
182 FilterOperations result;
183 size_t fromSize = from.operations().size();
184 size_t toSize = to.operations().size();
185 size_t size = max(fromSize, toSize);
186 for (size_t i = 0; i < size; i++) {
187 RefPtr<FilterOperation> fromOp = (i < fromSize) ? from.operations()[i].get() : 0;
188 RefPtr<FilterOperation> toOp = (i < toSize) ? to.operations()[i].get() : 0;
189 RefPtr<FilterOperation> blendedOp = toOp ? blendFunc(anim, fromOp.get(), toOp.get(), progress) : (fromOp ? blendFunc(anim, 0, fromOp.get(), progress, true) : 0);
191 result.operations().append(blendedOp);
193 RefPtr<FilterOperation> identityOp = PassthroughFilterOperation::create();
195 result.operations().append(toOp ? toOp : identityOp);
197 result.operations().append(fromOp ? fromOp : identityOp);
203 static inline FilterOperations blendFunc(const AnimationBase* anim, const FilterOperations& from, const FilterOperations& to, double progress)
205 FilterOperations result;
207 // If we have a filter function list, use that to do a per-function animation.
208 if (anim->filterFunctionListsMatch())
209 result = blendFilterOperations(anim, from, to, progress);
211 // 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.
212 // For now we'll just fail to animate.
219 static inline PassRefPtr<StyleImage> blendFilter(const AnimationBase* anim, CachedImage* image, const FilterOperations& from, const FilterOperations& to, double progress)
222 FilterOperations filterResult = blendFilterOperations(anim, from, to, progress);
224 RefPtr<StyleCachedImage> styledImage = StyleCachedImage::create(image);
225 RefPtr<CSSImageValue> imageValue = CSSImageValue::create(image->url(), styledImage.get());
226 RefPtr<CSSValue> filterValue = ComputedStyleExtractor::valueForFilter(anim->renderer(), anim->renderer()->style(), filterResult, DoNotAdjustPixelValues);
227 RefPtr<CSSFilterImageValue> result = CSSFilterImageValue::create(imageValue, filterValue);
228 result->setFilterOperations(filterResult);
230 return StyleGeneratedImage::create(result.get());
232 #endif // ENABLE(CSS_FILTERS)
234 static inline EVisibility blendFunc(const AnimationBase* anim, EVisibility from, EVisibility to, double progress)
236 // Any non-zero result means we consider the object to be visible. Only at 0 do we consider the object to be
237 // invisible. The invisible value we use (HIDDEN vs. COLLAPSE) depends on the specified from/to values.
238 double fromVal = from == VISIBLE ? 1. : 0.;
239 double toVal = to == VISIBLE ? 1. : 0.;
240 if (fromVal == toVal)
242 double result = blendFunc(anim, fromVal, toVal, progress);
243 return result > 0. ? VISIBLE : (to != VISIBLE ? to : from);
246 static inline LengthBox blendFunc(const AnimationBase* anim, const LengthBox& from, const LengthBox& to, double progress)
248 LengthBox result(blendFunc(anim, from.top(), to.top(), progress),
249 blendFunc(anim, from.right(), to.right(), progress),
250 blendFunc(anim, from.bottom(), to.bottom(), progress),
251 blendFunc(anim, from.left(), to.left(), progress));
256 static inline SVGLength blendFunc(const AnimationBase*, const SVGLength& from, const SVGLength& to, double progress)
258 return to.blend(from, narrowPrecisionToFloat(progress));
260 static inline Vector<SVGLength> blendFunc(const AnimationBase*, const Vector<SVGLength>& from, const Vector<SVGLength>& to, double progress)
262 size_t fromLength = from.size();
263 size_t toLength = to.size();
265 return !progress ? from : to;
267 return progress == 1 ? from : to;
268 size_t resultLength = fromLength;
269 if (fromLength != toLength) {
270 if (!remainder(std::max(fromLength, toLength), std::min(fromLength, toLength)))
271 resultLength = std::max(fromLength, toLength);
273 resultLength = fromLength * toLength;
275 Vector<SVGLength> result(resultLength);
276 for (size_t i = 0; i < resultLength; ++i)
277 result[i] = to[i % toLength].blend(from[i % fromLength], narrowPrecisionToFloat(progress));
282 static inline PassRefPtr<StyleImage> crossfadeBlend(const AnimationBase*, StyleCachedImage* fromStyleImage, StyleCachedImage* toStyleImage, double progress)
284 // If progress is at one of the extremes, we want getComputedStyle to show the image,
285 // not a completed cross-fade, so we hand back one of the existing images.
287 return fromStyleImage;
291 CachedImage* fromCachedImage = static_cast<CachedImage*>(fromStyleImage->data());
292 CachedImage* toCachedImage = static_cast<CachedImage*>(toStyleImage->data());
294 RefPtr<CSSImageValue> fromImageValue = CSSImageValue::create(fromCachedImage->url(), fromStyleImage);
295 RefPtr<CSSImageValue> toImageValue = CSSImageValue::create(toCachedImage->url(), toStyleImage);
296 RefPtr<CSSCrossfadeValue> crossfadeValue = CSSCrossfadeValue::create(fromImageValue, toImageValue);
298 crossfadeValue->setPercentage(CSSPrimitiveValue::create(progress, CSSPrimitiveValue::CSS_NUMBER));
300 return StyleGeneratedImage::create(crossfadeValue.get());
303 static inline PassRefPtr<StyleImage> blendFunc(const AnimationBase* anim, StyleImage* from, StyleImage* to, double progress)
308 // Animation between two generated images. Cross fade for all other cases.
309 if (from->isGeneratedImage() && to->isGeneratedImage()) {
310 CSSImageGeneratorValue* fromGenerated = toStyleGeneratedImage(from)->imageValue();
311 CSSImageGeneratorValue* toGenerated = toStyleGeneratedImage(to)->imageValue();
313 #if ENABLE(CSS_FILTERS)
314 if (fromGenerated->isFilterImageValue() && toGenerated->isFilterImageValue()) {
315 // Animation of generated images just possible if input images are equal.
316 // Otherwise fall back to cross fade animation.
317 CSSFilterImageValue& fromFilter = *toCSSFilterImageValue(fromGenerated);
318 CSSFilterImageValue& toFilter = *toCSSFilterImageValue(toGenerated);
319 if (fromFilter.equalInputImages(toFilter) && fromFilter.cachedImage())
320 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), toFilter.filterOperations(), progress);
324 if (fromGenerated->isCrossfadeValue() && toGenerated->isCrossfadeValue()) {
325 CSSCrossfadeValue& fromCrossfade = *toCSSCrossfadeValue(fromGenerated);
326 CSSCrossfadeValue& toCrossfade = *toCSSCrossfadeValue(toGenerated);
327 if (fromCrossfade.equalInputImages(toCrossfade))
328 return StyleGeneratedImage::create(toCrossfade.blend(fromCrossfade, progress).get());
331 // FIXME: Add support for animation between two *gradient() functions.
332 // https://bugs.webkit.org/show_bug.cgi?id=119956
333 #if ENABLE(CSS_FILTERS)
334 } else if (from->isGeneratedImage() && to->isCachedImage()) {
335 CSSImageGeneratorValue* fromGenerated = toStyleGeneratedImage(from)->imageValue();
336 if (fromGenerated->isFilterImageValue()) {
337 CSSFilterImageValue& fromFilter = *toCSSFilterImageValue(fromGenerated);
338 if (fromFilter.cachedImage() && static_cast<StyleCachedImage*>(to)->cachedImage() == fromFilter.cachedImage())
339 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), FilterOperations(), progress);
341 // FIXME: Add interpolation between cross-fade and image source.
342 } else if (from->isCachedImage() && to->isGeneratedImage()) {
343 CSSImageGeneratorValue* toGenerated = toStyleGeneratedImage(to)->imageValue();
344 if (toGenerated->isFilterImageValue()) {
345 CSSFilterImageValue& toFilter = *toCSSFilterImageValue(toGenerated);
346 if (toFilter.cachedImage() && static_cast<StyleCachedImage*>(from)->cachedImage() == toFilter.cachedImage())
347 return blendFilter(anim, toFilter.cachedImage(), FilterOperations(), toFilter.filterOperations(), progress);
350 // FIXME: Add interpolation between image source and cross-fade.
353 // FIXME: Add support cross fade between cached and generated images.
354 // https://bugs.webkit.org/show_bug.cgi?id=78293
355 if (from->isCachedImage() && to->isCachedImage())
356 return crossfadeBlend(anim, static_cast<StyleCachedImage*>(from), static_cast<StyleCachedImage*>(to), progress);
361 static inline NinePieceImage blendFunc(const AnimationBase* anim, const NinePieceImage& from, const NinePieceImage& to, double progress)
363 if (!from.hasImage() || !to.hasImage())
366 // FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content.
368 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())
371 if (from.image()->imageSize(anim->renderer(), 1.0) != to.image()->imageSize(anim->renderer(), 1.0))
374 RefPtr<StyleImage> newContentImage = blendFunc(anim, from.image(), to.image(), progress);
376 return NinePieceImage(newContentImage, from.imageSlices(), from.fill(), from.borderSlices(), from.outset(), from.horizontalRule(), from.verticalRule());
379 class AnimationPropertyWrapperBase {
380 WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase);
381 WTF_MAKE_FAST_ALLOCATED;
383 AnimationPropertyWrapperBase(CSSPropertyID prop)
388 virtual ~AnimationPropertyWrapperBase() { }
390 virtual bool isShorthandWrapper() const { return false; }
391 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const = 0;
392 virtual void blend(const AnimationBase*, RenderStyle*, const RenderStyle*, const RenderStyle*, double) const = 0;
394 CSSPropertyID property() const { return m_prop; }
396 #if USE(ACCELERATED_COMPOSITING)
397 virtual bool animationIsAccelerated() const { return false; }
401 CSSPropertyID m_prop;
404 template <typename T>
405 class PropertyWrapperGetter : public AnimationPropertyWrapperBase {
407 PropertyWrapperGetter(CSSPropertyID prop, T (RenderStyle::*getter)() const)
408 : AnimationPropertyWrapperBase(prop)
413 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
415 // If the style pointers are the same, don't bother doing the test.
416 // If either is null, return false. If both are null, return true.
417 if ((!a && !b) || a == b)
421 return (a->*m_getter)() == (b->*m_getter)();
425 T (RenderStyle::*m_getter)() const;
428 template <typename T>
429 class PropertyWrapper : public PropertyWrapperGetter<T> {
431 PropertyWrapper(CSSPropertyID prop, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
432 : PropertyWrapperGetter<T>(prop, getter)
437 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
439 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T>::m_getter)(), (b->*PropertyWrapperGetter<T>::m_getter)(), progress));
443 void (RenderStyle::*m_setter)(T);
446 template <typename T>
447 class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> {
449 RefCountedPropertyWrapper(CSSPropertyID prop, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<T>))
450 : PropertyWrapperGetter<T*>(prop, getter)
455 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
457 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T*>::m_getter)(), (b->*PropertyWrapperGetter<T*>::m_getter)(), progress));
461 void (RenderStyle::*m_setter)(PassRefPtr<T>);
465 class PropertyWrapperClipPath : public RefCountedPropertyWrapper<ClipPathOperation> {
467 PropertyWrapperClipPath(CSSPropertyID prop, ClipPathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ClipPathOperation>))
468 : RefCountedPropertyWrapper<ClipPathOperation>(prop, getter, setter)
473 #if ENABLE(CSS_SHAPES)
474 class PropertyWrapperShape : public RefCountedPropertyWrapper<ShapeValue> {
476 PropertyWrapperShape(CSSPropertyID prop, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ShapeValue>))
477 : RefCountedPropertyWrapper<ShapeValue>(prop, getter, setter)
483 class StyleImagePropertyWrapper : public RefCountedPropertyWrapper<StyleImage> {
485 StyleImagePropertyWrapper(CSSPropertyID prop, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<StyleImage>))
486 : RefCountedPropertyWrapper<StyleImage>(prop, getter, setter)
490 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
492 // If the style pointers are the same, don't bother doing the test.
493 // If either is null, return false. If both are null, return true.
499 StyleImage* imageA = (a->*m_getter)();
500 StyleImage* imageB = (b->*m_getter)();
501 return StyleImage::imagesEquivalent(imageA, imageB);
505 class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
507 PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
508 : PropertyWrapperGetter<Color>(prop, getter)
513 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
515 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_getter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
519 void (RenderStyle::*m_setter)(const Color&);
522 #if USE(ACCELERATED_COMPOSITING)
523 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
525 PropertyWrapperAcceleratedOpacity()
526 : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)
530 virtual bool animationIsAccelerated() const { return true; }
532 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
534 float fromOpacity = a->opacity();
536 // This makes sure we put the object being animated into a RenderLayer during the animation
537 dst->setOpacity(blendFunc(anim, (fromOpacity == 1) ? 0.999999f : fromOpacity, b->opacity(), progress));
541 class PropertyWrapperAcceleratedTransform : public PropertyWrapper<const TransformOperations&> {
543 PropertyWrapperAcceleratedTransform()
544 : PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform)
548 virtual bool animationIsAccelerated() const { return true; }
550 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
552 dst->setTransform(blendFunc(anim, a->transform(), b->transform(), progress));
556 #if ENABLE(CSS_FILTERS)
557 class PropertyWrapperAcceleratedFilter : public PropertyWrapper<const FilterOperations&> {
559 PropertyWrapperAcceleratedFilter()
560 : PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter)
564 virtual bool animationIsAccelerated() const { return true; }
566 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
568 dst->setFilter(blendFunc(anim, a->filter(), b->filter(), progress));
572 #endif // USE(ACCELERATED_COMPOSITING)
574 static inline size_t shadowListLength(const ShadowData* shadow)
577 for (count = 0; shadow; shadow = shadow->next())
582 static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow)
584 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (IntPoint(), 0, 0, Normal, false, Color::transparent));
585 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (IntPoint(), 0, 0, Inset, false, Color::transparent));
587 DEFINE_STATIC_LOCAL(ShadowData, defaultWebKitBoxShadowData, (IntPoint(), 0, 0, Normal, true, Color::transparent));
588 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetWebKitBoxShadowData, (IntPoint(), 0, 0, Inset, true, Color::transparent));
593 if (otherShadow->style() == Inset)
594 return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData : &defaultInsetShadowData;
596 return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData : &defaultShadowData;
599 class PropertyWrapperShadow : public AnimationPropertyWrapperBase {
601 PropertyWrapperShadow(CSSPropertyID prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassOwnPtr<ShadowData>, bool))
602 : AnimationPropertyWrapperBase(prop)
608 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
610 const ShadowData* shadowA = (a->*m_getter)();
611 const ShadowData* shadowB = (b->*m_getter)();
615 if (!shadowA && !shadowB)
618 // end of just one of the lists
619 if (!shadowA || !shadowB)
622 if (*shadowA != *shadowB)
625 shadowA = shadowA->next();
626 shadowB = shadowB->next();
632 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
634 const ShadowData* shadowA = (a->*m_getter)();
635 const ShadowData* shadowB = (b->*m_getter)();
637 int fromLength = shadowListLength(shadowA);
638 int toLength = shadowListLength(shadowB);
640 if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) {
641 (dst->*m_setter)(blendSimpleOrMatchedShadowLists(anim, progress, shadowA, shadowB), false);
645 (dst->*m_setter)(blendMismatchedShadowLists(anim, progress, shadowA, shadowB, fromLength, toLength), false);
649 PassOwnPtr<ShadowData> blendSimpleOrMatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB) const
651 OwnPtr<ShadowData> newShadowData;
652 ShadowData* lastShadow = 0;
654 while (shadowA || shadowB) {
655 const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB);
656 const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA);
658 OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
659 ShadowData* blendedShadowPtr = blendedShadow.get();
662 newShadowData = blendedShadow.release();
664 lastShadow->setNext(blendedShadow.release());
666 lastShadow = blendedShadowPtr;
668 shadowA = shadowA ? shadowA->next() : 0;
669 shadowB = shadowB ? shadowB->next() : 0;
672 return newShadowData.release();
675 PassOwnPtr<ShadowData> blendMismatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength) const
677 // The shadows in ShadowData are stored in reverse order, so when animating mismatched lists,
678 // reverse them and match from the end.
679 Vector<const ShadowData*, 4> fromShadows(fromLength);
680 for (int i = fromLength - 1; i >= 0; --i) {
681 fromShadows[i] = shadowA;
682 shadowA = shadowA->next();
685 Vector<const ShadowData*, 4> toShadows(toLength);
686 for (int i = toLength - 1; i >= 0; --i) {
687 toShadows[i] = shadowB;
688 shadowB = shadowB->next();
691 OwnPtr<ShadowData> newShadowData;
693 int maxLength = max(fromLength, toLength);
694 for (int i = 0; i < maxLength; ++i) {
695 const ShadowData* fromShadow = i < fromLength ? fromShadows[i] : 0;
696 const ShadowData* toShadow = i < toLength ? toShadows[i] : 0;
698 const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow);
699 const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow);
701 OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
702 // Insert at the start of the list to preserve the order.
703 blendedShadow->setNext(newShadowData.release());
704 newShadowData = blendedShadow.release();
707 return newShadowData.release();
710 const ShadowData* (RenderStyle::*m_getter)() const;
711 void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
714 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
716 PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
717 : AnimationPropertyWrapperBase(prop)
723 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
725 Color fromColor = (a->*m_getter)();
726 Color toColor = (b->*m_getter)();
728 if (!fromColor.isValid() && !toColor.isValid())
731 if (!fromColor.isValid())
732 fromColor = a->color();
733 if (!toColor.isValid())
734 toColor = b->color();
736 return fromColor == toColor;
739 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
741 Color fromColor = (a->*m_getter)();
742 Color toColor = (b->*m_getter)();
744 if (!fromColor.isValid() && !toColor.isValid())
747 if (!fromColor.isValid())
748 fromColor = a->color();
749 if (!toColor.isValid())
750 toColor = b->color();
751 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
755 Color (RenderStyle::*m_getter)() const;
756 void (RenderStyle::*m_setter)(const Color&);
760 enum MaybeInvalidColorTag { MaybeInvalidColor };
761 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
763 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
764 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
765 : AnimationPropertyWrapperBase(prop)
766 , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter)))
767 , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter, visitedSetter)))
770 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
771 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
772 : AnimationPropertyWrapperBase(prop)
773 , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter)))
774 , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, visitedGetter, visitedSetter)))
777 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
779 return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
781 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
783 m_wrapper->blend(anim, dst, a, b, progress);
784 m_visitedWrapper->blend(anim, dst, a, b, progress);
788 OwnPtr<AnimationPropertyWrapperBase> m_wrapper;
789 OwnPtr<AnimationPropertyWrapperBase> m_visitedWrapper;
792 // Wrapper base class for an animatable property in a FillLayer
793 class FillLayerAnimationPropertyWrapperBase {
795 FillLayerAnimationPropertyWrapperBase()
799 virtual ~FillLayerAnimationPropertyWrapperBase() { }
801 virtual bool equals(const FillLayer*, const FillLayer*) const = 0;
802 virtual void blend(const AnimationBase*, FillLayer*, const FillLayer*, const FillLayer*, double) const = 0;
805 template <typename T>
806 class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase {
807 WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter);
809 FillLayerPropertyWrapperGetter(T (FillLayer::*getter)() const)
814 virtual bool equals(const FillLayer* a, const FillLayer* b) const
816 // If the style pointers are the same, don't bother doing the test.
817 // If either is null, return false. If both are null, return true.
818 if ((!a && !b) || a == b)
822 return (a->*m_getter)() == (b->*m_getter)();
826 T (FillLayer::*m_getter)() const;
829 template <typename T>
830 class FillLayerPropertyWrapper : public FillLayerPropertyWrapperGetter<T> {
832 FillLayerPropertyWrapper(T (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
833 : FillLayerPropertyWrapperGetter<T>(getter)
838 virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
840 (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<T>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<T>::m_getter)(), progress));
844 void (FillLayer::*m_setter)(T);
847 template <typename T>
848 class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> {
850 FillLayerRefCountedPropertyWrapper(T* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<T>))
851 : FillLayerPropertyWrapperGetter<T*>(getter)
856 virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
858 (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), progress));
862 void (FillLayer::*m_setter)(PassRefPtr<T>);
865 class FillLayerStyleImagePropertyWrapper : public FillLayerRefCountedPropertyWrapper<StyleImage> {
867 FillLayerStyleImagePropertyWrapper(StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<StyleImage>))
868 : FillLayerRefCountedPropertyWrapper<StyleImage>(getter, setter)
872 virtual bool equals(const FillLayer* a, const FillLayer* b) const
874 // If the style pointers are the same, don't bother doing the test.
875 // If either is null, return false. If both are null, return true.
881 StyleImage* imageA = (a->*m_getter)();
882 StyleImage* imageB = (b->*m_getter)();
883 return StyleImage::imagesEquivalent(imageA, imageB);
888 class FillLayersPropertyWrapper : public AnimationPropertyWrapperBase {
890 typedef const FillLayer* (RenderStyle::*LayersGetter)() const;
891 typedef FillLayer* (RenderStyle::*LayersAccessor)();
893 FillLayersPropertyWrapper(CSSPropertyID prop, LayersGetter getter, LayersAccessor accessor)
894 : AnimationPropertyWrapperBase(prop)
895 , m_layersGetter(getter)
896 , m_layersAccessor(accessor)
899 case CSSPropertyBackgroundPositionX:
900 case CSSPropertyWebkitMaskPositionX:
901 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::xPosition, &FillLayer::setXPosition);
903 case CSSPropertyBackgroundPositionY:
904 case CSSPropertyWebkitMaskPositionY:
905 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::yPosition, &FillLayer::setYPosition);
907 case CSSPropertyBackgroundSize:
908 case CSSPropertyWebkitBackgroundSize:
909 case CSSPropertyWebkitMaskSize:
910 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<LengthSize>(&FillLayer::sizeLength, &FillLayer::setSizeLength);
912 case CSSPropertyBackgroundImage:
913 m_fillLayerPropertyWrapper = new FillLayerStyleImagePropertyWrapper(&FillLayer::image, &FillLayer::setImage);
920 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
922 const FillLayer* fromLayer = (a->*m_layersGetter)();
923 const FillLayer* toLayer = (b->*m_layersGetter)();
925 while (fromLayer && toLayer) {
926 if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer))
929 fromLayer = fromLayer->next();
930 toLayer = toLayer->next();
936 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
938 const FillLayer* aLayer = (a->*m_layersGetter)();
939 const FillLayer* bLayer = (b->*m_layersGetter)();
940 FillLayer* dstLayer = (dst->*m_layersAccessor)();
942 while (aLayer && bLayer && dstLayer) {
943 m_fillLayerPropertyWrapper->blend(anim, dstLayer, aLayer, bLayer, progress);
944 aLayer = aLayer->next();
945 bLayer = bLayer->next();
946 dstLayer = dstLayer->next();
951 FillLayerAnimationPropertyWrapperBase* m_fillLayerPropertyWrapper;
953 LayersGetter m_layersGetter;
954 LayersAccessor m_layersAccessor;
957 class ShorthandPropertyWrapper : public AnimationPropertyWrapperBase {
959 ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers)
960 : AnimationPropertyWrapperBase(property)
962 m_propertyWrappers.swap(longhandWrappers);
965 virtual bool isShorthandWrapper() const { return true; }
967 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
969 Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
970 for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it) {
971 if (!(*it)->equals(a, b))
977 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
979 Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
980 for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it)
981 (*it)->blend(anim, dst, a, b, progress);
984 const Vector<AnimationPropertyWrapperBase*> propertyWrappers() const { return m_propertyWrappers; }
987 Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
990 class PropertyWrapperFlex : public AnimationPropertyWrapperBase {
992 PropertyWrapperFlex() : AnimationPropertyWrapperBase(CSSPropertyWebkitFlex)
996 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
998 // If the style pointers are the same, don't bother doing the test.
999 // If either is null, return false. If both are null, return true.
1000 if ((!a && !b) || a == b)
1005 return a->flexBasis() == b->flexBasis() && a->flexGrow() == b->flexGrow() && a->flexShrink() == b->flexShrink();
1008 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1010 dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progress));
1011 dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress));
1012 dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), progress));
1017 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
1019 PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (RenderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
1020 : AnimationPropertyWrapperBase(prop)
1021 , m_paintTypeGetter(paintTypeGetter)
1027 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1029 if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
1032 // We only support animations between SVGPaints that are pure Color values.
1033 // For everything else we must return true for this method, otherwise
1034 // we will try to animate between values forever.
1035 if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) {
1036 Color fromColor = (a->*m_getter)();
1037 Color toColor = (b->*m_getter)();
1039 if (!fromColor.isValid() && !toColor.isValid())
1042 if (!fromColor.isValid())
1043 fromColor = Color();
1044 if (!toColor.isValid())
1047 return fromColor == toColor;
1052 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1054 if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
1055 || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
1058 Color fromColor = (a->*m_getter)();
1059 Color toColor = (b->*m_getter)();
1061 if (!fromColor.isValid() && !toColor.isValid())
1064 if (!fromColor.isValid())
1065 fromColor = Color();
1066 if (!toColor.isValid())
1068 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
1072 const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
1073 Color (RenderStyle::*m_getter)() const;
1074 void (RenderStyle::*m_setter)(const Color&);
1078 class CSSPropertyAnimationWrapperMap {
1080 static CSSPropertyAnimationWrapperMap& instance()
1082 // FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last AnimationController is destroyed?
1083 DEFINE_STATIC_LOCAL(OwnPtr<CSSPropertyAnimationWrapperMap>, map, ());
1085 map = adoptPtr(new CSSPropertyAnimationWrapperMap);
1086 map->ensurePropertyMap(); // FIXME: ensurePropertyMap() calls instance() inside addShorthandProperties().
1091 AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID)
1093 int propIndex = propertyID - firstCSSProperty;
1094 if (propertyID < firstCSSProperty || propertyID > lastCSSProperty)
1097 unsigned wrapperIndex = m_propertyToIdMap[propIndex];
1098 if (wrapperIndex == cInvalidPropertyWrapperIndex)
1101 return m_propertyWrappers[wrapperIndex];
1104 AnimationPropertyWrapperBase* wrapperForIndex(unsigned index)
1106 ASSERT(index < m_propertyWrappers.size());
1107 return m_propertyWrappers[index];
1112 return m_propertyWrappers.size();
1117 void addShorthandProperties();
1118 void ensurePropertyMap();
1120 void addPropertyWrapper(CSSPropertyID propertyID, AnimationPropertyWrapperBase* wrapper)
1122 int propIndex = propertyID - firstCSSProperty;
1124 ASSERT(m_propertyToIdMap[propIndex] == cInvalidPropertyWrapperIndex);
1126 unsigned wrapperIndex = m_propertyWrappers.size();
1127 m_propertyWrappers.append(wrapper);
1128 m_propertyToIdMap[propIndex] = wrapperIndex;
1131 Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
1132 unsigned m_propertyToIdMap[numCSSProperties];
1134 const unsigned cInvalidPropertyWrapperIndex = UINT_MAX;
1137 void CSSPropertyAnimationWrapperMap::addShorthandProperties()
1139 static const CSSPropertyID animatableShorthandProperties[] = {
1140 CSSPropertyBackground, // for background-color, background-position, background-image
1141 CSSPropertyBackgroundPosition,
1142 CSSPropertyFont, // for font-size, font-weight
1143 CSSPropertyWebkitMask, // for mask-position
1144 CSSPropertyWebkitMaskPosition,
1145 CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft,
1146 CSSPropertyBorderColor,
1147 CSSPropertyBorderRadius,
1148 CSSPropertyBorderWidth,
1150 CSSPropertyBorderImage,
1151 CSSPropertyBorderSpacing,
1152 CSSPropertyListStyle, // for list-style-image
1156 CSSPropertyWebkitTextStroke,
1157 CSSPropertyWebkitColumnRule,
1158 CSSPropertyWebkitBorderRadius,
1159 CSSPropertyWebkitTransformOrigin
1162 CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1164 for (size_t i = 0; i < WTF_ARRAY_LENGTH(animatableShorthandProperties); ++i) {
1165 CSSPropertyID propertyID = animatableShorthandProperties[i];
1166 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
1167 if (!shorthand.length())
1170 Vector<AnimationPropertyWrapperBase*> longhandWrappers;
1171 for (unsigned i = 0; i < shorthand.length(); ++i) {
1172 if (AnimationPropertyWrapperBase* wrapper = map.wrapperForProperty(shorthand.properties()[i]))
1173 longhandWrappers.append(wrapper);
1176 map.addPropertyWrapper(propertyID, new ShorthandPropertyWrapper(propertyID, longhandWrappers));
1180 void CSSPropertyAnimationWrapperMap::ensurePropertyMap()
1182 Vector<AnimationPropertyWrapperBase*>* gPropertyWrappers = &m_propertyWrappers; // FIXME: Remove this aliasing.
1184 // build the list of property wrappers to do the comparisons and blends
1185 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft));
1186 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight));
1187 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop));
1188 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom));
1190 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth));
1191 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMinWidth, &RenderStyle::minWidth, &RenderStyle::setMinWidth));
1192 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMaxWidth, &RenderStyle::maxWidth, &RenderStyle::setMaxWidth));
1194 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight));
1195 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight));
1196 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight));
1198 gPropertyWrappers->append(new PropertyWrapperFlex());
1200 gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth));
1201 gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth));
1202 gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth));
1203 gPropertyWrappers->append(new PropertyWrapper<unsigned>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth));
1204 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft));
1205 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight));
1206 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop));
1207 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom));
1208 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft));
1209 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight));
1210 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop));
1211 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom));
1212 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::visitedLinkColor, &RenderStyle::setVisitedLinkColor));
1214 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor));
1216 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers));
1217 gPropertyWrappers->append(new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage));
1218 gPropertyWrappers->append(new StyleImagePropertyWrapper(CSSPropertyWebkitMaskImage, &RenderStyle::maskImage, &RenderStyle::setMaskImage));
1220 gPropertyWrappers->append(new StyleImagePropertyWrapper(CSSPropertyBorderImageSource, &RenderStyle::borderImageSource, &RenderStyle::setBorderImageSource));
1221 gPropertyWrappers->append(new PropertyWrapper<LengthBox>(CSSPropertyBorderImageSlice, &RenderStyle::borderImageSlices, &RenderStyle::setBorderImageSlices));
1222 gPropertyWrappers->append(new PropertyWrapper<LengthBox>(CSSPropertyBorderImageWidth, &RenderStyle::borderImageWidth, &RenderStyle::setBorderImageWidth));
1223 gPropertyWrappers->append(new PropertyWrapper<LengthBox>(CSSPropertyBorderImageOutset, &RenderStyle::borderImageOutset, &RenderStyle::setBorderImageOutset));
1225 gPropertyWrappers->append(new StyleImagePropertyWrapper(CSSPropertyWebkitMaskBoxImageSource, &RenderStyle::maskBoxImageSource, &RenderStyle::setMaskBoxImageSource));
1226 gPropertyWrappers->append(new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage));
1228 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionX, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers));
1229 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionY, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers));
1230 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers));
1231 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyWebkitBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers));
1233 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers));
1234 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers));
1235 gPropertyWrappers->append(new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers));
1237 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyFontSize,
1238 // Must pass a specified size to setFontSize if Text Autosizing is enabled, but a computed size
1239 // if text zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1240 // FIXME: Find some way to assert that text zoom isn't activated when Text Autosizing is compiled in.
1241 #if ENABLE(TEXT_AUTOSIZING)
1242 &RenderStyle::specifiedFontSize,
1244 &RenderStyle::computedFontSize,
1246 &RenderStyle::setFontSize));
1247 gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth));
1248 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap));
1249 gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount));
1250 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth));
1251 gPropertyWrappers->append(new PropertyWrapper<short>(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing));
1252 gPropertyWrappers->append(new PropertyWrapper<short>(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing));
1253 gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::zIndex, &RenderStyle::setZIndex));
1254 gPropertyWrappers->append(new PropertyWrapper<short>(CSSPropertyOrphans, &RenderStyle::orphans, &RenderStyle::setOrphans));
1255 gPropertyWrappers->append(new PropertyWrapper<short>(CSSPropertyWidows, &RenderStyle::widows, &RenderStyle::setWidows));
1256 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight));
1257 gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset));
1258 gPropertyWrappers->append(new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth));
1259 gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing));
1260 gPropertyWrappers->append(new PropertyWrapper<int>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing));
1261 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent));
1263 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective));
1264 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX));
1265 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY));
1266 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX));
1267 gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY));
1268 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ));
1269 gPropertyWrappers->append(new PropertyWrapper<LengthSize>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius));
1270 gPropertyWrappers->append(new PropertyWrapper<LengthSize>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius));
1271 gPropertyWrappers->append(new PropertyWrapper<LengthSize>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius));
1272 gPropertyWrappers->append(new PropertyWrapper<LengthSize>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius));
1273 gPropertyWrappers->append(new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility));
1274 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoomWithoutReturnValue));
1276 gPropertyWrappers->append(new PropertyWrapper<LengthBox>(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip));
1278 #if USE(ACCELERATED_COMPOSITING)
1279 gPropertyWrappers->append(new PropertyWrapperAcceleratedOpacity());
1280 gPropertyWrappers->append(new PropertyWrapperAcceleratedTransform());
1281 #if ENABLE(CSS_FILTERS)
1282 gPropertyWrappers->append(new PropertyWrapperAcceleratedFilter());
1285 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity));
1286 gPropertyWrappers->append(new PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform));
1287 #if ENABLE(CSS_FILTERS)
1288 gPropertyWrappers->append(new PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter));
1292 gPropertyWrappers->append(new PropertyWrapperClipPath(CSSPropertyWebkitClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath));
1294 #if ENABLE(CSS_SHAPES)
1295 gPropertyWrappers->append(new PropertyWrapperShape(CSSPropertyWebkitShapeInside, &RenderStyle::shapeInside, &RenderStyle::setShapeInside));
1298 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitColumnRuleColor, MaybeInvalidColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor, &RenderStyle::visitedLinkColumnRuleColor, &RenderStyle::setVisitedLinkColumnRuleColor));
1299 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextStrokeColor, MaybeInvalidColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor, &RenderStyle::visitedLinkTextStrokeColor, &RenderStyle::setVisitedLinkTextStrokeColor));
1300 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextFillColor, MaybeInvalidColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor, &RenderStyle::visitedLinkTextFillColor, &RenderStyle::setVisitedLinkTextFillColor));
1301 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderLeftColor, MaybeInvalidColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor, &RenderStyle::visitedLinkBorderLeftColor, &RenderStyle::setVisitedLinkBorderLeftColor));
1302 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderRightColor, MaybeInvalidColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor, &RenderStyle::visitedLinkBorderRightColor, &RenderStyle::setVisitedLinkBorderRightColor));
1303 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderTopColor, MaybeInvalidColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor, &RenderStyle::visitedLinkBorderTopColor, &RenderStyle::setVisitedLinkBorderTopColor));
1304 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderBottomColor, MaybeInvalidColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor, &RenderStyle::visitedLinkBorderBottomColor, &RenderStyle::setVisitedLinkBorderBottomColor));
1305 gPropertyWrappers->append(new PropertyWrapperVisitedAffectedColor(CSSPropertyOutlineColor, MaybeInvalidColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::visitedLinkOutlineColor, &RenderStyle::setVisitedLinkOutlineColor));
1307 gPropertyWrappers->append(new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow));
1308 gPropertyWrappers->append(new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow));
1309 gPropertyWrappers->append(new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow));
1312 gPropertyWrappers->append(new PropertyWrapperSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor));
1313 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity));
1315 gPropertyWrappers->append(new PropertyWrapperSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor));
1316 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity));
1317 gPropertyWrappers->append(new PropertyWrapper<SVGLength>(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth));
1318 gPropertyWrappers->append(new PropertyWrapper< Vector<SVGLength> >(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray));
1319 gPropertyWrappers->append(new PropertyWrapper<SVGLength>(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset));
1320 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit));
1322 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity));
1323 gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor));
1325 gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity));
1326 gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor));
1328 gPropertyWrappers->append(new PropertyWrapperMaybeInvalidColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor));
1330 gPropertyWrappers->append(new PropertyWrapper<SVGLength>(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue));
1331 gPropertyWrappers->append(new PropertyWrapper<SVGLength>(CSSPropertyKerning, &RenderStyle::kerning, &RenderStyle::setKerning));
1336 // CSSPropertyVerticalAlign
1338 // Compound properties that have components that should be animatable:
1340 // CSSPropertyWebkitColumns
1341 // CSSPropertyWebkitBoxReflect
1343 // Make sure unused slots have a value
1344 for (unsigned int i = 0; i < static_cast<unsigned int>(numCSSProperties); ++i)
1345 m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex;
1347 // First we put the non-shorthand property wrappers into the map, so the shorthand-building
1348 // code can find them.
1349 size_t n = gPropertyWrappers->size();
1350 for (unsigned int i = 0; i < n; ++i) {
1351 ASSERT(m_propertyWrappers[i]->property() - firstCSSProperty < numCSSProperties);
1352 m_propertyToIdMap[m_propertyWrappers[i]->property() - firstCSSProperty] = i;
1355 // Now add the shorthand wrappers.
1356 addShorthandProperties();
1359 static bool gatherEnclosingShorthandProperties(CSSPropertyID property, AnimationPropertyWrapperBase* wrapper, HashSet<CSSPropertyID>& propertySet)
1361 if (!wrapper->isShorthandWrapper())
1364 ShorthandPropertyWrapper* shorthandWrapper = static_cast<ShorthandPropertyWrapper*>(wrapper);
1366 bool contained = false;
1367 for (size_t i = 0; i < shorthandWrapper->propertyWrappers().size(); ++i) {
1368 AnimationPropertyWrapperBase* currWrapper = shorthandWrapper->propertyWrappers()[i];
1370 if (gatherEnclosingShorthandProperties(property, currWrapper, propertySet) || currWrapper->property() == property)
1375 propertySet.add(wrapper->property());
1380 // Returns true if we need to start animation timers
1381 bool CSSPropertyAnimation::blendProperties(const AnimationBase* anim, CSSPropertyID prop, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress)
1383 ASSERT(prop != CSSPropertyInvalid);
1385 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1387 wrapper->blend(anim, dst, a, b, progress);
1388 #if USE(ACCELERATED_COMPOSITING)
1389 return !wrapper->animationIsAccelerated() || !anim->isAccelerated();
1398 #if USE(ACCELERATED_COMPOSITING)
1399 bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(CSSPropertyID prop)
1401 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1402 return wrapper ? wrapper->animationIsAccelerated() : false;
1406 // Note: this is inefficient. It's only called from pauseTransitionAtTime().
1407 HashSet<CSSPropertyID> CSSPropertyAnimation::animatableShorthandsAffectingProperty(CSSPropertyID property)
1409 CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1411 HashSet<CSSPropertyID> foundProperties;
1412 for (unsigned i = 0; i < map.size(); ++i)
1413 gatherEnclosingShorthandProperties(property, map.wrapperForIndex(i), foundProperties);
1415 return foundProperties;
1418 bool CSSPropertyAnimation::propertiesEqual(CSSPropertyID prop, const RenderStyle* a, const RenderStyle* b)
1420 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1422 return wrapper->equals(a, b);
1426 CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, bool& isShorthand)
1428 CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1430 if (i < 0 || static_cast<unsigned>(i) >= map.size())
1431 return CSSPropertyInvalid;
1433 AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i);
1434 isShorthand = wrapper->isShorthandWrapper();
1435 return wrapper->property();
1438 int CSSPropertyAnimation::getNumProperties()
1440 return CSSPropertyAnimationWrapperMap::instance().size();