Revert use of SVG <mask> elements for -webkit-mask-image (r176798, r177494, r186180)
[WebKit-https.git] / Source / WebCore / page / animation / CSSPropertyAnimation.cpp
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
3  * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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 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. 
17  *
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.
28  */
29
30 #include "config.h"
31 #include "CSSPropertyAnimation.h"
32
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"
53 #include <algorithm>
54 #include <memory>
55 #include <wtf/MathExtras.h>
56 #include <wtf/Noncopyable.h>
57 #include <wtf/RefCounted.h>
58
59 namespace WebCore {
60
61 static inline int blendFunc(const AnimationBase*, int from, int to, double progress)
62 {
63     return blend(from, to, progress);
64 }
65
66 static inline double blendFunc(const AnimationBase*, double from, double to, double progress)
67 {
68     return blend(from, to, progress);
69 }
70
71 static inline float blendFunc(const AnimationBase*, float from, float to, double progress)
72 {
73     return narrowPrecisionToFloat(from + (to - from) * progress);
74 }
75
76 static inline Color blendFunc(const AnimationBase*, const Color& from, const Color& to, double progress)
77 {
78     return blend(from, to, progress);
79 }
80
81 static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress)
82 {
83     return to.blend(from, narrowPrecisionToFloat(progress));
84 }
85
86 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress)
87 {
88     return LengthSize(blendFunc(anim, from.width(), to.width(), progress),
89                       blendFunc(anim, from.height(), to.height(), progress));
90 }
91
92 static inline ShadowStyle blendFunc(const AnimationBase* anim, ShadowStyle from, ShadowStyle to, double progress)
93 {
94     if (from == to)
95         return to;
96
97     double fromVal = from == Normal ? 1 : 0;
98     double toVal = to == Normal ? 1 : 0;
99     double result = blendFunc(anim, fromVal, toVal, progress);
100     return result > 0 ? Normal : Inset;
101 }
102
103 static inline std::unique_ptr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
104 {
105     ASSERT(from && to);
106     if (from->style() != to->style())
107         return std::make_unique<ShadowData>(*to);
108
109     return std::make_unique<ShadowData>(blend(from->location(), to->location(), progress),
110         blend(from->radius(), to->radius(), progress),
111         blend(from->spread(), to->spread(), progress),
112         blendFunc(anim, from->style(), to->style(), progress),
113         from->isWebkitBoxShadow(),
114         blend(from->color(), to->color(), progress));
115 }
116
117 static inline TransformOperations blendFunc(const AnimationBase* animation, const TransformOperations& from, const TransformOperations& to, double progress)
118 {
119     if (animation->isTransformFunctionListValid())
120         return to.blendByMatchingOperations(from, progress);
121     return to.blendByUsingMatrixInterpolation(from, progress, is<RenderBox>(*animation->renderer()) ? downcast<RenderBox>(*animation->renderer()).borderBoxRect().size() : LayoutSize());
122 }
123
124 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, ClipPathOperation* from, ClipPathOperation* to, double progress)
125 {
126     if (!from || !to)
127         return to;
128
129     // Other clip-path operations than BasicShapes can not be animated.
130     if (from->type() != ClipPathOperation::Shape || to->type() != ClipPathOperation::Shape)
131         return to;
132
133     const BasicShape& fromShape = downcast<ShapeClipPathOperation>(*from).basicShape();
134     const BasicShape& toShape = downcast<ShapeClipPathOperation>(*to).basicShape();
135
136     if (!fromShape.canBlend(toShape))
137         return to;
138
139     return ShapeClipPathOperation::create(toShape.blend(fromShape, progress));
140 }
141
142 #if ENABLE(CSS_SHAPES)
143 static inline PassRefPtr<ShapeValue> blendFunc(const AnimationBase*, ShapeValue* from, ShapeValue* to, double progress)
144 {
145     if (!from || !to)
146         return to;
147
148     if (from->type() != ShapeValue::Type::Shape || to->type() != ShapeValue::Type::Shape)
149         return to;
150
151     if (from->cssBox() != to->cssBox())
152         return to;
153
154     const BasicShape& fromShape = *from->shape();
155     const BasicShape& toShape = *to->shape();
156
157     if (!fromShape.canBlend(toShape))
158         return to;
159
160     return ShapeValue::createShapeValue(toShape.blend(fromShape, progress), to->cssBox());
161 }
162 #endif
163
164 static inline PassRefPtr<FilterOperation> blendFunc(const AnimationBase* animation, FilterOperation* fromOp, FilterOperation* toOp, double progress, bool blendToPassthrough = false)
165 {
166     ASSERT(toOp);
167     if (toOp->blendingNeedsRendererSize()) {
168         LayoutSize size = is<RenderBox>(*animation->renderer()) ? downcast<RenderBox>(*animation->renderer()).borderBoxRect().size() : LayoutSize();
169         return toOp->blend(fromOp, progress, size, blendToPassthrough);
170     }
171     return toOp->blend(fromOp, progress, blendToPassthrough);
172 }
173
174 static inline FilterOperations blendFilterOperations(const AnimationBase* anim,  const FilterOperations& from, const FilterOperations& to, double progress)
175 {
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);
184         if (blendedOp)
185             result.operations().append(blendedOp);
186         else {
187             RefPtr<FilterOperation> identityOp = PassthroughFilterOperation::create();
188             if (progress > 0.5)
189                 result.operations().append(toOp ? toOp : identityOp);
190             else
191                 result.operations().append(fromOp ? fromOp : identityOp);
192         }
193     }
194     return result;
195 }
196
197 static inline FilterOperations blendFunc(const AnimationBase* anim, const FilterOperations& from, const FilterOperations& to, double progress, bool animatingBackdropFilter = false)
198 {
199     FilterOperations result;
200
201     // If we have a filter function list, use that to do a per-function animation.
202 #if ENABLE(FILTERS_LEVEL_2)
203     if ((!animatingBackdropFilter && anim->filterFunctionListsMatch()) || (animatingBackdropFilter && anim->backdropFilterFunctionListsMatch()))
204 #else
205     UNUSED_PARAM(animatingBackdropFilter);
206     if (anim->filterFunctionListsMatch())
207 #endif
208
209         result = blendFilterOperations(anim, from, to, progress);
210     else {
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.
213         result = to;
214     }
215
216     return result;
217 }
218
219 static inline PassRefPtr<StyleImage> blendFilter(const AnimationBase* anim, CachedImage* image, const FilterOperations& from, const FilterOperations& to, double progress)
220 {
221     ASSERT(image);
222     FilterOperations filterResult = blendFilterOperations(anim, from, to, progress);
223
224     RefPtr<StyleCachedImage> styledImage = StyleCachedImage::create(image);
225     auto imageValue = CSSImageValue::create(image->url(), styledImage.get());
226     auto filterValue = ComputedStyleExtractor::valueForFilter(anim->renderer()->style(), filterResult, DoNotAdjustPixelValues);
227
228     auto result = CSSFilterImageValue::create(WTF::move(imageValue), WTF::move(filterValue));
229     result.get().setFilterOperations(filterResult);
230     return StyleGeneratedImage::create(WTF::move(result));
231 }
232
233 static inline EVisibility blendFunc(const AnimationBase* anim, EVisibility from, EVisibility to, double progress)
234 {
235     // Any non-zero result means we consider the object to be visible. Only at 0 do we consider the object to be
236     // invisible. The invisible value we use (HIDDEN vs. COLLAPSE) depends on the specified from/to values.
237     double fromVal = from == VISIBLE ? 1. : 0.;
238     double toVal = to == VISIBLE ? 1. : 0.;
239     if (fromVal == toVal)
240         return to;
241     double result = blendFunc(anim, fromVal, toVal, progress);
242     return result > 0. ? VISIBLE : (to != VISIBLE ? to : from);
243 }
244
245 static inline LengthBox blendFunc(const AnimationBase* anim, const LengthBox& from, const LengthBox& to, double progress)
246 {
247     LengthBox result(blendFunc(anim, from.top(), to.top(), progress),
248                      blendFunc(anim, from.right(), to.right(), progress),
249                      blendFunc(anim, from.bottom(), to.bottom(), progress),
250                      blendFunc(anim, from.left(), to.left(), progress));
251     return result;
252 }
253
254 static inline SVGLength blendFunc(const AnimationBase*, const SVGLength& from, const SVGLength& to, double progress)
255 {
256     return to.blend(from, narrowPrecisionToFloat(progress));
257 }
258 static inline Vector<SVGLength> blendFunc(const AnimationBase*, const Vector<SVGLength>& from, const Vector<SVGLength>& to, double progress)
259 {
260     size_t fromLength = from.size();
261     size_t toLength = to.size();
262     if (!fromLength)
263         return !progress ? from : to;
264     if (!toLength)
265         return progress == 1 ? from : to;
266     size_t resultLength = fromLength;
267     if (fromLength != toLength) {
268         if (!remainder(std::max(fromLength, toLength), std::min(fromLength, toLength)))
269             resultLength = std::max(fromLength, toLength);
270         else
271             resultLength = fromLength * toLength;
272     }
273     Vector<SVGLength> result(resultLength);
274     for (size_t i = 0; i < resultLength; ++i)
275         result[i] = to[i % toLength].blend(from[i % fromLength], narrowPrecisionToFloat(progress));
276     return result;
277 }
278
279 static inline PassRefPtr<StyleImage> crossfadeBlend(const AnimationBase*, StyleCachedImage* fromStyleImage, StyleCachedImage* toStyleImage, double progress)
280 {
281     // If progress is at one of the extremes, we want getComputedStyle to show the image,
282     // not a completed cross-fade, so we hand back one of the existing images.
283     if (!progress)
284         return fromStyleImage;
285     if (progress == 1)
286         return toStyleImage;
287
288     auto fromImageValue = CSSImageValue::create(fromStyleImage->cachedImage()->url(), fromStyleImage);
289     auto toImageValue = CSSImageValue::create(toStyleImage->cachedImage()->url(), toStyleImage);
290
291     auto crossfadeValue = CSSCrossfadeValue::create(WTF::move(fromImageValue), WTF::move(toImageValue));
292     crossfadeValue.get().setPercentage(CSSPrimitiveValue::create(progress, CSSPrimitiveValue::CSS_NUMBER));
293     return StyleGeneratedImage::create(WTF::move(crossfadeValue));
294 }
295
296 static inline PassRefPtr<StyleImage> blendFunc(const AnimationBase* anim, StyleImage* from, StyleImage* to, double progress)
297 {
298     if (!from || !to)
299         return to;
300
301     // Animation between two generated images. Cross fade for all other cases.
302     if (is<StyleGeneratedImage>(*from) && is<StyleGeneratedImage>(*to)) {
303         CSSImageGeneratorValue& fromGenerated = downcast<StyleGeneratedImage>(*from).imageValue();
304         CSSImageGeneratorValue& toGenerated = downcast<StyleGeneratedImage>(*to).imageValue();
305
306         if (is<CSSFilterImageValue>(fromGenerated) && is<CSSFilterImageValue>(toGenerated)) {
307             // Animation of generated images just possible if input images are equal.
308             // Otherwise fall back to cross fade animation.
309             CSSFilterImageValue& fromFilter = downcast<CSSFilterImageValue>(fromGenerated);
310             CSSFilterImageValue& toFilter = downcast<CSSFilterImageValue>(toGenerated);
311             if (fromFilter.equalInputImages(toFilter) && fromFilter.cachedImage())
312                 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), toFilter.filterOperations(), progress);
313         }
314
315         if (is<CSSCrossfadeValue>(fromGenerated) && is<CSSCrossfadeValue>(toGenerated)) {
316             CSSCrossfadeValue& fromCrossfade = downcast<CSSCrossfadeValue>(fromGenerated);
317             CSSCrossfadeValue& toCrossfade = downcast<CSSCrossfadeValue>(toGenerated);
318             if (fromCrossfade.equalInputImages(toCrossfade))
319                 return StyleGeneratedImage::create(*toCrossfade.blend(fromCrossfade, progress));
320         }
321
322         // FIXME: Add support for animation between two *gradient() functions.
323         // https://bugs.webkit.org/show_bug.cgi?id=119956
324     } else if (is<StyleGeneratedImage>(*from) && is<StyleCachedImage>(*to)) {
325         CSSImageGeneratorValue& fromGenerated = downcast<StyleGeneratedImage>(*from).imageValue();
326         if (is<CSSFilterImageValue>(fromGenerated)) {
327             CSSFilterImageValue& fromFilter = downcast<CSSFilterImageValue>(fromGenerated);
328             if (fromFilter.cachedImage() && downcast<StyleCachedImage>(*to).cachedImage() == fromFilter.cachedImage())
329                 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), FilterOperations(), progress);
330         }
331         // FIXME: Add interpolation between cross-fade and image source.
332     } else if (is<StyleCachedImage>(*from) && is<StyleGeneratedImage>(*to)) {
333         CSSImageGeneratorValue& toGenerated = downcast<StyleGeneratedImage>(*to).imageValue();
334         if (is<CSSFilterImageValue>(toGenerated)) {
335             CSSFilterImageValue& toFilter = downcast<CSSFilterImageValue>(toGenerated);
336             if (toFilter.cachedImage() && downcast<StyleCachedImage>(*from).cachedImage() == toFilter.cachedImage())
337                 return blendFilter(anim, toFilter.cachedImage(), FilterOperations(), toFilter.filterOperations(), progress);
338         }
339         // FIXME: Add interpolation between image source and cross-fade.
340     }
341
342     // FIXME: Add support cross fade between cached and generated images.
343     // https://bugs.webkit.org/show_bug.cgi?id=78293
344     if (is<StyleCachedImage>(*from) && is<StyleCachedImage>(*to))
345         return crossfadeBlend(anim, downcast<StyleCachedImage>(from), downcast<StyleCachedImage>(to), progress);
346
347     return to;
348 }
349
350 static inline NinePieceImage blendFunc(const AnimationBase* anim, const NinePieceImage& from, const NinePieceImage& to, double progress)
351 {
352     if (!from.hasImage() || !to.hasImage())
353         return to;
354
355     // FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content.
356
357     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())
358         return to;
359
360     if (from.image()->imageSize(anim->renderer(), 1.0) != to.image()->imageSize(anim->renderer(), 1.0))
361         return to;
362
363     RefPtr<StyleImage> newContentImage = blendFunc(anim, from.image(), to.image(), progress);
364
365     return NinePieceImage(newContentImage, from.imageSlices(), from.fill(), from.borderSlices(), from.outset(), from.horizontalRule(), from.verticalRule());
366 }
367
368 class AnimationPropertyWrapperBase {
369     WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase);
370     WTF_MAKE_FAST_ALLOCATED;
371 public:
372     AnimationPropertyWrapperBase(CSSPropertyID prop)
373         : m_prop(prop)
374     {
375     }
376
377     virtual ~AnimationPropertyWrapperBase() { }
378
379     virtual bool isShorthandWrapper() const { return false; }
380     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const = 0;
381     virtual void blend(const AnimationBase*, RenderStyle*, const RenderStyle*, const RenderStyle*, double) const = 0;
382
383     CSSPropertyID property() const { return m_prop; }
384
385     virtual bool animationIsAccelerated() const { return false; }
386
387 private:
388     CSSPropertyID m_prop;
389 };
390
391 template <typename T>
392 class PropertyWrapperGetter : public AnimationPropertyWrapperBase {
393     WTF_MAKE_FAST_ALLOCATED;
394 public:
395     PropertyWrapperGetter(CSSPropertyID prop, T (RenderStyle::*getter)() const)
396         : AnimationPropertyWrapperBase(prop)
397         , m_getter(getter)
398     {
399     }
400
401     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
402     {
403         // If the style pointers are the same, don't bother doing the test.
404         // If either is null, return false. If both are null, return true.
405         if ((!a && !b) || a == b)
406             return true;
407         if (!a || !b)
408             return false;
409         return (a->*m_getter)() == (b->*m_getter)();
410     }
411
412 protected:
413     T (RenderStyle::*m_getter)() const;
414 };
415
416 template <typename T>
417 class PropertyWrapper : public PropertyWrapperGetter<T> {
418     WTF_MAKE_FAST_ALLOCATED;
419 public:
420     PropertyWrapper(CSSPropertyID prop, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
421         : PropertyWrapperGetter<T>(prop, getter)
422         , m_setter(setter)
423     {
424     }
425
426     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
427     {
428         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T>::m_getter)(), (b->*PropertyWrapperGetter<T>::m_getter)(), progress));
429     }
430
431 protected:
432     void (RenderStyle::*m_setter)(T);
433 };
434
435 template <typename T>
436 class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> {
437     WTF_MAKE_FAST_ALLOCATED;
438 public:
439     RefCountedPropertyWrapper(CSSPropertyID prop, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<T>))
440         : PropertyWrapperGetter<T*>(prop, getter)
441         , m_setter(setter)
442     {
443     }
444
445     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
446     {
447         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T*>::m_getter)(), (b->*PropertyWrapperGetter<T*>::m_getter)(), progress));
448     }
449
450 protected:
451     void (RenderStyle::*m_setter)(PassRefPtr<T>);
452 };
453
454 template <typename T>
455 class LengthPropertyWrapper : public PropertyWrapperGetter<const T&> {
456     WTF_MAKE_FAST_ALLOCATED;
457 public:
458     LengthPropertyWrapper(CSSPropertyID prop, const T& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
459         : PropertyWrapperGetter<const T&>(prop, getter)
460         , m_setter(setter)
461     {
462     }
463
464     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
465     {
466         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<const T&>::m_getter)(), (b->*PropertyWrapperGetter<const T&>::m_getter)(), progress));
467     }
468
469 protected:
470     void (RenderStyle::*m_setter)(T);
471 };
472
473 class PropertyWrapperClipPath : public RefCountedPropertyWrapper<ClipPathOperation> {
474     WTF_MAKE_FAST_ALLOCATED;
475 public:
476     PropertyWrapperClipPath(CSSPropertyID prop, ClipPathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ClipPathOperation>))
477         : RefCountedPropertyWrapper<ClipPathOperation>(prop, getter, setter)
478     {
479     }
480 };
481
482 #if ENABLE(CSS_SHAPES)
483 class PropertyWrapperShape : public RefCountedPropertyWrapper<ShapeValue> {
484     WTF_MAKE_FAST_ALLOCATED;
485 public:
486     PropertyWrapperShape(CSSPropertyID prop, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ShapeValue>))
487         : RefCountedPropertyWrapper<ShapeValue>(prop, getter, setter)
488     {
489     }
490 };
491 #endif
492
493 class StyleImagePropertyWrapper : public RefCountedPropertyWrapper<StyleImage> {
494     WTF_MAKE_FAST_ALLOCATED;
495 public:
496     StyleImagePropertyWrapper(CSSPropertyID prop, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<StyleImage>))
497         : RefCountedPropertyWrapper<StyleImage>(prop, getter, setter)
498     {
499     }
500
501     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
502     {
503        // If the style pointers are the same, don't bother doing the test.
504        // If either is null, return false. If both are null, return true.
505        if (a == b)
506            return true;
507        if (!a || !b)
508             return false;
509
510         StyleImage* imageA = (a->*m_getter)();
511         StyleImage* imageB = (b->*m_getter)();
512         return StyleImage::imagesEquivalent(imageA, imageB);
513     }
514 };
515
516 class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
517     WTF_MAKE_FAST_ALLOCATED;
518 public:
519     PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
520         : PropertyWrapperGetter<Color>(prop, getter)
521         , m_setter(setter)
522     {
523     }
524
525     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
526     {
527         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_getter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
528     }
529
530 protected:
531     void (RenderStyle::*m_setter)(const Color&);
532 };
533
534
535 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
536     WTF_MAKE_FAST_ALLOCATED;
537 public:
538     PropertyWrapperAcceleratedOpacity()
539         : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)
540     {
541     }
542
543     virtual bool animationIsAccelerated() const { return true; }
544
545     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
546     {
547         float fromOpacity = a->opacity();
548
549         // This makes sure we put the object being animated into a RenderLayer during the animation
550         dst->setOpacity(blendFunc(anim, (fromOpacity == 1) ? 0.999999f : fromOpacity, b->opacity(), progress));
551     }
552 };
553
554 class PropertyWrapperAcceleratedTransform : public PropertyWrapper<const TransformOperations&> {
555     WTF_MAKE_FAST_ALLOCATED;
556 public:
557     PropertyWrapperAcceleratedTransform()
558         : PropertyWrapper<const TransformOperations&>(CSSPropertyTransform, &RenderStyle::transform, &RenderStyle::setTransform)
559     {
560     }
561
562     virtual bool animationIsAccelerated() const { return true; }
563
564     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
565     {
566         dst->setTransform(blendFunc(anim, a->transform(), b->transform(), progress));
567     }
568 };
569
570 class PropertyWrapperAcceleratedFilter : public PropertyWrapper<const FilterOperations&> {
571     WTF_MAKE_FAST_ALLOCATED;
572 public:
573     PropertyWrapperAcceleratedFilter()
574         : PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter)
575     {
576     }
577
578     virtual bool animationIsAccelerated() const { return true; }
579
580     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
581     {
582         dst->setFilter(blendFunc(anim, a->filter(), b->filter(), progress));
583     }
584 };
585
586 #if ENABLE(FILTERS_LEVEL_2)
587 class PropertyWrapperAcceleratedBackdropFilter : public PropertyWrapper<const FilterOperations&> {
588     WTF_MAKE_FAST_ALLOCATED;
589 public:
590     PropertyWrapperAcceleratedBackdropFilter()
591         : PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitBackdropFilter, &RenderStyle::backdropFilter, &RenderStyle::setBackdropFilter)
592     {
593     }
594
595     virtual bool animationIsAccelerated() const { return true; }
596
597     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
598     {
599         dst->setBackdropFilter(blendFunc(anim, a->backdropFilter(), b->backdropFilter(), progress, true));
600     }
601 };
602 #endif
603
604 static inline size_t shadowListLength(const ShadowData* shadow)
605 {
606     size_t count;
607     for (count = 0; shadow; shadow = shadow->next())
608         ++count;
609     return count;
610 }
611
612 static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow)
613 {
614     DEPRECATED_DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (IntPoint(), 0, 0, Normal, false, Color::transparent));
615     DEPRECATED_DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (IntPoint(), 0, 0, Inset, false, Color::transparent));
616
617     DEPRECATED_DEFINE_STATIC_LOCAL(ShadowData, defaultWebKitBoxShadowData, (IntPoint(), 0, 0, Normal, true, Color::transparent));
618     DEPRECATED_DEFINE_STATIC_LOCAL(ShadowData, defaultInsetWebKitBoxShadowData, (IntPoint(), 0, 0, Inset, true, Color::transparent));
619
620     if (srcShadow)
621         return srcShadow;
622
623     if (otherShadow->style() == Inset)
624         return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData : &defaultInsetShadowData;
625
626     return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData : &defaultShadowData;
627 }
628
629 class PropertyWrapperShadow : public AnimationPropertyWrapperBase {
630     WTF_MAKE_FAST_ALLOCATED;
631 public:
632     PropertyWrapperShadow(CSSPropertyID prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(std::unique_ptr<ShadowData>, bool))
633         : AnimationPropertyWrapperBase(prop)
634         , m_getter(getter)
635         , m_setter(setter)
636     {
637     }
638
639     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
640     {
641         const ShadowData* shadowA = (a->*m_getter)();
642         const ShadowData* shadowB = (b->*m_getter)();
643
644         while (true) {
645             // end of both lists
646             if (!shadowA && !shadowB)
647                 return true;
648
649             // end of just one of the lists
650             if (!shadowA || !shadowB)
651                 return false;
652
653             if (*shadowA != *shadowB)
654                 return false;
655
656             shadowA = shadowA->next();
657             shadowB = shadowB->next();
658         }
659
660         return true;
661     }
662
663     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
664     {
665         const ShadowData* shadowA = (a->*m_getter)();
666         const ShadowData* shadowB = (b->*m_getter)();
667
668         int fromLength = shadowListLength(shadowA);
669         int toLength = shadowListLength(shadowB);
670
671         if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) {
672             (dst->*m_setter)(blendSimpleOrMatchedShadowLists(anim, progress, shadowA, shadowB), false);
673             return;
674         }
675
676         (dst->*m_setter)(blendMismatchedShadowLists(anim, progress, shadowA, shadowB, fromLength, toLength), false);
677     }
678
679 private:
680     std::unique_ptr<ShadowData> blendSimpleOrMatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB) const
681     {
682         std::unique_ptr<ShadowData> newShadowData;
683         ShadowData* lastShadow = 0;
684
685         while (shadowA || shadowB) {
686             const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB);
687             const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA);
688
689             std::unique_ptr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
690             ShadowData* blendedShadowPtr = blendedShadow.get();
691
692             if (!lastShadow)
693                 newShadowData = WTF::move(blendedShadow);
694             else
695                 lastShadow->setNext(WTF::move(blendedShadow));
696
697             lastShadow = blendedShadowPtr;
698
699             shadowA = shadowA ? shadowA->next() : 0;
700             shadowB = shadowB ? shadowB->next() : 0;
701         }
702
703         return newShadowData;
704     }
705
706     std::unique_ptr<ShadowData> blendMismatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength) const
707     {
708         // The shadows in ShadowData are stored in reverse order, so when animating mismatched lists,
709         // reverse them and match from the end.
710         Vector<const ShadowData*, 4> fromShadows(fromLength);
711         for (int i = fromLength - 1; i >= 0; --i) {
712             fromShadows[i] = shadowA;
713             shadowA = shadowA->next();
714         }
715
716         Vector<const ShadowData*, 4> toShadows(toLength);
717         for (int i = toLength - 1; i >= 0; --i) {
718             toShadows[i] = shadowB;
719             shadowB = shadowB->next();
720         }
721
722         std::unique_ptr<ShadowData> newShadowData;
723
724         int maxLength = std::max(fromLength, toLength);
725         for (int i = 0; i < maxLength; ++i) {
726             const ShadowData* fromShadow = i < fromLength ? fromShadows[i] : 0;
727             const ShadowData* toShadow = i < toLength ? toShadows[i] : 0;
728
729             const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow);
730             const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow);
731
732             std::unique_ptr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
733             // Insert at the start of the list to preserve the order.
734             blendedShadow->setNext(WTF::move(newShadowData));
735             newShadowData = WTF::move(blendedShadow);
736         }
737
738         return newShadowData;
739     }
740
741     const ShadowData* (RenderStyle::*m_getter)() const;
742     void (RenderStyle::*m_setter)(std::unique_ptr<ShadowData>, bool);
743 };
744
745 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
746     WTF_MAKE_FAST_ALLOCATED;
747 public:
748     PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
749         : AnimationPropertyWrapperBase(prop)
750         , m_getter(getter)
751         , m_setter(setter)
752     {
753     }
754
755     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
756     {
757         Color fromColor = (a->*m_getter)();
758         Color toColor = (b->*m_getter)();
759
760         if (!fromColor.isValid() && !toColor.isValid())
761             return true;
762
763         if (!fromColor.isValid())
764             fromColor = a->color();
765         if (!toColor.isValid())
766             toColor = b->color();
767
768         return fromColor == toColor;
769     }
770
771     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
772     {
773         Color fromColor = (a->*m_getter)();
774         Color toColor = (b->*m_getter)();
775
776         if (!fromColor.isValid() && !toColor.isValid())
777             return;
778
779         if (!fromColor.isValid())
780             fromColor = a->color();
781         if (!toColor.isValid())
782             toColor = b->color();
783         (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
784     }
785
786 private:
787     Color (RenderStyle::*m_getter)() const;
788     void (RenderStyle::*m_setter)(const Color&);
789 };
790
791
792 enum MaybeInvalidColorTag { MaybeInvalidColor };
793 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
794     WTF_MAKE_FAST_ALLOCATED;
795 public:
796     PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
797                                         Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
798         : AnimationPropertyWrapperBase(prop)
799         , m_wrapper(std::make_unique<PropertyWrapperColor>(prop, getter, setter))
800         , m_visitedWrapper(std::make_unique<PropertyWrapperColor>(prop, visitedGetter, visitedSetter))
801     {
802     }
803     PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
804                                         Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
805         : AnimationPropertyWrapperBase(prop)
806         , m_wrapper(std::make_unique<PropertyWrapperMaybeInvalidColor>(prop, getter, setter))
807         , m_visitedWrapper(std::make_unique<PropertyWrapperMaybeInvalidColor>(prop, visitedGetter, visitedSetter))
808     {
809     }
810     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
811     {
812         return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
813     }
814     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
815     {
816         m_wrapper->blend(anim, dst, a, b, progress);
817         m_visitedWrapper->blend(anim, dst, a, b, progress);
818     }
819
820 private:
821     std::unique_ptr<AnimationPropertyWrapperBase> m_wrapper;
822     std::unique_ptr<AnimationPropertyWrapperBase> m_visitedWrapper;
823 };
824
825 // Wrapper base class for an animatable property in a FillLayer
826 class FillLayerAnimationPropertyWrapperBase {
827     WTF_MAKE_FAST_ALLOCATED;
828 public:
829     FillLayerAnimationPropertyWrapperBase()
830     {
831     }
832
833     virtual ~FillLayerAnimationPropertyWrapperBase() { }
834
835     virtual bool equals(const FillLayer*, const FillLayer*) const = 0;
836     virtual void blend(const AnimationBase*, FillLayer*, const FillLayer*, const FillLayer*, double) const = 0;
837 };
838
839 template <typename T>
840 class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase {
841     WTF_MAKE_FAST_ALLOCATED;
842     WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter);
843 public:
844     FillLayerPropertyWrapperGetter(T (FillLayer::*getter)() const)
845         : m_getter(getter)
846     {
847     }
848
849     virtual bool equals(const FillLayer* a, const FillLayer* b) const
850     {
851        // If the style pointers are the same, don't bother doing the test.
852        // If either is null, return false. If both are null, return true.
853        if ((!a && !b) || a == b)
854            return true;
855        if (!a || !b)
856             return false;
857         return (a->*m_getter)() == (b->*m_getter)();
858     }
859
860 protected:
861     T (FillLayer::*m_getter)() const;
862 };
863
864 template <typename T>
865 class FillLayerPropertyWrapper : public FillLayerPropertyWrapperGetter<const T&> {
866     WTF_MAKE_FAST_ALLOCATED;
867 public:
868     FillLayerPropertyWrapper(const T& (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
869         : FillLayerPropertyWrapperGetter<const T&>(getter)
870         , m_setter(setter)
871     {
872     }
873
874     virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
875     {
876         (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), progress));
877     }
878
879 protected:
880     void (FillLayer::*m_setter)(T);
881 };
882
883 template <typename T>
884 class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> {
885     WTF_MAKE_FAST_ALLOCATED;
886 public:
887     FillLayerRefCountedPropertyWrapper(T* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<T>))
888         : FillLayerPropertyWrapperGetter<T*>(getter)
889         , m_setter(setter)
890     {
891     }
892
893     virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
894     {
895         (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), progress));
896     }
897
898 protected:
899     void (FillLayer::*m_setter)(PassRefPtr<T>);
900 };
901
902 class FillLayerStyleImagePropertyWrapper : public FillLayerRefCountedPropertyWrapper<StyleImage> {
903     WTF_MAKE_FAST_ALLOCATED;
904 public:
905     FillLayerStyleImagePropertyWrapper(StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<StyleImage>))
906         : FillLayerRefCountedPropertyWrapper<StyleImage>(getter, setter)
907     {
908     }
909
910     virtual bool equals(const FillLayer* a, const FillLayer* b) const
911     {
912        // If the style pointers are the same, don't bother doing the test.
913        // If either is null, return false. If both are null, return true.
914        if (a == b)
915            return true;
916        if (!a || !b)
917             return false;
918
919         StyleImage* imageA = (a->*m_getter)();
920         StyleImage* imageB = (b->*m_getter)();
921         return StyleImage::imagesEquivalent(imageA, imageB);
922     }
923 };
924
925 class FillLayersPropertyWrapper : public AnimationPropertyWrapperBase {
926     WTF_MAKE_FAST_ALLOCATED;
927 public:
928     typedef const FillLayer* (RenderStyle::*LayersGetter)() const;
929     typedef FillLayer& (RenderStyle::*LayersAccessor)();
930
931     FillLayersPropertyWrapper(CSSPropertyID prop, LayersGetter getter, LayersAccessor accessor)
932         : AnimationPropertyWrapperBase(prop)
933         , m_layersGetter(getter)
934         , m_layersAccessor(accessor)
935     {
936         switch (prop) {
937         case CSSPropertyBackgroundPositionX:
938         case CSSPropertyWebkitMaskPositionX:
939             m_fillLayerPropertyWrapper = std::make_unique<FillLayerPropertyWrapper<Length>>(&FillLayer::xPosition, &FillLayer::setXPosition);
940             break;
941         case CSSPropertyBackgroundPositionY:
942         case CSSPropertyWebkitMaskPositionY:
943             m_fillLayerPropertyWrapper = std::make_unique<FillLayerPropertyWrapper<Length>>(&FillLayer::yPosition, &FillLayer::setYPosition);
944             break;
945         case CSSPropertyBackgroundSize:
946         case CSSPropertyWebkitBackgroundSize:
947         case CSSPropertyWebkitMaskSize:
948             m_fillLayerPropertyWrapper = std::make_unique<FillLayerPropertyWrapper<LengthSize>>(&FillLayer::sizeLength, &FillLayer::setSizeLength);
949             break;
950         case CSSPropertyBackgroundImage:
951             m_fillLayerPropertyWrapper = std::make_unique<FillLayerStyleImagePropertyWrapper>(&FillLayer::image, &FillLayer::setImage);
952             break;
953         default:
954             break;
955         }
956     }
957
958     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
959     {
960         const FillLayer* fromLayer = (a->*m_layersGetter)();
961         const FillLayer* toLayer = (b->*m_layersGetter)();
962
963         while (fromLayer && toLayer) {
964             if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer))
965                 return false;
966
967             fromLayer = fromLayer->next();
968             toLayer = toLayer->next();
969         }
970
971         return true;
972     }
973
974     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
975     {
976         const FillLayer* aLayer = (a->*m_layersGetter)();
977         const FillLayer* bLayer = (b->*m_layersGetter)();
978         FillLayer* dstLayer = &(dst->*m_layersAccessor)();
979
980         while (aLayer && bLayer && dstLayer) {
981             m_fillLayerPropertyWrapper->blend(anim, dstLayer, aLayer, bLayer, progress);
982             aLayer = aLayer->next();
983             bLayer = bLayer->next();
984             dstLayer = dstLayer->next();
985         }
986     }
987
988 private:
989     std::unique_ptr<FillLayerAnimationPropertyWrapperBase> m_fillLayerPropertyWrapper;
990
991     LayersGetter m_layersGetter;
992     LayersAccessor m_layersAccessor;
993 };
994
995 class ShorthandPropertyWrapper : public AnimationPropertyWrapperBase {
996     WTF_MAKE_FAST_ALLOCATED;
997 public:
998     ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers)
999         : AnimationPropertyWrapperBase(property)
1000         , m_propertyWrappers(WTF::move(longhandWrappers))
1001     {
1002     }
1003
1004     virtual bool isShorthandWrapper() const { return true; }
1005
1006     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1007     {
1008         for (auto& wrapper : m_propertyWrappers) {
1009             if (!wrapper->equals(a, b))
1010                 return false;
1011         }
1012         return true;
1013     }
1014
1015     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1016     {
1017         for (auto& wrapper : m_propertyWrappers)
1018             wrapper->blend(anim, dst, a, b, progress);
1019     }
1020
1021     const Vector<AnimationPropertyWrapperBase*>& propertyWrappers() const { return m_propertyWrappers; }
1022
1023 private:
1024     Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
1025 };
1026
1027 class PropertyWrapperFlex : public AnimationPropertyWrapperBase {
1028     WTF_MAKE_FAST_ALLOCATED;
1029 public:
1030     PropertyWrapperFlex()
1031         : AnimationPropertyWrapperBase(CSSPropertyFlex)
1032     {
1033     }
1034
1035     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1036     {
1037         // If the style pointers are the same, don't bother doing the test.
1038         // If either is null, return false. If both are null, return true.
1039         if ((!a && !b) || a == b)
1040             return true;
1041         if (!a || !b)
1042             return false;
1043
1044         return a->flexBasis() == b->flexBasis() && a->flexGrow() == b->flexGrow() && a->flexShrink() == b->flexShrink();
1045     }
1046
1047     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1048     {
1049         dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progress));
1050         dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress));
1051         dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), progress));
1052     }
1053 };
1054
1055 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
1056     WTF_MAKE_FAST_ALLOCATED;
1057 public:
1058     PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (RenderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
1059         : AnimationPropertyWrapperBase(prop)
1060         , m_paintTypeGetter(paintTypeGetter)
1061         , m_getter(getter)
1062         , m_setter(setter)
1063     {
1064     }
1065
1066     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1067     {
1068         if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
1069             return false;
1070
1071         // We only support animations between SVGPaints that are pure Color values.
1072         // For everything else we must return true for this method, otherwise
1073         // we will try to animate between values forever.
1074         if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) {
1075             Color fromColor = (a->*m_getter)();
1076             Color toColor = (b->*m_getter)();
1077
1078             if (!fromColor.isValid() && !toColor.isValid())
1079                 return true;
1080
1081             if (!fromColor.isValid())
1082                 fromColor = Color();
1083             if (!toColor.isValid())
1084                 toColor = Color();
1085
1086             return fromColor == toColor;
1087         }
1088         return true;
1089     }
1090
1091     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1092     {
1093         if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
1094             || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
1095             return;
1096
1097         Color fromColor = (a->*m_getter)();
1098         Color toColor = (b->*m_getter)();
1099
1100         if (!fromColor.isValid() && !toColor.isValid())
1101             return;
1102
1103         if (!fromColor.isValid())
1104             fromColor = Color();
1105         if (!toColor.isValid())
1106             toColor = Color();
1107         (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
1108     }
1109
1110 private:
1111     const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
1112     Color (RenderStyle::*m_getter)() const;
1113     void (RenderStyle::*m_setter)(const Color&);
1114 };
1115
1116 class CSSPropertyAnimationWrapperMap {
1117     WTF_MAKE_FAST_ALLOCATED;
1118 public:
1119     static CSSPropertyAnimationWrapperMap& singleton()
1120     {
1121         // FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last AnimationController is destroyed?
1122         static NeverDestroyed<CSSPropertyAnimationWrapperMap> map;
1123         return map;
1124     }
1125
1126     AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID)
1127     {
1128         if (propertyID < firstCSSProperty || propertyID > lastCSSProperty)
1129             return 0;
1130
1131         unsigned wrapperIndex = indexFromPropertyID(propertyID);
1132         if (wrapperIndex == cInvalidPropertyWrapperIndex)
1133             return 0;
1134
1135         return m_propertyWrappers[wrapperIndex].get();
1136     }
1137
1138     AnimationPropertyWrapperBase* wrapperForIndex(unsigned index)
1139     {
1140         ASSERT(index < m_propertyWrappers.size());
1141         return m_propertyWrappers[index].get();
1142     }
1143
1144     unsigned size()
1145     {
1146         return m_propertyWrappers.size();
1147     }
1148
1149 private:
1150     CSSPropertyAnimationWrapperMap();
1151     ~CSSPropertyAnimationWrapperMap() = delete;
1152
1153     unsigned char& indexFromPropertyID(CSSPropertyID propertyID)
1154     {
1155         return m_propertyToIdMap[propertyID - firstCSSProperty];
1156     }
1157
1158     Vector<std::unique_ptr<AnimationPropertyWrapperBase>> m_propertyWrappers;
1159     unsigned char m_propertyToIdMap[numCSSProperties];
1160
1161     static const unsigned char cInvalidPropertyWrapperIndex = UCHAR_MAX;
1162
1163     friend class WTF::NeverDestroyed<CSSPropertyAnimationWrapperMap>;
1164 };
1165
1166 CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap()
1167 {
1168     // build the list of property wrappers to do the comparisons and blends
1169     AnimationPropertyWrapperBase* animatableLonghandPropertyWrappers[] = {
1170         new LengthPropertyWrapper<Length>(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft),
1171         new LengthPropertyWrapper<Length>(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight),
1172         new LengthPropertyWrapper<Length>(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop),
1173         new LengthPropertyWrapper<Length>(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom),
1174
1175         new LengthPropertyWrapper<Length>(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth),
1176         new LengthPropertyWrapper<Length>(CSSPropertyMinWidth, &RenderStyle::minWidth, &RenderStyle::setMinWidth),
1177         new LengthPropertyWrapper<Length>(CSSPropertyMaxWidth, &RenderStyle::maxWidth, &RenderStyle::setMaxWidth),
1178
1179         new LengthPropertyWrapper<Length>(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight),
1180         new LengthPropertyWrapper<Length>(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight),
1181         new LengthPropertyWrapper<Length>(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight),
1182
1183         new PropertyWrapperFlex(),
1184
1185         new PropertyWrapper<float>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth),
1186         new PropertyWrapper<float>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth),
1187         new PropertyWrapper<float>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth),
1188         new PropertyWrapper<float>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth),
1189         new LengthPropertyWrapper<Length>(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft),
1190         new LengthPropertyWrapper<Length>(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight),
1191         new LengthPropertyWrapper<Length>(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop),
1192         new LengthPropertyWrapper<Length>(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom),
1193         new LengthPropertyWrapper<Length>(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft),
1194         new LengthPropertyWrapper<Length>(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight),
1195         new LengthPropertyWrapper<Length>(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop),
1196         new LengthPropertyWrapper<Length>(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom),
1197         new PropertyWrapperVisitedAffectedColor(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::visitedLinkColor, &RenderStyle::setVisitedLinkColor),
1198
1199         new PropertyWrapperVisitedAffectedColor(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor),
1200
1201         new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
1202         new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage),
1203         new StyleImagePropertyWrapper(CSSPropertyWebkitMaskImage, &RenderStyle::maskImage, &RenderStyle::setMaskImage),
1204
1205         new StyleImagePropertyWrapper(CSSPropertyBorderImageSource, &RenderStyle::borderImageSource, &RenderStyle::setBorderImageSource),
1206         new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageSlice, &RenderStyle::borderImageSlices, &RenderStyle::setBorderImageSlices),
1207         new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageWidth, &RenderStyle::borderImageWidth, &RenderStyle::setBorderImageWidth),
1208         new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageOutset, &RenderStyle::borderImageOutset, &RenderStyle::setBorderImageOutset),
1209
1210         new StyleImagePropertyWrapper(CSSPropertyWebkitMaskBoxImageSource, &RenderStyle::maskBoxImageSource, &RenderStyle::setMaskBoxImageSource),
1211         new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage),
1212
1213         new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionX, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
1214         new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionY, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
1215         new FillLayersPropertyWrapper(CSSPropertyBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
1216         new FillLayersPropertyWrapper(CSSPropertyWebkitBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::ensureBackgroundLayers),
1217
1218         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
1219         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
1220         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::ensureMaskLayers),
1221
1222         new PropertyWrapper<float>(CSSPropertyFontSize,
1223             // Must pass a specified size to setFontSize if Text Autosizing is enabled, but a computed size
1224             // if text zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1225             // FIXME: Find some way to assert that text zoom isn't activated when Text Autosizing is compiled in.
1226 #if ENABLE(TEXT_AUTOSIZING)
1227             &RenderStyle::specifiedFontSize,
1228 #else
1229             &RenderStyle::computedFontSize,
1230 #endif
1231             &RenderStyle::setFontSize),
1232         new PropertyWrapper<unsigned short>(CSSPropertyColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth),
1233         new PropertyWrapper<float>(CSSPropertyColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap),
1234         new PropertyWrapper<unsigned short>(CSSPropertyColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount),
1235         new PropertyWrapper<float>(CSSPropertyColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth),
1236         new PropertyWrapper<short>(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing),
1237         new PropertyWrapper<short>(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing),
1238         new PropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::zIndex, &RenderStyle::setZIndex),
1239         new PropertyWrapper<short>(CSSPropertyOrphans, &RenderStyle::orphans, &RenderStyle::setOrphans),
1240         new PropertyWrapper<short>(CSSPropertyWidows, &RenderStyle::widows, &RenderStyle::setWidows),
1241         new LengthPropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight),
1242         new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset),
1243         new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth),
1244         new PropertyWrapper<float>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing),
1245         new LengthPropertyWrapper<Length>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing),
1246         new LengthPropertyWrapper<Length>(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent),
1247
1248         new PropertyWrapper<float>(CSSPropertyPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective),
1249         new LengthPropertyWrapper<Length>(CSSPropertyPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX),
1250         new LengthPropertyWrapper<Length>(CSSPropertyPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY),
1251         new LengthPropertyWrapper<Length>(CSSPropertyTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX),
1252         new LengthPropertyWrapper<Length>(CSSPropertyTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY),
1253         new PropertyWrapper<float>(CSSPropertyTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ),
1254         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius),
1255         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius),
1256         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius),
1257         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius),
1258         new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility),
1259         new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoomWithoutReturnValue),
1260
1261         new LengthPropertyWrapper<LengthBox>(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip),
1262
1263         new PropertyWrapperAcceleratedOpacity(),
1264         new PropertyWrapperAcceleratedTransform(),
1265         new PropertyWrapperAcceleratedFilter(),
1266 #if ENABLE(FILTERS_LEVEL_2)
1267         new PropertyWrapperAcceleratedBackdropFilter(),
1268 #endif
1269         new PropertyWrapperClipPath(CSSPropertyWebkitClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath),
1270
1271 #if ENABLE(CSS_SHAPES)
1272         new PropertyWrapperShape(CSSPropertyWebkitShapeOutside, &RenderStyle::shapeOutside, &RenderStyle::setShapeOutside),
1273         new LengthPropertyWrapper<Length>(CSSPropertyWebkitShapeMargin, &RenderStyle::shapeMargin, &RenderStyle::setShapeMargin),
1274         new PropertyWrapper<float>(CSSPropertyWebkitShapeImageThreshold, &RenderStyle::shapeImageThreshold, &RenderStyle::setShapeImageThreshold),
1275 #endif
1276
1277         new PropertyWrapperVisitedAffectedColor(CSSPropertyColumnRuleColor, MaybeInvalidColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor, &RenderStyle::visitedLinkColumnRuleColor, &RenderStyle::setVisitedLinkColumnRuleColor),
1278         new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextStrokeColor, MaybeInvalidColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor, &RenderStyle::visitedLinkTextStrokeColor, &RenderStyle::setVisitedLinkTextStrokeColor),
1279         new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextFillColor, MaybeInvalidColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor, &RenderStyle::visitedLinkTextFillColor, &RenderStyle::setVisitedLinkTextFillColor),
1280         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderLeftColor, MaybeInvalidColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor, &RenderStyle::visitedLinkBorderLeftColor, &RenderStyle::setVisitedLinkBorderLeftColor),
1281         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderRightColor, MaybeInvalidColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor, &RenderStyle::visitedLinkBorderRightColor, &RenderStyle::setVisitedLinkBorderRightColor),
1282         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderTopColor, MaybeInvalidColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor, &RenderStyle::visitedLinkBorderTopColor, &RenderStyle::setVisitedLinkBorderTopColor),
1283         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderBottomColor, MaybeInvalidColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor, &RenderStyle::visitedLinkBorderBottomColor, &RenderStyle::setVisitedLinkBorderBottomColor),
1284         new PropertyWrapperVisitedAffectedColor(CSSPropertyOutlineColor, MaybeInvalidColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::visitedLinkOutlineColor, &RenderStyle::setVisitedLinkOutlineColor),
1285
1286         new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1287         new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1288         new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow),
1289
1290         new PropertyWrapperSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor),
1291         new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity),
1292
1293         new PropertyWrapperSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor),
1294         new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity),
1295         new PropertyWrapper< Vector<SVGLength>>(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray),
1296         new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit),
1297
1298         new LengthPropertyWrapper<Length>(CSSPropertyCx, &RenderStyle::cx, &RenderStyle::setCx),
1299         new LengthPropertyWrapper<Length>(CSSPropertyCy, &RenderStyle::cy, &RenderStyle::setCy),
1300         new LengthPropertyWrapper<Length>(CSSPropertyR, &RenderStyle::r, &RenderStyle::setR),
1301         new LengthPropertyWrapper<Length>(CSSPropertyRx, &RenderStyle::rx, &RenderStyle::setRx),
1302         new LengthPropertyWrapper<Length>(CSSPropertyRy, &RenderStyle::ry, &RenderStyle::setRy),
1303         new LengthPropertyWrapper<Length>(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset),
1304         new LengthPropertyWrapper<Length>(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth),
1305         new LengthPropertyWrapper<Length>(CSSPropertyX, &RenderStyle::x, &RenderStyle::setX),
1306         new LengthPropertyWrapper<Length>(CSSPropertyY, &RenderStyle::y, &RenderStyle::setY),
1307
1308         new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity),
1309         new PropertyWrapperMaybeInvalidColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor),
1310
1311         new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity),
1312         new PropertyWrapperMaybeInvalidColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor),
1313
1314         new PropertyWrapperMaybeInvalidColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor),
1315
1316         new PropertyWrapper<SVGLength>(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue),
1317         new PropertyWrapper<SVGLength>(CSSPropertyKerning, &RenderStyle::kerning, &RenderStyle::setKerning),
1318     };
1319     const unsigned animatableLonghandPropertiesCount = WTF_ARRAY_LENGTH(animatableLonghandPropertyWrappers);
1320
1321     static const CSSPropertyID animatableShorthandProperties[] = {
1322         CSSPropertyBackground, // for background-color, background-position, background-image
1323         CSSPropertyBackgroundPosition,
1324         CSSPropertyFont, // for font-size, font-weight
1325         CSSPropertyWebkitMask, // for mask-position
1326         CSSPropertyWebkitMaskPosition,
1327         CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft,
1328         CSSPropertyBorderColor,
1329         CSSPropertyBorderRadius,
1330         CSSPropertyBorderWidth,
1331         CSSPropertyBorder,
1332         CSSPropertyBorderImage,
1333         CSSPropertyBorderSpacing,
1334         CSSPropertyListStyle, // for list-style-image
1335         CSSPropertyMargin,
1336         CSSPropertyOutline,
1337         CSSPropertyPadding,
1338         CSSPropertyWebkitTextStroke,
1339         CSSPropertyColumnRule,
1340         CSSPropertyWebkitBorderRadius,
1341         CSSPropertyTransformOrigin
1342     };
1343     const unsigned animatableShorthandPropertiesCount = WTF_ARRAY_LENGTH(animatableShorthandProperties);
1344
1345     // TODO:
1346     //
1347     //  CSSPropertyVerticalAlign
1348     //
1349     // Compound properties that have components that should be animatable:
1350     //
1351     //  CSSPropertyColumns
1352     //  CSSPropertyWebkitBoxReflect
1353
1354     // Make sure unused slots have a value
1355     for (int i = 0; i < numCSSProperties; ++i)
1356         m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex;
1357
1358     COMPILE_ASSERT(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount < UCHAR_MAX, numberOfAnimatablePropertiesMustBeLessThanUCharMax);
1359     m_propertyWrappers.reserveInitialCapacity(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount);
1360
1361     // First we put the non-shorthand property wrappers into the map, so the shorthand-building
1362     // code can find them.
1363
1364     for (unsigned i = 0; i < animatableLonghandPropertiesCount; ++i) {
1365         AnimationPropertyWrapperBase* wrapper = animatableLonghandPropertyWrappers[i];
1366         m_propertyWrappers.uncheckedAppend(std::unique_ptr<AnimationPropertyWrapperBase>(wrapper));
1367         indexFromPropertyID(wrapper->property()) = i;
1368     }
1369
1370     for (size_t i = 0; i < animatableShorthandPropertiesCount; ++i) {
1371         CSSPropertyID propertyID = animatableShorthandProperties[i];
1372         StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
1373         if (!shorthand.length())
1374             continue;
1375
1376         Vector<AnimationPropertyWrapperBase*> longhandWrappers;
1377         longhandWrappers.reserveInitialCapacity(shorthand.length());
1378         const CSSPropertyID* properties = shorthand.properties();
1379         for (unsigned j = 0; j < shorthand.length(); ++j) {
1380             unsigned wrapperIndex = indexFromPropertyID(properties[j]);
1381             if (wrapperIndex == cInvalidPropertyWrapperIndex)
1382                 continue;
1383             ASSERT(m_propertyWrappers[wrapperIndex]);
1384             longhandWrappers.uncheckedAppend(m_propertyWrappers[wrapperIndex].get());
1385         }
1386
1387         m_propertyWrappers.uncheckedAppend(std::make_unique<ShorthandPropertyWrapper>(propertyID, WTF::move(longhandWrappers)));
1388         indexFromPropertyID(propertyID) = animatableLonghandPropertiesCount + i;
1389     }
1390 }
1391
1392 static bool gatherEnclosingShorthandProperties(CSSPropertyID property, AnimationPropertyWrapperBase* wrapper, HashSet<CSSPropertyID>& propertySet)
1393 {
1394     if (!wrapper->isShorthandWrapper())
1395         return false;
1396
1397     ShorthandPropertyWrapper* shorthandWrapper = static_cast<ShorthandPropertyWrapper*>(wrapper);
1398     bool contained = false;
1399     for (auto& currWrapper : shorthandWrapper->propertyWrappers()) {
1400         if (gatherEnclosingShorthandProperties(property, currWrapper, propertySet) || currWrapper->property() == property)
1401             contained = true;
1402     }
1403
1404     if (contained)
1405         propertySet.add(wrapper->property());
1406
1407     return contained;
1408 }
1409
1410 // Returns true if we need to start animation timers
1411 bool CSSPropertyAnimation::blendProperties(const AnimationBase* anim, CSSPropertyID prop, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress)
1412 {
1413     ASSERT(prop != CSSPropertyInvalid);
1414
1415     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(prop);
1416     if (wrapper) {
1417         wrapper->blend(anim, dst, a, b, progress);
1418         return !wrapper->animationIsAccelerated() || !anim->isAccelerated();
1419     }
1420
1421     return false;
1422 }
1423
1424 bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(CSSPropertyID prop)
1425 {
1426     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(prop);
1427     return wrapper ? wrapper->animationIsAccelerated() : false;
1428 }
1429
1430 // Note: this is inefficient. It's only called from pauseTransitionAtTime().
1431 HashSet<CSSPropertyID> CSSPropertyAnimation::animatableShorthandsAffectingProperty(CSSPropertyID property)
1432 {
1433     CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::singleton();
1434
1435     HashSet<CSSPropertyID> foundProperties;
1436     for (unsigned i = 0; i < map.size(); ++i)
1437         gatherEnclosingShorthandProperties(property, map.wrapperForIndex(i), foundProperties);
1438
1439     return foundProperties;
1440 }
1441
1442 bool CSSPropertyAnimation::propertiesEqual(CSSPropertyID prop, const RenderStyle* a, const RenderStyle* b)
1443 {
1444     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::singleton().wrapperForProperty(prop);
1445     if (wrapper)
1446         return wrapper->equals(a, b);
1447     return true;
1448 }
1449
1450 CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, bool& isShorthand)
1451 {
1452     CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::singleton();
1453
1454     if (i < 0 || static_cast<unsigned>(i) >= map.size())
1455         return CSSPropertyInvalid;
1456
1457     AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i);
1458     isShorthand = wrapper->isShorthandWrapper();
1459     return wrapper->property();
1460 }
1461
1462 int CSSPropertyAnimation::getNumProperties()
1463 {
1464     return CSSPropertyAnimationWrapperMap::singleton().size();
1465 }
1466
1467 }