CSSFilterImageValue constructor should require both image and filter.
[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 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. 
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 <wtf/MathExtras.h>
55 #include <wtf/Noncopyable.h>
56 #include <wtf/RefCounted.h>
57
58 namespace WebCore {
59
60 static inline int blendFunc(const AnimationBase*, int from, int to, double progress)
61 {
62     return blend(from, to, progress);
63 }
64
65 static inline unsigned blendFunc(const AnimationBase*, unsigned from, unsigned to, double progress)
66 {
67     return blend(from, to, progress);
68 }
69
70 static inline double blendFunc(const AnimationBase*, double from, double to, double progress)
71 {
72     return blend(from, to, progress);
73 }
74
75 static inline float blendFunc(const AnimationBase*, float from, float to, double progress)
76 {
77     return narrowPrecisionToFloat(from + (to - from) * progress);
78 }
79
80 static inline Color blendFunc(const AnimationBase*, const Color& from, const Color& to, double progress)
81 {
82     return blend(from, to, progress);
83 }
84
85 static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress)
86 {
87     return to.blend(from, narrowPrecisionToFloat(progress));
88 }
89
90 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress)
91 {
92     return LengthSize(blendFunc(anim, from.width(), to.width(), progress),
93                       blendFunc(anim, from.height(), to.height(), progress));
94 }
95
96 static inline ShadowStyle blendFunc(const AnimationBase* anim, ShadowStyle from, ShadowStyle to, double progress)
97 {
98     if (from == to)
99         return to;
100
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;
105 }
106
107 static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
108 {
109     ASSERT(from && to);
110     if (from->style() != to->style())
111         return adoptPtr(new ShadowData(*to));
112
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)));
119 }
120
121 static inline TransformOperations blendFunc(const AnimationBase* anim, const TransformOperations& from, const TransformOperations& to, double progress)
122 {
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());
126 }
127
128 static inline PassRefPtr<ClipPathOperation> blendFunc(const AnimationBase*, ClipPathOperation* from, ClipPathOperation* to, double progress)
129 {
130     if (!from || !to)
131         return to;
132
133     // Other clip-path operations than BasicShapes can not be animated.
134     if (from->type() != ClipPathOperation::SHAPE || to->type() != ClipPathOperation::SHAPE)
135         return to;
136
137     const BasicShape* fromShape = static_cast<ShapeClipPathOperation*>(from)->basicShape();
138     const BasicShape* toShape = static_cast<ShapeClipPathOperation*>(to)->basicShape();
139
140     if (!fromShape->canBlend(toShape))
141         return to;
142
143     return ShapeClipPathOperation::create(toShape->blend(fromShape, progress));
144 }
145
146 #if ENABLE(CSS_SHAPES)
147 static inline PassRefPtr<ShapeValue> blendFunc(const AnimationBase*, ShapeValue* from, ShapeValue* to, double progress)
148 {
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)
151         return to;
152
153     const BasicShape* fromShape = from->shape();
154     const BasicShape* toShape = to->shape();
155
156     if (!fromShape->canBlend(toShape))
157         return to;
158
159     return ShapeValue::createShapeValue(toShape->blend(fromShape, progress));
160 }
161 #endif
162
163 #if ENABLE(CSS_FILTERS)
164 static inline PassRefPtr<FilterOperation> blendFunc(const AnimationBase* anim, FilterOperation* fromOp, FilterOperation* toOp, double progress, bool blendToPassthrough = false)
165 {
166     ASSERT(toOp);
167     if (toOp->blendingNeedsRendererSize()) {
168         LayoutSize size = anim->renderer()->isBox() ? toRenderBox(anim->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)
198 {
199     FilterOperations result;
200
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);
204     else {
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.
207         result = to;
208     }
209
210     return result;
211 }
212
213 static inline PassRefPtr<StyleImage> blendFilter(const AnimationBase* anim, CachedImage* image, const FilterOperations& from, const FilterOperations& to, double progress)
214 {
215     ASSERT(image);
216     FilterOperations filterResult = blendFilterOperations(anim, from, to, progress);
217
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);
221
222     auto result = CSSFilterImageValue::create(std::move(imageValue), std::move(filterValue));
223     result.get().setFilterOperations(filterResult);
224     return StyleGeneratedImage::create(std::move(result));
225 }
226 #endif // ENABLE(CSS_FILTERS)
227
228 static inline EVisibility blendFunc(const AnimationBase* anim, EVisibility from, EVisibility to, double progress)
229 {
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)
235         return to;
236     double result = blendFunc(anim, fromVal, toVal, progress);
237     return result > 0. ? VISIBLE : (to != VISIBLE ? to : from);
238 }
239
240 static inline LengthBox blendFunc(const AnimationBase* anim, const LengthBox& from, const LengthBox& to, double progress)
241 {
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));
246     return result;
247 }
248
249 #if ENABLE(SVG)
250 static inline SVGLength blendFunc(const AnimationBase*, const SVGLength& from, const SVGLength& to, double progress)
251 {
252     return to.blend(from, narrowPrecisionToFloat(progress));
253 }
254 static inline Vector<SVGLength> blendFunc(const AnimationBase*, const Vector<SVGLength>& from, const Vector<SVGLength>& to, double progress)
255 {
256     size_t fromLength = from.size();
257     size_t toLength = to.size();
258     if (!fromLength)
259         return !progress ? from : to;
260     if (!toLength)
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);
266         else
267             resultLength = fromLength * toLength;
268     }
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));
272     return result;
273 }
274 #endif
275
276 static inline PassRefPtr<StyleImage> crossfadeBlend(const AnimationBase*, StyleCachedImage* fromStyleImage, StyleCachedImage* toStyleImage, double progress)
277 {
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.
280     if (!progress)
281         return fromStyleImage;
282     if (progress == 1)
283         return toStyleImage;
284
285     auto fromImageValue = CSSImageValue::create(fromStyleImage->cachedImage()->url(), fromStyleImage);
286     auto toImageValue = CSSImageValue::create(toStyleImage->cachedImage()->url(), toStyleImage);
287
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));
291 }
292
293 static inline PassRefPtr<StyleImage> blendFunc(const AnimationBase* anim, StyleImage* from, StyleImage* to, double progress)
294 {
295     if (!from || !to)
296         return to;
297
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();
302
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);
311         }
312 #endif
313
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));
319         }
320
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);
330         }
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);
338         }
339 #endif
340         // FIXME: Add interpolation between image source and cross-fade.
341     }
342
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);
347
348     return to;
349 }
350
351 static inline NinePieceImage blendFunc(const AnimationBase* anim, const NinePieceImage& from, const NinePieceImage& to, double progress)
352 {
353     if (!from.hasImage() || !to.hasImage())
354         return to;
355
356     // FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content.
357
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())
359         return to;
360
361     if (from.image()->imageSize(anim->renderer(), 1.0) != to.image()->imageSize(anim->renderer(), 1.0))
362         return to;
363
364     RefPtr<StyleImage> newContentImage = blendFunc(anim, from.image(), to.image(), progress);
365
366     return NinePieceImage(newContentImage, from.imageSlices(), from.fill(), from.borderSlices(), from.outset(), from.horizontalRule(), from.verticalRule());
367 }
368
369 class AnimationPropertyWrapperBase {
370     WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase);
371     WTF_MAKE_FAST_ALLOCATED;
372 public:
373     AnimationPropertyWrapperBase(CSSPropertyID prop)
374         : m_prop(prop)
375     {
376     }
377
378     virtual ~AnimationPropertyWrapperBase() { }
379
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;
383
384     CSSPropertyID property() const { return m_prop; }
385
386 #if USE(ACCELERATED_COMPOSITING)
387     virtual bool animationIsAccelerated() const { return false; }
388 #endif
389
390 private:
391     CSSPropertyID m_prop;
392 };
393
394 template <typename T>
395 class PropertyWrapperGetter : public AnimationPropertyWrapperBase {
396 public:
397     PropertyWrapperGetter(CSSPropertyID prop, T (RenderStyle::*getter)() const)
398         : AnimationPropertyWrapperBase(prop)
399         , m_getter(getter)
400     {
401     }
402
403     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
404     {
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)
408             return true;
409         if (!a || !b)
410             return false;
411         return (a->*m_getter)() == (b->*m_getter)();
412     }
413
414 protected:
415     T (RenderStyle::*m_getter)() const;
416 };
417
418 template <typename T>
419 class PropertyWrapper : public PropertyWrapperGetter<T> {
420 public:
421     PropertyWrapper(CSSPropertyID prop, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
422         : PropertyWrapperGetter<T>(prop, getter)
423         , m_setter(setter)
424     {
425     }
426
427     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
428     {
429         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T>::m_getter)(), (b->*PropertyWrapperGetter<T>::m_getter)(), progress));
430     }
431
432 protected:
433     void (RenderStyle::*m_setter)(T);
434 };
435
436 template <typename T>
437 class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> {
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 public:
457     LengthPropertyWrapper(CSSPropertyID prop, const T& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
458         : PropertyWrapperGetter<const T&>(prop, getter)
459         , m_setter(setter)
460     {
461     }
462
463     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
464     {
465         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<const T&>::m_getter)(), (b->*PropertyWrapperGetter<const T&>::m_getter)(), progress));
466     }
467
468 protected:
469     void (RenderStyle::*m_setter)(T);
470 };
471
472 class PropertyWrapperClipPath : public RefCountedPropertyWrapper<ClipPathOperation> {
473 public:
474     PropertyWrapperClipPath(CSSPropertyID prop, ClipPathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ClipPathOperation>))
475         : RefCountedPropertyWrapper<ClipPathOperation>(prop, getter, setter)
476     {
477     }
478 };
479
480 #if ENABLE(CSS_SHAPES)
481 class PropertyWrapperShape : public RefCountedPropertyWrapper<ShapeValue> {
482 public:
483     PropertyWrapperShape(CSSPropertyID prop, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ShapeValue>))
484         : RefCountedPropertyWrapper<ShapeValue>(prop, getter, setter)
485     {
486     }
487 };
488 #endif
489
490 class StyleImagePropertyWrapper : public RefCountedPropertyWrapper<StyleImage> {
491 public:
492     StyleImagePropertyWrapper(CSSPropertyID prop, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<StyleImage>))
493         : RefCountedPropertyWrapper<StyleImage>(prop, getter, setter)
494     {
495     }
496
497     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
498     {
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.
501        if (a == b)
502            return true;
503        if (!a || !b)
504             return false;
505
506         StyleImage* imageA = (a->*m_getter)();
507         StyleImage* imageB = (b->*m_getter)();
508         return StyleImage::imagesEquivalent(imageA, imageB);
509     }
510 };
511
512 class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
513 public:
514     PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
515         : PropertyWrapperGetter<Color>(prop, getter)
516         , m_setter(setter)
517     {
518     }
519
520     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
521     {
522         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_getter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
523     }
524
525 protected:
526     void (RenderStyle::*m_setter)(const Color&);
527 };
528
529
530 #if USE(ACCELERATED_COMPOSITING)
531 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
532 public:
533     PropertyWrapperAcceleratedOpacity()
534         : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)
535     {
536     }
537
538     virtual bool animationIsAccelerated() const { return true; }
539
540     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
541     {
542         float fromOpacity = a->opacity();
543
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));
546     }
547 };
548
549 class PropertyWrapperAcceleratedTransform : public PropertyWrapper<const TransformOperations&> {
550 public:
551     PropertyWrapperAcceleratedTransform()
552         : PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform)
553     {
554     }
555
556     virtual bool animationIsAccelerated() const { return true; }
557
558     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
559     {
560         dst->setTransform(blendFunc(anim, a->transform(), b->transform(), progress));
561     }
562 };
563
564 #if ENABLE(CSS_FILTERS)
565 class PropertyWrapperAcceleratedFilter : public PropertyWrapper<const FilterOperations&> {
566 public:
567     PropertyWrapperAcceleratedFilter()
568         : PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter)
569     {
570     }
571
572     virtual bool animationIsAccelerated() const { return true; }
573
574     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
575     {
576         dst->setFilter(blendFunc(anim, a->filter(), b->filter(), progress));
577     }
578 };
579 #endif
580 #endif // USE(ACCELERATED_COMPOSITING)
581
582 static inline size_t shadowListLength(const ShadowData* shadow)
583 {
584     size_t count;
585     for (count = 0; shadow; shadow = shadow->next())
586         ++count;
587     return count;
588 }
589
590 static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow)
591 {
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));
594
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));
597
598     if (srcShadow)
599         return srcShadow;
600
601     if (otherShadow->style() == Inset)
602         return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData : &defaultInsetShadowData;
603
604     return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData : &defaultShadowData;
605 }
606
607 class PropertyWrapperShadow : public AnimationPropertyWrapperBase {
608 public:
609     PropertyWrapperShadow(CSSPropertyID prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassOwnPtr<ShadowData>, bool))
610         : AnimationPropertyWrapperBase(prop)
611         , m_getter(getter)
612         , m_setter(setter)
613     {
614     }
615
616     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
617     {
618         const ShadowData* shadowA = (a->*m_getter)();
619         const ShadowData* shadowB = (b->*m_getter)();
620
621         while (true) {
622             // end of both lists
623             if (!shadowA && !shadowB)
624                 return true;
625
626             // end of just one of the lists
627             if (!shadowA || !shadowB)
628                 return false;
629
630             if (*shadowA != *shadowB)
631                 return false;
632
633             shadowA = shadowA->next();
634             shadowB = shadowB->next();
635         }
636
637         return true;
638     }
639
640     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
641     {
642         const ShadowData* shadowA = (a->*m_getter)();
643         const ShadowData* shadowB = (b->*m_getter)();
644
645         int fromLength = shadowListLength(shadowA);
646         int toLength = shadowListLength(shadowB);
647
648         if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) {
649             (dst->*m_setter)(blendSimpleOrMatchedShadowLists(anim, progress, shadowA, shadowB), false);
650             return;
651         }
652
653         (dst->*m_setter)(blendMismatchedShadowLists(anim, progress, shadowA, shadowB, fromLength, toLength), false);
654     }
655
656 private:
657     PassOwnPtr<ShadowData> blendSimpleOrMatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB) const
658     {
659         OwnPtr<ShadowData> newShadowData;
660         ShadowData* lastShadow = 0;
661
662         while (shadowA || shadowB) {
663             const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB);
664             const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA);
665
666             OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
667             ShadowData* blendedShadowPtr = blendedShadow.get();
668
669             if (!lastShadow)
670                 newShadowData = blendedShadow.release();
671             else
672                 lastShadow->setNext(blendedShadow.release());
673
674             lastShadow = blendedShadowPtr;
675
676             shadowA = shadowA ? shadowA->next() : 0;
677             shadowB = shadowB ? shadowB->next() : 0;
678         }
679
680         return newShadowData.release();
681     }
682
683     PassOwnPtr<ShadowData> blendMismatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength) const
684     {
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();
691         }
692
693         Vector<const ShadowData*, 4> toShadows(toLength);
694         for (int i = toLength - 1; i >= 0; --i) {
695             toShadows[i] = shadowB;
696             shadowB = shadowB->next();
697         }
698
699         OwnPtr<ShadowData> newShadowData;
700
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;
705
706             const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow);
707             const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow);
708
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();
713         }
714
715         return newShadowData.release();
716     }
717
718     const ShadowData* (RenderStyle::*m_getter)() const;
719     void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
720 };
721
722 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
723 public:
724     PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
725         : AnimationPropertyWrapperBase(prop)
726         , m_getter(getter)
727         , m_setter(setter)
728     {
729     }
730
731     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
732     {
733         Color fromColor = (a->*m_getter)();
734         Color toColor = (b->*m_getter)();
735
736         if (!fromColor.isValid() && !toColor.isValid())
737             return true;
738
739         if (!fromColor.isValid())
740             fromColor = a->color();
741         if (!toColor.isValid())
742             toColor = b->color();
743
744         return fromColor == toColor;
745     }
746
747     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
748     {
749         Color fromColor = (a->*m_getter)();
750         Color toColor = (b->*m_getter)();
751
752         if (!fromColor.isValid() && !toColor.isValid())
753             return;
754
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));
760     }
761
762 private:
763     Color (RenderStyle::*m_getter)() const;
764     void (RenderStyle::*m_setter)(const Color&);
765 };
766
767
768 enum MaybeInvalidColorTag { MaybeInvalidColor };
769 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
770 public:
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)))
776     {
777     }
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)))
783     {
784     }
785     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
786     {
787         return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
788     }
789     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
790     {
791         m_wrapper->blend(anim, dst, a, b, progress);
792         m_visitedWrapper->blend(anim, dst, a, b, progress);
793     }
794
795 private:
796     OwnPtr<AnimationPropertyWrapperBase> m_wrapper;
797     OwnPtr<AnimationPropertyWrapperBase> m_visitedWrapper;
798 };
799
800 // Wrapper base class for an animatable property in a FillLayer
801 class FillLayerAnimationPropertyWrapperBase {
802 public:
803     FillLayerAnimationPropertyWrapperBase()
804     {
805     }
806
807     virtual ~FillLayerAnimationPropertyWrapperBase() { }
808
809     virtual bool equals(const FillLayer*, const FillLayer*) const = 0;
810     virtual void blend(const AnimationBase*, FillLayer*, const FillLayer*, const FillLayer*, double) const = 0;
811 };
812
813 template <typename T>
814 class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase {
815     WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter);
816 public:
817     FillLayerPropertyWrapperGetter(T (FillLayer::*getter)() const)
818         : m_getter(getter)
819     {
820     }
821
822     virtual bool equals(const FillLayer* a, const FillLayer* b) const
823     {
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)
827            return true;
828        if (!a || !b)
829             return false;
830         return (a->*m_getter)() == (b->*m_getter)();
831     }
832
833 protected:
834     T (FillLayer::*m_getter)() const;
835 };
836
837 template <typename T>
838 class FillLayerPropertyWrapper : public FillLayerPropertyWrapperGetter<const T&> {
839 public:
840     FillLayerPropertyWrapper(const T& (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
841         : FillLayerPropertyWrapperGetter<const T&>(getter)
842         , m_setter(setter)
843     {
844     }
845
846     virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
847     {
848         (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), progress));
849     }
850
851 protected:
852     void (FillLayer::*m_setter)(T);
853 };
854
855 template <typename T>
856 class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> {
857 public:
858     FillLayerRefCountedPropertyWrapper(T* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<T>))
859         : FillLayerPropertyWrapperGetter<T*>(getter)
860         , m_setter(setter)
861     {
862     }
863
864     virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
865     {
866         (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), progress));
867     }
868
869 protected:
870     void (FillLayer::*m_setter)(PassRefPtr<T>);
871 };
872
873 class FillLayerStyleImagePropertyWrapper : public FillLayerRefCountedPropertyWrapper<StyleImage> {
874 public:
875     FillLayerStyleImagePropertyWrapper(StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<StyleImage>))
876         : FillLayerRefCountedPropertyWrapper<StyleImage>(getter, setter)
877     {
878     }
879
880     virtual bool equals(const FillLayer* a, const FillLayer* b) const
881     {
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.
884        if (a == b)
885            return true;
886        if (!a || !b)
887             return false;
888
889         StyleImage* imageA = (a->*m_getter)();
890         StyleImage* imageB = (b->*m_getter)();
891         return StyleImage::imagesEquivalent(imageA, imageB);
892     }
893 };
894
895 class FillLayersPropertyWrapper : public AnimationPropertyWrapperBase {
896 public:
897     typedef const FillLayer* (RenderStyle::*LayersGetter)() const;
898     typedef FillLayer* (RenderStyle::*LayersAccessor)();
899
900     FillLayersPropertyWrapper(CSSPropertyID prop, LayersGetter getter, LayersAccessor accessor)
901         : AnimationPropertyWrapperBase(prop)
902         , m_layersGetter(getter)
903         , m_layersAccessor(accessor)
904     {
905         switch (prop) {
906         case CSSPropertyBackgroundPositionX:
907         case CSSPropertyWebkitMaskPositionX:
908             m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::xPosition, &FillLayer::setXPosition);
909             break;
910         case CSSPropertyBackgroundPositionY:
911         case CSSPropertyWebkitMaskPositionY:
912             m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::yPosition, &FillLayer::setYPosition);
913             break;
914         case CSSPropertyBackgroundSize:
915         case CSSPropertyWebkitBackgroundSize:
916         case CSSPropertyWebkitMaskSize:
917             m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<LengthSize>(&FillLayer::sizeLength, &FillLayer::setSizeLength);
918             break;
919         case CSSPropertyBackgroundImage:
920             m_fillLayerPropertyWrapper = new FillLayerStyleImagePropertyWrapper(&FillLayer::image, &FillLayer::setImage);
921             break;
922         default:
923             break;
924         }
925     }
926
927     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
928     {
929         const FillLayer* fromLayer = (a->*m_layersGetter)();
930         const FillLayer* toLayer = (b->*m_layersGetter)();
931
932         while (fromLayer && toLayer) {
933             if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer))
934                 return false;
935
936             fromLayer = fromLayer->next();
937             toLayer = toLayer->next();
938         }
939
940         return true;
941     }
942
943     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
944     {
945         const FillLayer* aLayer = (a->*m_layersGetter)();
946         const FillLayer* bLayer = (b->*m_layersGetter)();
947         FillLayer* dstLayer = (dst->*m_layersAccessor)();
948
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();
954         }
955     }
956
957 private:
958     FillLayerAnimationPropertyWrapperBase* m_fillLayerPropertyWrapper;
959
960     LayersGetter m_layersGetter;
961     LayersAccessor m_layersAccessor;
962 };
963
964 class ShorthandPropertyWrapper : public AnimationPropertyWrapperBase {
965 public:
966     ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers)
967         : AnimationPropertyWrapperBase(property)
968     {
969         m_propertyWrappers.swap(longhandWrappers);
970     }
971
972     virtual bool isShorthandWrapper() const { return true; }
973
974     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
975     {
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))
979                 return false;
980         }
981         return true;
982     }
983
984     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
985     {
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);
989     }
990
991     const Vector<AnimationPropertyWrapperBase*> propertyWrappers() const { return m_propertyWrappers; }
992
993 private:
994     Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
995 };
996
997 class PropertyWrapperFlex : public AnimationPropertyWrapperBase {
998 public:
999     PropertyWrapperFlex() : AnimationPropertyWrapperBase(CSSPropertyWebkitFlex)
1000     {
1001     }
1002
1003     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1004     {
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)
1008             return true;
1009         if (!a || !b)
1010             return false;
1011
1012         return a->flexBasis() == b->flexBasis() && a->flexGrow() == b->flexGrow() && a->flexShrink() == b->flexShrink();
1013     }
1014
1015     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1016     {
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));
1020     }
1021 };
1022
1023 #if ENABLE(SVG)
1024 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
1025 public:
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)
1029         , m_getter(getter)
1030         , m_setter(setter)
1031     {
1032     }
1033
1034     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1035     {
1036         if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
1037             return false;
1038
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)();
1045
1046             if (!fromColor.isValid() && !toColor.isValid())
1047                 return true;
1048
1049             if (!fromColor.isValid())
1050                 fromColor = Color();
1051             if (!toColor.isValid())
1052                 toColor = Color();
1053
1054             return fromColor == toColor;
1055         }
1056         return true;
1057     }
1058
1059     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1060     {
1061         if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
1062             || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
1063             return;
1064
1065         Color fromColor = (a->*m_getter)();
1066         Color toColor = (b->*m_getter)();
1067
1068         if (!fromColor.isValid() && !toColor.isValid())
1069             return;
1070
1071         if (!fromColor.isValid())
1072             fromColor = Color();
1073         if (!toColor.isValid())
1074             toColor = Color();
1075         (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
1076     }
1077
1078 private:
1079     const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
1080     Color (RenderStyle::*m_getter)() const;
1081     void (RenderStyle::*m_setter)(const Color&);
1082 };
1083 #endif
1084
1085 class CSSPropertyAnimationWrapperMap {
1086 public:
1087     static CSSPropertyAnimationWrapperMap& instance()
1088     {
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, ());
1091         if (!map)
1092             map = adoptPtr(new CSSPropertyAnimationWrapperMap);
1093         return *map;
1094     }
1095
1096     AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID)
1097     {
1098         if (propertyID < firstCSSProperty || propertyID > lastCSSProperty)
1099             return 0;
1100
1101         unsigned wrapperIndex = indexFromPropertyID(propertyID);
1102         if (wrapperIndex == cInvalidPropertyWrapperIndex)
1103             return 0;
1104
1105         return m_propertyWrappers[wrapperIndex].get();
1106     }
1107
1108     AnimationPropertyWrapperBase* wrapperForIndex(unsigned index)
1109     {
1110         ASSERT(index < m_propertyWrappers.size());
1111         return m_propertyWrappers[index].get();
1112     }
1113
1114     unsigned size()
1115     {
1116         return m_propertyWrappers.size();
1117     }
1118
1119 private:
1120     CSSPropertyAnimationWrapperMap();
1121     unsigned char& indexFromPropertyID(CSSPropertyID propertyID)
1122     {
1123         return m_propertyToIdMap[propertyID - firstCSSProperty];
1124     }
1125
1126     Vector<OwnPtr<AnimationPropertyWrapperBase>> m_propertyWrappers;
1127     unsigned char m_propertyToIdMap[numCSSProperties];
1128
1129     static const unsigned char cInvalidPropertyWrapperIndex = UCHAR_MAX;
1130 };
1131
1132 CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap()
1133 {
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),
1140
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),
1144
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),
1148
1149         new PropertyWrapperFlex(),
1150
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),
1164
1165         new PropertyWrapperVisitedAffectedColor(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor),
1166
1167         new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1168         new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage),
1169         new StyleImagePropertyWrapper(CSSPropertyWebkitMaskImage, &RenderStyle::maskImage, &RenderStyle::setMaskImage),
1170
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),
1175
1176         new StyleImagePropertyWrapper(CSSPropertyWebkitMaskBoxImageSource, &RenderStyle::maskBoxImageSource, &RenderStyle::setMaskBoxImageSource),
1177         new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage),
1178
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),
1183
1184         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1185         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1186         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1187
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,
1194 #else
1195             &RenderStyle::computedFontSize,
1196 #endif
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),
1213
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),
1226
1227         new LengthPropertyWrapper<LengthBox>(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip),
1228
1229 #if USE(ACCELERATED_COMPOSITING)
1230         new PropertyWrapperAcceleratedOpacity(),
1231         new PropertyWrapperAcceleratedTransform(),
1232 #if ENABLE(CSS_FILTERS)
1233         new PropertyWrapperAcceleratedFilter(),
1234 #endif
1235 #else
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),
1240 #endif
1241 #endif
1242
1243         new PropertyWrapperClipPath(CSSPropertyWebkitClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath),
1244
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),
1250 #endif
1251
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),
1260
1261         new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1262         new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1263         new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow),
1264
1265 #if ENABLE(SVG)
1266         new PropertyWrapperSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor),
1267         new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity),
1268
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),
1275
1276         new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity),
1277         new PropertyWrapperMaybeInvalidColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor),
1278
1279         new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity),
1280         new PropertyWrapperMaybeInvalidColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor),
1281
1282         new PropertyWrapperMaybeInvalidColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor),
1283
1284         new PropertyWrapper<SVGLength>(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue),
1285         new PropertyWrapper<SVGLength>(CSSPropertyKerning, &RenderStyle::kerning, &RenderStyle::setKerning),
1286 #endif
1287     };
1288     const unsigned animatableLonghandPropertiesCount = WTF_ARRAY_LENGTH(animatableLonghandPropertyWrappers);
1289
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,
1300         CSSPropertyBorder,
1301         CSSPropertyBorderImage,
1302         CSSPropertyBorderSpacing,
1303         CSSPropertyListStyle, // for list-style-image
1304         CSSPropertyMargin,
1305         CSSPropertyOutline,
1306         CSSPropertyPadding,
1307         CSSPropertyWebkitTextStroke,
1308         CSSPropertyWebkitColumnRule,
1309         CSSPropertyWebkitBorderRadius,
1310         CSSPropertyWebkitTransformOrigin
1311     };
1312     const unsigned animatableShorthandPropertiesCount = WTF_ARRAY_LENGTH(animatableShorthandProperties);
1313
1314     // TODO:
1315     //
1316     //  CSSPropertyVerticalAlign
1317     //
1318     // Compound properties that have components that should be animatable:
1319     //
1320     //  CSSPropertyWebkitColumns
1321     //  CSSPropertyWebkitBoxReflect
1322
1323     // Make sure unused slots have a value
1324     for (int i = 0; i < numCSSProperties; ++i)
1325         m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex;
1326
1327     COMPILE_ASSERT(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount < UCHAR_MAX, numberOfAnimatablePropertiesMustBeLessThanUCharMax);
1328     m_propertyWrappers.reserveInitialCapacity(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount);
1329
1330     // First we put the non-shorthand property wrappers into the map, so the shorthand-building
1331     // code can find them.
1332
1333     for (unsigned i = 0; i < animatableLonghandPropertiesCount; ++i) {
1334         AnimationPropertyWrapperBase* wrapper = animatableLonghandPropertyWrappers[i];
1335         m_propertyWrappers.uncheckedAppend(adoptPtr(wrapper));
1336         indexFromPropertyID(wrapper->property()) = i;
1337     }
1338
1339     for (size_t i = 0; i < animatableShorthandPropertiesCount; ++i) {
1340         CSSPropertyID propertyID = animatableShorthandProperties[i];
1341         StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
1342         if (!shorthand.length())
1343             continue;
1344
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)
1351                 continue;
1352             ASSERT(m_propertyWrappers[wrapperIndex]);
1353             longhandWrappers.uncheckedAppend(m_propertyWrappers[wrapperIndex].get());
1354         }
1355
1356         m_propertyWrappers.uncheckedAppend(adoptPtr(new ShorthandPropertyWrapper(propertyID, longhandWrappers)));
1357         indexFromPropertyID(propertyID) = animatableLonghandPropertiesCount + i;
1358     }
1359 }
1360
1361 static bool gatherEnclosingShorthandProperties(CSSPropertyID property, AnimationPropertyWrapperBase* wrapper, HashSet<CSSPropertyID>& propertySet)
1362 {
1363     if (!wrapper->isShorthandWrapper())
1364         return false;
1365
1366     ShorthandPropertyWrapper* shorthandWrapper = static_cast<ShorthandPropertyWrapper*>(wrapper);
1367
1368     bool contained = false;
1369     for (size_t i = 0; i < shorthandWrapper->propertyWrappers().size(); ++i) {
1370         AnimationPropertyWrapperBase* currWrapper = shorthandWrapper->propertyWrappers()[i];
1371
1372         if (gatherEnclosingShorthandProperties(property, currWrapper, propertySet) || currWrapper->property() == property)
1373             contained = true;
1374     }
1375
1376     if (contained)
1377         propertySet.add(wrapper->property());
1378
1379     return contained;
1380 }
1381
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)
1384 {
1385     ASSERT(prop != CSSPropertyInvalid);
1386
1387     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1388     if (wrapper) {
1389         wrapper->blend(anim, dst, a, b, progress);
1390 #if USE(ACCELERATED_COMPOSITING)
1391         return !wrapper->animationIsAccelerated() || !anim->isAccelerated();
1392 #else
1393         return true;
1394 #endif
1395     }
1396
1397     return false;
1398 }
1399
1400 #if USE(ACCELERATED_COMPOSITING)
1401 bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(CSSPropertyID prop)
1402 {
1403     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1404     return wrapper ? wrapper->animationIsAccelerated() : false;
1405 }
1406 #endif
1407
1408 // Note: this is inefficient. It's only called from pauseTransitionAtTime().
1409 HashSet<CSSPropertyID> CSSPropertyAnimation::animatableShorthandsAffectingProperty(CSSPropertyID property)
1410 {
1411     CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1412
1413     HashSet<CSSPropertyID> foundProperties;
1414     for (unsigned i = 0; i < map.size(); ++i)
1415         gatherEnclosingShorthandProperties(property, map.wrapperForIndex(i), foundProperties);
1416
1417     return foundProperties;
1418 }
1419
1420 bool CSSPropertyAnimation::propertiesEqual(CSSPropertyID prop, const RenderStyle* a, const RenderStyle* b)
1421 {
1422     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1423     if (wrapper)
1424         return wrapper->equals(a, b);
1425     return true;
1426 }
1427
1428 CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, bool& isShorthand)
1429 {
1430     CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1431
1432     if (i < 0 || static_cast<unsigned>(i) >= map.size())
1433         return CSSPropertyInvalid;
1434
1435     AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i);
1436     isShorthand = wrapper->isShorthandWrapper();
1437     return wrapper->property();
1438 }
1439
1440 int CSSPropertyAnimation::getNumProperties()
1441 {
1442     return CSSPropertyAnimationWrapperMap::instance().size();
1443 }
1444
1445 }