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 auto filterValue = ComputedStyleExtractor::valueForFilter(anim->renderer(), &anim->renderer()->style(), filterResult, DoNotAdjustPixelValues);
222 auto result = CSSFilterImageValue::create(std::move(imageValue), std::move(filterValue));
223 result.get().setFilterOperations(filterResult);
224 return StyleGeneratedImage::create(std::move(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);
288 auto crossfadeValue = CSSCrossfadeValue::create(std::move(fromImageValue), std::move(toImageValue));
289 crossfadeValue.get().setPercentage(CSSPrimitiveValue::create(progress, CSSPrimitiveValue::CSS_NUMBER));
290 return StyleGeneratedImage::create(std::move(crossfadeValue));
293 static inline PassRefPtr<StyleImage> blendFunc(const AnimationBase* anim, StyleImage* from, StyleImage* to, double progress)
298 // Animation between two generated images. Cross fade for all other cases.
299 if (from->isGeneratedImage() && to->isGeneratedImage()) {
300 CSSImageGeneratorValue& fromGenerated = toStyleGeneratedImage(from)->imageValue();
301 CSSImageGeneratorValue& toGenerated = toStyleGeneratedImage(to)->imageValue();
303 #if ENABLE(CSS_FILTERS)
304 if (fromGenerated.isFilterImageValue() && toGenerated.isFilterImageValue()) {
305 // Animation of generated images just possible if input images are equal.
306 // Otherwise fall back to cross fade animation.
307 CSSFilterImageValue& fromFilter = toCSSFilterImageValue(fromGenerated);
308 CSSFilterImageValue& toFilter = toCSSFilterImageValue(toGenerated);
309 if (fromFilter.equalInputImages(toFilter) && fromFilter.cachedImage())
310 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), toFilter.filterOperations(), progress);
314 if (fromGenerated.isCrossfadeValue() && toGenerated.isCrossfadeValue()) {
315 CSSCrossfadeValue& fromCrossfade = toCSSCrossfadeValue(fromGenerated);
316 CSSCrossfadeValue& toCrossfade = toCSSCrossfadeValue(toGenerated);
317 if (fromCrossfade.equalInputImages(toCrossfade))
318 return StyleGeneratedImage::create(*toCrossfade.blend(fromCrossfade, progress));
321 // FIXME: Add support for animation between two *gradient() functions.
322 // https://bugs.webkit.org/show_bug.cgi?id=119956
323 #if ENABLE(CSS_FILTERS)
324 } else if (from->isGeneratedImage() && to->isCachedImage()) {
325 CSSImageGeneratorValue& fromGenerated = toStyleGeneratedImage(from)->imageValue();
326 if (fromGenerated.isFilterImageValue()) {
327 CSSFilterImageValue& fromFilter = toCSSFilterImageValue(fromGenerated);
328 if (fromFilter.cachedImage() && static_cast<StyleCachedImage*>(to)->cachedImage() == fromFilter.cachedImage())
329 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), FilterOperations(), progress);
331 // FIXME: Add interpolation between cross-fade and image source.
332 } else if (from->isCachedImage() && to->isGeneratedImage()) {
333 CSSImageGeneratorValue& toGenerated = toStyleGeneratedImage(to)->imageValue();
334 if (toGenerated.isFilterImageValue()) {
335 CSSFilterImageValue& toFilter = toCSSFilterImageValue(toGenerated);
336 if (toFilter.cachedImage() && static_cast<StyleCachedImage*>(from)->cachedImage() == toFilter.cachedImage())
337 return blendFilter(anim, toFilter.cachedImage(), FilterOperations(), toFilter.filterOperations(), progress);
340 // FIXME: Add interpolation between image source and cross-fade.
343 // FIXME: Add support cross fade between cached and generated images.
344 // https://bugs.webkit.org/show_bug.cgi?id=78293
345 if (from->isCachedImage() && to->isCachedImage())
346 return crossfadeBlend(anim, static_cast<StyleCachedImage*>(from), static_cast<StyleCachedImage*>(to), progress);
351 static inline NinePieceImage blendFunc(const AnimationBase* anim, const NinePieceImage& from, const NinePieceImage& to, double progress)
353 if (!from.hasImage() || !to.hasImage())
356 // FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content.
358 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())
361 if (from.image()->imageSize(anim->renderer(), 1.0) != to.image()->imageSize(anim->renderer(), 1.0))
364 RefPtr<StyleImage> newContentImage = blendFunc(anim, from.image(), to.image(), progress);
366 return NinePieceImage(newContentImage, from.imageSlices(), from.fill(), from.borderSlices(), from.outset(), from.horizontalRule(), from.verticalRule());
369 class AnimationPropertyWrapperBase {
370 WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase);
371 WTF_MAKE_FAST_ALLOCATED;
373 AnimationPropertyWrapperBase(CSSPropertyID prop)
378 virtual ~AnimationPropertyWrapperBase() { }
380 virtual bool isShorthandWrapper() const { return false; }
381 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const = 0;
382 virtual void blend(const AnimationBase*, RenderStyle*, const RenderStyle*, const RenderStyle*, double) const = 0;
384 CSSPropertyID property() const { return m_prop; }
386 #if USE(ACCELERATED_COMPOSITING)
387 virtual bool animationIsAccelerated() const { return false; }
391 CSSPropertyID m_prop;
394 template <typename T>
395 class PropertyWrapperGetter : public AnimationPropertyWrapperBase {
397 PropertyWrapperGetter(CSSPropertyID prop, T (RenderStyle::*getter)() const)
398 : AnimationPropertyWrapperBase(prop)
403 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
405 // If the style pointers are the same, don't bother doing the test.
406 // If either is null, return false. If both are null, return true.
407 if ((!a && !b) || a == b)
411 return (a->*m_getter)() == (b->*m_getter)();
415 T (RenderStyle::*m_getter)() const;
418 template <typename T>
419 class PropertyWrapper : public PropertyWrapperGetter<T> {
421 PropertyWrapper(CSSPropertyID prop, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
422 : PropertyWrapperGetter<T>(prop, getter)
427 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
429 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T>::m_getter)(), (b->*PropertyWrapperGetter<T>::m_getter)(), progress));
433 void (RenderStyle::*m_setter)(T);
436 template <typename T>
437 class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> {
439 RefCountedPropertyWrapper(CSSPropertyID prop, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<T>))
440 : PropertyWrapperGetter<T*>(prop, getter)
445 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
447 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T*>::m_getter)(), (b->*PropertyWrapperGetter<T*>::m_getter)(), progress));
451 void (RenderStyle::*m_setter)(PassRefPtr<T>);
454 template <typename T>
455 class LengthPropertyWrapper : public PropertyWrapperGetter<const T&> {
457 LengthPropertyWrapper(CSSPropertyID prop, const T& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
458 : PropertyWrapperGetter<const T&>(prop, getter)
463 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
465 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<const T&>::m_getter)(), (b->*PropertyWrapperGetter<const T&>::m_getter)(), progress));
469 void (RenderStyle::*m_setter)(T);
472 class PropertyWrapperClipPath : public RefCountedPropertyWrapper<ClipPathOperation> {
474 PropertyWrapperClipPath(CSSPropertyID prop, ClipPathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ClipPathOperation>))
475 : RefCountedPropertyWrapper<ClipPathOperation>(prop, getter, setter)
480 #if ENABLE(CSS_SHAPES)
481 class PropertyWrapperShape : public RefCountedPropertyWrapper<ShapeValue> {
483 PropertyWrapperShape(CSSPropertyID prop, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ShapeValue>))
484 : RefCountedPropertyWrapper<ShapeValue>(prop, getter, setter)
490 class StyleImagePropertyWrapper : public RefCountedPropertyWrapper<StyleImage> {
492 StyleImagePropertyWrapper(CSSPropertyID prop, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<StyleImage>))
493 : RefCountedPropertyWrapper<StyleImage>(prop, getter, setter)
497 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
499 // If the style pointers are the same, don't bother doing the test.
500 // If either is null, return false. If both are null, return true.
506 StyleImage* imageA = (a->*m_getter)();
507 StyleImage* imageB = (b->*m_getter)();
508 return StyleImage::imagesEquivalent(imageA, imageB);
512 class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
514 PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
515 : PropertyWrapperGetter<Color>(prop, getter)
520 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
522 (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_getter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
526 void (RenderStyle::*m_setter)(const Color&);
530 #if USE(ACCELERATED_COMPOSITING)
531 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
533 PropertyWrapperAcceleratedOpacity()
534 : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)
538 virtual bool animationIsAccelerated() const { return true; }
540 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
542 float fromOpacity = a->opacity();
544 // This makes sure we put the object being animated into a RenderLayer during the animation
545 dst->setOpacity(blendFunc(anim, (fromOpacity == 1) ? 0.999999f : fromOpacity, b->opacity(), progress));
549 class PropertyWrapperAcceleratedTransform : public PropertyWrapper<const TransformOperations&> {
551 PropertyWrapperAcceleratedTransform()
552 : PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform)
556 virtual bool animationIsAccelerated() const { return true; }
558 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
560 dst->setTransform(blendFunc(anim, a->transform(), b->transform(), progress));
564 #if ENABLE(CSS_FILTERS)
565 class PropertyWrapperAcceleratedFilter : public PropertyWrapper<const FilterOperations&> {
567 PropertyWrapperAcceleratedFilter()
568 : PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter)
572 virtual bool animationIsAccelerated() const { return true; }
574 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
576 dst->setFilter(blendFunc(anim, a->filter(), b->filter(), progress));
580 #endif // USE(ACCELERATED_COMPOSITING)
582 static inline size_t shadowListLength(const ShadowData* shadow)
585 for (count = 0; shadow; shadow = shadow->next())
590 static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow)
592 DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (IntPoint(), 0, 0, Normal, false, Color::transparent));
593 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (IntPoint(), 0, 0, Inset, false, Color::transparent));
595 DEFINE_STATIC_LOCAL(ShadowData, defaultWebKitBoxShadowData, (IntPoint(), 0, 0, Normal, true, Color::transparent));
596 DEFINE_STATIC_LOCAL(ShadowData, defaultInsetWebKitBoxShadowData, (IntPoint(), 0, 0, Inset, true, Color::transparent));
601 if (otherShadow->style() == Inset)
602 return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData : &defaultInsetShadowData;
604 return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData : &defaultShadowData;
607 class PropertyWrapperShadow : public AnimationPropertyWrapperBase {
609 PropertyWrapperShadow(CSSPropertyID prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassOwnPtr<ShadowData>, bool))
610 : AnimationPropertyWrapperBase(prop)
616 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
618 const ShadowData* shadowA = (a->*m_getter)();
619 const ShadowData* shadowB = (b->*m_getter)();
623 if (!shadowA && !shadowB)
626 // end of just one of the lists
627 if (!shadowA || !shadowB)
630 if (*shadowA != *shadowB)
633 shadowA = shadowA->next();
634 shadowB = shadowB->next();
640 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
642 const ShadowData* shadowA = (a->*m_getter)();
643 const ShadowData* shadowB = (b->*m_getter)();
645 int fromLength = shadowListLength(shadowA);
646 int toLength = shadowListLength(shadowB);
648 if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) {
649 (dst->*m_setter)(blendSimpleOrMatchedShadowLists(anim, progress, shadowA, shadowB), false);
653 (dst->*m_setter)(blendMismatchedShadowLists(anim, progress, shadowA, shadowB, fromLength, toLength), false);
657 PassOwnPtr<ShadowData> blendSimpleOrMatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB) const
659 OwnPtr<ShadowData> newShadowData;
660 ShadowData* lastShadow = 0;
662 while (shadowA || shadowB) {
663 const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB);
664 const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA);
666 OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
667 ShadowData* blendedShadowPtr = blendedShadow.get();
670 newShadowData = blendedShadow.release();
672 lastShadow->setNext(blendedShadow.release());
674 lastShadow = blendedShadowPtr;
676 shadowA = shadowA ? shadowA->next() : 0;
677 shadowB = shadowB ? shadowB->next() : 0;
680 return newShadowData.release();
683 PassOwnPtr<ShadowData> blendMismatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength) const
685 // The shadows in ShadowData are stored in reverse order, so when animating mismatched lists,
686 // reverse them and match from the end.
687 Vector<const ShadowData*, 4> fromShadows(fromLength);
688 for (int i = fromLength - 1; i >= 0; --i) {
689 fromShadows[i] = shadowA;
690 shadowA = shadowA->next();
693 Vector<const ShadowData*, 4> toShadows(toLength);
694 for (int i = toLength - 1; i >= 0; --i) {
695 toShadows[i] = shadowB;
696 shadowB = shadowB->next();
699 OwnPtr<ShadowData> newShadowData;
701 int maxLength = std::max(fromLength, toLength);
702 for (int i = 0; i < maxLength; ++i) {
703 const ShadowData* fromShadow = i < fromLength ? fromShadows[i] : 0;
704 const ShadowData* toShadow = i < toLength ? toShadows[i] : 0;
706 const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow);
707 const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow);
709 OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
710 // Insert at the start of the list to preserve the order.
711 blendedShadow->setNext(newShadowData.release());
712 newShadowData = blendedShadow.release();
715 return newShadowData.release();
718 const ShadowData* (RenderStyle::*m_getter)() const;
719 void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
722 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
724 PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
725 : AnimationPropertyWrapperBase(prop)
731 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
733 Color fromColor = (a->*m_getter)();
734 Color toColor = (b->*m_getter)();
736 if (!fromColor.isValid() && !toColor.isValid())
739 if (!fromColor.isValid())
740 fromColor = a->color();
741 if (!toColor.isValid())
742 toColor = b->color();
744 return fromColor == toColor;
747 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
749 Color fromColor = (a->*m_getter)();
750 Color toColor = (b->*m_getter)();
752 if (!fromColor.isValid() && !toColor.isValid())
755 if (!fromColor.isValid())
756 fromColor = a->color();
757 if (!toColor.isValid())
758 toColor = b->color();
759 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
763 Color (RenderStyle::*m_getter)() const;
764 void (RenderStyle::*m_setter)(const Color&);
768 enum MaybeInvalidColorTag { MaybeInvalidColor };
769 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
771 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
772 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
773 : AnimationPropertyWrapperBase(prop)
774 , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter)))
775 , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter, visitedSetter)))
778 PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
779 Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
780 : AnimationPropertyWrapperBase(prop)
781 , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter)))
782 , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, visitedGetter, visitedSetter)))
785 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
787 return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
789 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
791 m_wrapper->blend(anim, dst, a, b, progress);
792 m_visitedWrapper->blend(anim, dst, a, b, progress);
796 OwnPtr<AnimationPropertyWrapperBase> m_wrapper;
797 OwnPtr<AnimationPropertyWrapperBase> m_visitedWrapper;
800 // Wrapper base class for an animatable property in a FillLayer
801 class FillLayerAnimationPropertyWrapperBase {
803 FillLayerAnimationPropertyWrapperBase()
807 virtual ~FillLayerAnimationPropertyWrapperBase() { }
809 virtual bool equals(const FillLayer*, const FillLayer*) const = 0;
810 virtual void blend(const AnimationBase*, FillLayer*, const FillLayer*, const FillLayer*, double) const = 0;
813 template <typename T>
814 class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase {
815 WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter);
817 FillLayerPropertyWrapperGetter(T (FillLayer::*getter)() const)
822 virtual bool equals(const FillLayer* a, const FillLayer* b) const
824 // If the style pointers are the same, don't bother doing the test.
825 // If either is null, return false. If both are null, return true.
826 if ((!a && !b) || a == b)
830 return (a->*m_getter)() == (b->*m_getter)();
834 T (FillLayer::*m_getter)() const;
837 template <typename T>
838 class FillLayerPropertyWrapper : public FillLayerPropertyWrapperGetter<const T&> {
840 FillLayerPropertyWrapper(const T& (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
841 : FillLayerPropertyWrapperGetter<const T&>(getter)
846 virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
848 (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), progress));
852 void (FillLayer::*m_setter)(T);
855 template <typename T>
856 class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> {
858 FillLayerRefCountedPropertyWrapper(T* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<T>))
859 : FillLayerPropertyWrapperGetter<T*>(getter)
864 virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
866 (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), progress));
870 void (FillLayer::*m_setter)(PassRefPtr<T>);
873 class FillLayerStyleImagePropertyWrapper : public FillLayerRefCountedPropertyWrapper<StyleImage> {
875 FillLayerStyleImagePropertyWrapper(StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<StyleImage>))
876 : FillLayerRefCountedPropertyWrapper<StyleImage>(getter, setter)
880 virtual bool equals(const FillLayer* a, const FillLayer* b) const
882 // If the style pointers are the same, don't bother doing the test.
883 // If either is null, return false. If both are null, return true.
889 StyleImage* imageA = (a->*m_getter)();
890 StyleImage* imageB = (b->*m_getter)();
891 return StyleImage::imagesEquivalent(imageA, imageB);
895 class FillLayersPropertyWrapper : public AnimationPropertyWrapperBase {
897 typedef const FillLayer* (RenderStyle::*LayersGetter)() const;
898 typedef FillLayer* (RenderStyle::*LayersAccessor)();
900 FillLayersPropertyWrapper(CSSPropertyID prop, LayersGetter getter, LayersAccessor accessor)
901 : AnimationPropertyWrapperBase(prop)
902 , m_layersGetter(getter)
903 , m_layersAccessor(accessor)
906 case CSSPropertyBackgroundPositionX:
907 case CSSPropertyWebkitMaskPositionX:
908 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::xPosition, &FillLayer::setXPosition);
910 case CSSPropertyBackgroundPositionY:
911 case CSSPropertyWebkitMaskPositionY:
912 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::yPosition, &FillLayer::setYPosition);
914 case CSSPropertyBackgroundSize:
915 case CSSPropertyWebkitBackgroundSize:
916 case CSSPropertyWebkitMaskSize:
917 m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<LengthSize>(&FillLayer::sizeLength, &FillLayer::setSizeLength);
919 case CSSPropertyBackgroundImage:
920 m_fillLayerPropertyWrapper = new FillLayerStyleImagePropertyWrapper(&FillLayer::image, &FillLayer::setImage);
927 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
929 const FillLayer* fromLayer = (a->*m_layersGetter)();
930 const FillLayer* toLayer = (b->*m_layersGetter)();
932 while (fromLayer && toLayer) {
933 if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer))
936 fromLayer = fromLayer->next();
937 toLayer = toLayer->next();
943 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
945 const FillLayer* aLayer = (a->*m_layersGetter)();
946 const FillLayer* bLayer = (b->*m_layersGetter)();
947 FillLayer* dstLayer = (dst->*m_layersAccessor)();
949 while (aLayer && bLayer && dstLayer) {
950 m_fillLayerPropertyWrapper->blend(anim, dstLayer, aLayer, bLayer, progress);
951 aLayer = aLayer->next();
952 bLayer = bLayer->next();
953 dstLayer = dstLayer->next();
958 FillLayerAnimationPropertyWrapperBase* m_fillLayerPropertyWrapper;
960 LayersGetter m_layersGetter;
961 LayersAccessor m_layersAccessor;
964 class ShorthandPropertyWrapper : public AnimationPropertyWrapperBase {
966 ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers)
967 : AnimationPropertyWrapperBase(property)
969 m_propertyWrappers.swap(longhandWrappers);
972 virtual bool isShorthandWrapper() const { return true; }
974 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
976 Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
977 for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it) {
978 if (!(*it)->equals(a, b))
984 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
986 Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
987 for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it)
988 (*it)->blend(anim, dst, a, b, progress);
991 const Vector<AnimationPropertyWrapperBase*> propertyWrappers() const { return m_propertyWrappers; }
994 Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
997 class PropertyWrapperFlex : public AnimationPropertyWrapperBase {
999 PropertyWrapperFlex() : AnimationPropertyWrapperBase(CSSPropertyWebkitFlex)
1003 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1005 // If the style pointers are the same, don't bother doing the test.
1006 // If either is null, return false. If both are null, return true.
1007 if ((!a && !b) || a == b)
1012 return a->flexBasis() == b->flexBasis() && a->flexGrow() == b->flexGrow() && a->flexShrink() == b->flexShrink();
1015 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1017 dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progress));
1018 dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress));
1019 dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), progress));
1024 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
1026 PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (RenderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
1027 : AnimationPropertyWrapperBase(prop)
1028 , m_paintTypeGetter(paintTypeGetter)
1034 virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1036 if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
1039 // We only support animations between SVGPaints that are pure Color values.
1040 // For everything else we must return true for this method, otherwise
1041 // we will try to animate between values forever.
1042 if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) {
1043 Color fromColor = (a->*m_getter)();
1044 Color toColor = (b->*m_getter)();
1046 if (!fromColor.isValid() && !toColor.isValid())
1049 if (!fromColor.isValid())
1050 fromColor = Color();
1051 if (!toColor.isValid())
1054 return fromColor == toColor;
1059 virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1061 if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
1062 || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
1065 Color fromColor = (a->*m_getter)();
1066 Color toColor = (b->*m_getter)();
1068 if (!fromColor.isValid() && !toColor.isValid())
1071 if (!fromColor.isValid())
1072 fromColor = Color();
1073 if (!toColor.isValid())
1075 (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
1079 const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
1080 Color (RenderStyle::*m_getter)() const;
1081 void (RenderStyle::*m_setter)(const Color&);
1085 class CSSPropertyAnimationWrapperMap {
1087 static CSSPropertyAnimationWrapperMap& instance()
1089 // FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last AnimationController is destroyed?
1090 DEFINE_STATIC_LOCAL(OwnPtr<CSSPropertyAnimationWrapperMap>, map, ());
1092 map = adoptPtr(new CSSPropertyAnimationWrapperMap);
1096 AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID)
1098 if (propertyID < firstCSSProperty || propertyID > lastCSSProperty)
1101 unsigned wrapperIndex = indexFromPropertyID(propertyID);
1102 if (wrapperIndex == cInvalidPropertyWrapperIndex)
1105 return m_propertyWrappers[wrapperIndex].get();
1108 AnimationPropertyWrapperBase* wrapperForIndex(unsigned index)
1110 ASSERT(index < m_propertyWrappers.size());
1111 return m_propertyWrappers[index].get();
1116 return m_propertyWrappers.size();
1120 CSSPropertyAnimationWrapperMap();
1121 unsigned char& indexFromPropertyID(CSSPropertyID propertyID)
1123 return m_propertyToIdMap[propertyID - firstCSSProperty];
1126 Vector<OwnPtr<AnimationPropertyWrapperBase>> m_propertyWrappers;
1127 unsigned char m_propertyToIdMap[numCSSProperties];
1129 static const unsigned char cInvalidPropertyWrapperIndex = UCHAR_MAX;
1132 CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap()
1134 // build the list of property wrappers to do the comparisons and blends
1135 AnimationPropertyWrapperBase* animatableLonghandPropertyWrappers[] = {
1136 new LengthPropertyWrapper<Length>(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft),
1137 new LengthPropertyWrapper<Length>(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight),
1138 new LengthPropertyWrapper<Length>(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop),
1139 new LengthPropertyWrapper<Length>(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom),
1141 new LengthPropertyWrapper<Length>(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth),
1142 new LengthPropertyWrapper<Length>(CSSPropertyMinWidth, &RenderStyle::minWidth, &RenderStyle::setMinWidth),
1143 new LengthPropertyWrapper<Length>(CSSPropertyMaxWidth, &RenderStyle::maxWidth, &RenderStyle::setMaxWidth),
1145 new LengthPropertyWrapper<Length>(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight),
1146 new LengthPropertyWrapper<Length>(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight),
1147 new LengthPropertyWrapper<Length>(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight),
1149 new PropertyWrapperFlex(),
1151 new PropertyWrapper<unsigned>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth),
1152 new PropertyWrapper<unsigned>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth),
1153 new PropertyWrapper<unsigned>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth),
1154 new PropertyWrapper<unsigned>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth),
1155 new LengthPropertyWrapper<Length>(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft),
1156 new LengthPropertyWrapper<Length>(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight),
1157 new LengthPropertyWrapper<Length>(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop),
1158 new LengthPropertyWrapper<Length>(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom),
1159 new LengthPropertyWrapper<Length>(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft),
1160 new LengthPropertyWrapper<Length>(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight),
1161 new LengthPropertyWrapper<Length>(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop),
1162 new LengthPropertyWrapper<Length>(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom),
1163 new PropertyWrapperVisitedAffectedColor(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::visitedLinkColor, &RenderStyle::setVisitedLinkColor),
1165 new PropertyWrapperVisitedAffectedColor(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor),
1167 new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1168 new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage),
1169 new StyleImagePropertyWrapper(CSSPropertyWebkitMaskImage, &RenderStyle::maskImage, &RenderStyle::setMaskImage),
1171 new StyleImagePropertyWrapper(CSSPropertyBorderImageSource, &RenderStyle::borderImageSource, &RenderStyle::setBorderImageSource),
1172 new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageSlice, &RenderStyle::borderImageSlices, &RenderStyle::setBorderImageSlices),
1173 new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageWidth, &RenderStyle::borderImageWidth, &RenderStyle::setBorderImageWidth),
1174 new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageOutset, &RenderStyle::borderImageOutset, &RenderStyle::setBorderImageOutset),
1176 new StyleImagePropertyWrapper(CSSPropertyWebkitMaskBoxImageSource, &RenderStyle::maskBoxImageSource, &RenderStyle::setMaskBoxImageSource),
1177 new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage),
1179 new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionX, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1180 new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionY, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1181 new FillLayersPropertyWrapper(CSSPropertyBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1182 new FillLayersPropertyWrapper(CSSPropertyWebkitBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1184 new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1185 new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1186 new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1188 new PropertyWrapper<float>(CSSPropertyFontSize,
1189 // Must pass a specified size to setFontSize if Text Autosizing is enabled, but a computed size
1190 // if text zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1191 // FIXME: Find some way to assert that text zoom isn't activated when Text Autosizing is compiled in.
1192 #if ENABLE(TEXT_AUTOSIZING)
1193 &RenderStyle::specifiedFontSize,
1195 &RenderStyle::computedFontSize,
1197 &RenderStyle::setFontSize),
1198 new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth),
1199 new PropertyWrapper<float>(CSSPropertyWebkitColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap),
1200 new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount),
1201 new PropertyWrapper<float>(CSSPropertyWebkitColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth),
1202 new PropertyWrapper<short>(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing),
1203 new PropertyWrapper<short>(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing),
1204 new PropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::zIndex, &RenderStyle::setZIndex),
1205 new PropertyWrapper<short>(CSSPropertyOrphans, &RenderStyle::orphans, &RenderStyle::setOrphans),
1206 new PropertyWrapper<short>(CSSPropertyWidows, &RenderStyle::widows, &RenderStyle::setWidows),
1207 new LengthPropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight),
1208 new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset),
1209 new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth),
1210 new PropertyWrapper<int>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing),
1211 new PropertyWrapper<int>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing),
1212 new LengthPropertyWrapper<Length>(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent),
1214 new PropertyWrapper<float>(CSSPropertyWebkitPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective),
1215 new LengthPropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX),
1216 new LengthPropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY),
1217 new LengthPropertyWrapper<Length>(CSSPropertyWebkitTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX),
1218 new LengthPropertyWrapper<Length>(CSSPropertyWebkitTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY),
1219 new PropertyWrapper<float>(CSSPropertyWebkitTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ),
1220 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius),
1221 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius),
1222 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius),
1223 new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius),
1224 new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility),
1225 new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoomWithoutReturnValue),
1227 new LengthPropertyWrapper<LengthBox>(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip),
1229 #if USE(ACCELERATED_COMPOSITING)
1230 new PropertyWrapperAcceleratedOpacity(),
1231 new PropertyWrapperAcceleratedTransform(),
1232 #if ENABLE(CSS_FILTERS)
1233 new PropertyWrapperAcceleratedFilter(),
1236 new PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity),
1237 new PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform),
1238 #if ENABLE(CSS_FILTERS)
1239 new PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter),
1243 new PropertyWrapperClipPath(CSSPropertyWebkitClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath),
1245 #if ENABLE(CSS_SHAPES)
1246 new PropertyWrapperShape(CSSPropertyWebkitShapeInside, &RenderStyle::shapeInside, &RenderStyle::setShapeInside),
1247 new PropertyWrapperShape(CSSPropertyWebkitShapeOutside, &RenderStyle::shapeOutside, &RenderStyle::setShapeOutside),
1248 new LengthPropertyWrapper<Length>(CSSPropertyWebkitShapeMargin, &RenderStyle::shapeMargin, &RenderStyle::setShapeMargin),
1249 new PropertyWrapper<float>(CSSPropertyWebkitShapeImageThreshold, &RenderStyle::shapeImageThreshold, &RenderStyle::setShapeImageThreshold),
1252 new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitColumnRuleColor, MaybeInvalidColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor, &RenderStyle::visitedLinkColumnRuleColor, &RenderStyle::setVisitedLinkColumnRuleColor),
1253 new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextStrokeColor, MaybeInvalidColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor, &RenderStyle::visitedLinkTextStrokeColor, &RenderStyle::setVisitedLinkTextStrokeColor),
1254 new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextFillColor, MaybeInvalidColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor, &RenderStyle::visitedLinkTextFillColor, &RenderStyle::setVisitedLinkTextFillColor),
1255 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderLeftColor, MaybeInvalidColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor, &RenderStyle::visitedLinkBorderLeftColor, &RenderStyle::setVisitedLinkBorderLeftColor),
1256 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderRightColor, MaybeInvalidColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor, &RenderStyle::visitedLinkBorderRightColor, &RenderStyle::setVisitedLinkBorderRightColor),
1257 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderTopColor, MaybeInvalidColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor, &RenderStyle::visitedLinkBorderTopColor, &RenderStyle::setVisitedLinkBorderTopColor),
1258 new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderBottomColor, MaybeInvalidColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor, &RenderStyle::visitedLinkBorderBottomColor, &RenderStyle::setVisitedLinkBorderBottomColor),
1259 new PropertyWrapperVisitedAffectedColor(CSSPropertyOutlineColor, MaybeInvalidColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::visitedLinkOutlineColor, &RenderStyle::setVisitedLinkOutlineColor),
1261 new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1262 new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1263 new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow),
1266 new PropertyWrapperSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor),
1267 new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity),
1269 new PropertyWrapperSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor),
1270 new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity),
1271 new PropertyWrapper<SVGLength>(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth),
1272 new PropertyWrapper< Vector<SVGLength>>(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray),
1273 new PropertyWrapper<SVGLength>(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset),
1274 new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit),
1276 new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity),
1277 new PropertyWrapperMaybeInvalidColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor),
1279 new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity),
1280 new PropertyWrapperMaybeInvalidColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor),
1282 new PropertyWrapperMaybeInvalidColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor),
1284 new PropertyWrapper<SVGLength>(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue),
1285 new PropertyWrapper<SVGLength>(CSSPropertyKerning, &RenderStyle::kerning, &RenderStyle::setKerning),
1288 const unsigned animatableLonghandPropertiesCount = WTF_ARRAY_LENGTH(animatableLonghandPropertyWrappers);
1290 static const CSSPropertyID animatableShorthandProperties[] = {
1291 CSSPropertyBackground, // for background-color, background-position, background-image
1292 CSSPropertyBackgroundPosition,
1293 CSSPropertyFont, // for font-size, font-weight
1294 CSSPropertyWebkitMask, // for mask-position
1295 CSSPropertyWebkitMaskPosition,
1296 CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft,
1297 CSSPropertyBorderColor,
1298 CSSPropertyBorderRadius,
1299 CSSPropertyBorderWidth,
1301 CSSPropertyBorderImage,
1302 CSSPropertyBorderSpacing,
1303 CSSPropertyListStyle, // for list-style-image
1307 CSSPropertyWebkitTextStroke,
1308 CSSPropertyWebkitColumnRule,
1309 CSSPropertyWebkitBorderRadius,
1310 CSSPropertyWebkitTransformOrigin
1312 const unsigned animatableShorthandPropertiesCount = WTF_ARRAY_LENGTH(animatableShorthandProperties);
1316 // CSSPropertyVerticalAlign
1318 // Compound properties that have components that should be animatable:
1320 // CSSPropertyWebkitColumns
1321 // CSSPropertyWebkitBoxReflect
1323 // Make sure unused slots have a value
1324 for (int i = 0; i < numCSSProperties; ++i)
1325 m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex;
1327 COMPILE_ASSERT(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount < UCHAR_MAX, numberOfAnimatablePropertiesMustBeLessThanUCharMax);
1328 m_propertyWrappers.reserveInitialCapacity(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount);
1330 // First we put the non-shorthand property wrappers into the map, so the shorthand-building
1331 // code can find them.
1333 for (unsigned i = 0; i < animatableLonghandPropertiesCount; ++i) {
1334 AnimationPropertyWrapperBase* wrapper = animatableLonghandPropertyWrappers[i];
1335 m_propertyWrappers.uncheckedAppend(adoptPtr(wrapper));
1336 indexFromPropertyID(wrapper->property()) = i;
1339 for (size_t i = 0; i < animatableShorthandPropertiesCount; ++i) {
1340 CSSPropertyID propertyID = animatableShorthandProperties[i];
1341 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
1342 if (!shorthand.length())
1345 Vector<AnimationPropertyWrapperBase*> longhandWrappers;
1346 longhandWrappers.reserveInitialCapacity(shorthand.length());
1347 const CSSPropertyID* properties = shorthand.properties();
1348 for (unsigned j = 0; j < shorthand.length(); ++j) {
1349 unsigned wrapperIndex = indexFromPropertyID(properties[j]);
1350 if (wrapperIndex == cInvalidPropertyWrapperIndex)
1352 ASSERT(m_propertyWrappers[wrapperIndex]);
1353 longhandWrappers.uncheckedAppend(m_propertyWrappers[wrapperIndex].get());
1356 m_propertyWrappers.uncheckedAppend(adoptPtr(new ShorthandPropertyWrapper(propertyID, longhandWrappers)));
1357 indexFromPropertyID(propertyID) = animatableLonghandPropertiesCount + i;
1361 static bool gatherEnclosingShorthandProperties(CSSPropertyID property, AnimationPropertyWrapperBase* wrapper, HashSet<CSSPropertyID>& propertySet)
1363 if (!wrapper->isShorthandWrapper())
1366 ShorthandPropertyWrapper* shorthandWrapper = static_cast<ShorthandPropertyWrapper*>(wrapper);
1368 bool contained = false;
1369 for (size_t i = 0; i < shorthandWrapper->propertyWrappers().size(); ++i) {
1370 AnimationPropertyWrapperBase* currWrapper = shorthandWrapper->propertyWrappers()[i];
1372 if (gatherEnclosingShorthandProperties(property, currWrapper, propertySet) || currWrapper->property() == property)
1377 propertySet.add(wrapper->property());
1382 // Returns true if we need to start animation timers
1383 bool CSSPropertyAnimation::blendProperties(const AnimationBase* anim, CSSPropertyID prop, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress)
1385 ASSERT(prop != CSSPropertyInvalid);
1387 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1389 wrapper->blend(anim, dst, a, b, progress);
1390 #if USE(ACCELERATED_COMPOSITING)
1391 return !wrapper->animationIsAccelerated() || !anim->isAccelerated();
1400 #if USE(ACCELERATED_COMPOSITING)
1401 bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(CSSPropertyID prop)
1403 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1404 return wrapper ? wrapper->animationIsAccelerated() : false;
1408 // Note: this is inefficient. It's only called from pauseTransitionAtTime().
1409 HashSet<CSSPropertyID> CSSPropertyAnimation::animatableShorthandsAffectingProperty(CSSPropertyID property)
1411 CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1413 HashSet<CSSPropertyID> foundProperties;
1414 for (unsigned i = 0; i < map.size(); ++i)
1415 gatherEnclosingShorthandProperties(property, map.wrapperForIndex(i), foundProperties);
1417 return foundProperties;
1420 bool CSSPropertyAnimation::propertiesEqual(CSSPropertyID prop, const RenderStyle* a, const RenderStyle* b)
1422 AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1424 return wrapper->equals(a, b);
1428 CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, bool& isShorthand)
1430 CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1432 if (i < 0 || static_cast<unsigned>(i) >= map.size())
1433 return CSSPropertyInvalid;
1435 AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i);
1436 isShorthand = wrapper->isShorthandWrapper();
1437 return wrapper->property();
1440 int CSSPropertyAnimation::getNumProperties()
1442 return CSSPropertyAnimationWrapperMap::instance().size();