54458bd52d3f3b1b6f961deb94abae38fca43a72
[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     RefPtr<CSSValue> filterValue = ComputedStyleExtractor::valueForFilter(anim->renderer(), &anim->renderer()->style(), filterResult, DoNotAdjustPixelValues);
221     RefPtr<CSSFilterImageValue> result = CSSFilterImageValue::create(std::move(imageValue), filterValue);
222     result->setFilterOperations(filterResult);
223
224     return StyleGeneratedImage::create(*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     RefPtr<CSSCrossfadeValue> crossfadeValue = CSSCrossfadeValue::create(std::move(fromImageValue), std::move(toImageValue));
288
289     crossfadeValue->setPercentage(CSSPrimitiveValue::create(progress, CSSPrimitiveValue::CSS_NUMBER));
290
291     return StyleGeneratedImage::create(*crossfadeValue);
292 }
293
294 static inline PassRefPtr<StyleImage> blendFunc(const AnimationBase* anim, StyleImage* from, StyleImage* to, double progress)
295 {
296     if (!from || !to)
297         return to;
298
299     // Animation between two generated images. Cross fade for all other cases.
300     if (from->isGeneratedImage() && to->isGeneratedImage()) {
301         CSSImageGeneratorValue& fromGenerated = toStyleGeneratedImage(from)->imageValue();
302         CSSImageGeneratorValue& toGenerated = toStyleGeneratedImage(to)->imageValue();
303
304 #if ENABLE(CSS_FILTERS)
305         if (fromGenerated.isFilterImageValue() && toGenerated.isFilterImageValue()) {
306             // Animation of generated images just possible if input images are equal.
307             // Otherwise fall back to cross fade animation.
308             CSSFilterImageValue& fromFilter = toCSSFilterImageValue(fromGenerated);
309             CSSFilterImageValue& toFilter = toCSSFilterImageValue(toGenerated);
310             if (fromFilter.equalInputImages(toFilter) && fromFilter.cachedImage())
311                 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), toFilter.filterOperations(), progress);
312         }
313 #endif
314
315         if (fromGenerated.isCrossfadeValue() && toGenerated.isCrossfadeValue()) {
316             CSSCrossfadeValue& fromCrossfade = toCSSCrossfadeValue(fromGenerated);
317             CSSCrossfadeValue& toCrossfade = toCSSCrossfadeValue(toGenerated);
318             if (fromCrossfade.equalInputImages(toCrossfade))
319                 return StyleGeneratedImage::create(*toCrossfade.blend(fromCrossfade, progress));
320         }
321
322         // FIXME: Add support for animation between two *gradient() functions.
323         // https://bugs.webkit.org/show_bug.cgi?id=119956
324 #if ENABLE(CSS_FILTERS)
325     } else if (from->isGeneratedImage() && to->isCachedImage()) {
326         CSSImageGeneratorValue& fromGenerated = toStyleGeneratedImage(from)->imageValue();
327         if (fromGenerated.isFilterImageValue()) {
328             CSSFilterImageValue& fromFilter = toCSSFilterImageValue(fromGenerated);
329             if (fromFilter.cachedImage() && static_cast<StyleCachedImage*>(to)->cachedImage() == fromFilter.cachedImage())
330                 return blendFilter(anim, fromFilter.cachedImage(), fromFilter.filterOperations(), FilterOperations(), progress);
331         }
332         // FIXME: Add interpolation between cross-fade and image source.
333     } else if (from->isCachedImage() && to->isGeneratedImage()) {
334         CSSImageGeneratorValue& toGenerated = toStyleGeneratedImage(to)->imageValue();
335         if (toGenerated.isFilterImageValue()) {
336             CSSFilterImageValue& toFilter = toCSSFilterImageValue(toGenerated);
337             if (toFilter.cachedImage() && static_cast<StyleCachedImage*>(from)->cachedImage() == toFilter.cachedImage())     
338                 return blendFilter(anim, toFilter.cachedImage(), FilterOperations(), toFilter.filterOperations(), progress);
339         }
340 #endif
341         // FIXME: Add interpolation between image source and cross-fade.
342     }
343
344     // FIXME: Add support cross fade between cached and generated images.
345     // https://bugs.webkit.org/show_bug.cgi?id=78293
346     if (from->isCachedImage() && to->isCachedImage())
347         return crossfadeBlend(anim, static_cast<StyleCachedImage*>(from), static_cast<StyleCachedImage*>(to), progress);
348
349     return to;
350 }
351
352 static inline NinePieceImage blendFunc(const AnimationBase* anim, const NinePieceImage& from, const NinePieceImage& to, double progress)
353 {
354     if (!from.hasImage() || !to.hasImage())
355         return to;
356
357     // FIXME (74112): Support transitioning between NinePieceImages that differ by more than image content.
358
359     if (from.imageSlices() != to.imageSlices() || from.borderSlices() != to.borderSlices() || from.outset() != to.outset() || from.fill() != to.fill() || from.horizontalRule() != to.horizontalRule() || from.verticalRule() != to.verticalRule())
360         return to;
361
362     if (from.image()->imageSize(anim->renderer(), 1.0) != to.image()->imageSize(anim->renderer(), 1.0))
363         return to;
364
365     RefPtr<StyleImage> newContentImage = blendFunc(anim, from.image(), to.image(), progress);
366
367     return NinePieceImage(newContentImage, from.imageSlices(), from.fill(), from.borderSlices(), from.outset(), from.horizontalRule(), from.verticalRule());
368 }
369
370 class AnimationPropertyWrapperBase {
371     WTF_MAKE_NONCOPYABLE(AnimationPropertyWrapperBase);
372     WTF_MAKE_FAST_ALLOCATED;
373 public:
374     AnimationPropertyWrapperBase(CSSPropertyID prop)
375         : m_prop(prop)
376     {
377     }
378
379     virtual ~AnimationPropertyWrapperBase() { }
380
381     virtual bool isShorthandWrapper() const { return false; }
382     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const = 0;
383     virtual void blend(const AnimationBase*, RenderStyle*, const RenderStyle*, const RenderStyle*, double) const = 0;
384
385     CSSPropertyID property() const { return m_prop; }
386
387 #if USE(ACCELERATED_COMPOSITING)
388     virtual bool animationIsAccelerated() const { return false; }
389 #endif
390
391 private:
392     CSSPropertyID m_prop;
393 };
394
395 template <typename T>
396 class PropertyWrapperGetter : public AnimationPropertyWrapperBase {
397 public:
398     PropertyWrapperGetter(CSSPropertyID prop, T (RenderStyle::*getter)() const)
399         : AnimationPropertyWrapperBase(prop)
400         , m_getter(getter)
401     {
402     }
403
404     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
405     {
406         // If the style pointers are the same, don't bother doing the test.
407         // If either is null, return false. If both are null, return true.
408         if ((!a && !b) || a == b)
409             return true;
410         if (!a || !b)
411             return false;
412         return (a->*m_getter)() == (b->*m_getter)();
413     }
414
415 protected:
416     T (RenderStyle::*m_getter)() const;
417 };
418
419 template <typename T>
420 class PropertyWrapper : public PropertyWrapperGetter<T> {
421 public:
422     PropertyWrapper(CSSPropertyID prop, T (RenderStyle::*getter)() const, void (RenderStyle::*setter)(T))
423         : PropertyWrapperGetter<T>(prop, getter)
424         , m_setter(setter)
425     {
426     }
427
428     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
429     {
430         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T>::m_getter)(), (b->*PropertyWrapperGetter<T>::m_getter)(), progress));
431     }
432
433 protected:
434     void (RenderStyle::*m_setter)(T);
435 };
436
437 template <typename T>
438 class RefCountedPropertyWrapper : public PropertyWrapperGetter<T*> {
439 public:
440     RefCountedPropertyWrapper(CSSPropertyID prop, T* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<T>))
441         : PropertyWrapperGetter<T*>(prop, getter)
442         , m_setter(setter)
443     {
444     }
445
446     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
447     {
448         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<T*>::m_getter)(), (b->*PropertyWrapperGetter<T*>::m_getter)(), progress));
449     }
450
451 protected:
452     void (RenderStyle::*m_setter)(PassRefPtr<T>);
453 };
454
455 template <typename T>
456 class LengthPropertyWrapper : public PropertyWrapperGetter<const T&> {
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 public:
475     PropertyWrapperClipPath(CSSPropertyID prop, ClipPathOperation* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ClipPathOperation>))
476         : RefCountedPropertyWrapper<ClipPathOperation>(prop, getter, setter)
477     {
478     }
479 };
480
481 #if ENABLE(CSS_SHAPES)
482 class PropertyWrapperShape : public RefCountedPropertyWrapper<ShapeValue> {
483 public:
484     PropertyWrapperShape(CSSPropertyID prop, ShapeValue* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<ShapeValue>))
485         : RefCountedPropertyWrapper<ShapeValue>(prop, getter, setter)
486     {
487     }
488 };
489 #endif
490
491 class StyleImagePropertyWrapper : public RefCountedPropertyWrapper<StyleImage> {
492 public:
493     StyleImagePropertyWrapper(CSSPropertyID prop, StyleImage* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassRefPtr<StyleImage>))
494         : RefCountedPropertyWrapper<StyleImage>(prop, getter, setter)
495     {
496     }
497
498     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
499     {
500        // If the style pointers are the same, don't bother doing the test.
501        // If either is null, return false. If both are null, return true.
502        if (a == b)
503            return true;
504        if (!a || !b)
505             return false;
506
507         StyleImage* imageA = (a->*m_getter)();
508         StyleImage* imageB = (b->*m_getter)();
509         return StyleImage::imagesEquivalent(imageA, imageB);
510     }
511 };
512
513 class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
514 public:
515     PropertyWrapperColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
516         : PropertyWrapperGetter<Color>(prop, getter)
517         , m_setter(setter)
518     {
519     }
520
521     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
522     {
523         (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_getter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
524     }
525
526 protected:
527     void (RenderStyle::*m_setter)(const Color&);
528 };
529
530
531 #if USE(ACCELERATED_COMPOSITING)
532 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
533 public:
534     PropertyWrapperAcceleratedOpacity()
535         : PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity)
536     {
537     }
538
539     virtual bool animationIsAccelerated() const { return true; }
540
541     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
542     {
543         float fromOpacity = a->opacity();
544
545         // This makes sure we put the object being animated into a RenderLayer during the animation
546         dst->setOpacity(blendFunc(anim, (fromOpacity == 1) ? 0.999999f : fromOpacity, b->opacity(), progress));
547     }
548 };
549
550 class PropertyWrapperAcceleratedTransform : public PropertyWrapper<const TransformOperations&> {
551 public:
552     PropertyWrapperAcceleratedTransform()
553         : PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform)
554     {
555     }
556
557     virtual bool animationIsAccelerated() const { return true; }
558
559     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
560     {
561         dst->setTransform(blendFunc(anim, a->transform(), b->transform(), progress));
562     }
563 };
564
565 #if ENABLE(CSS_FILTERS)
566 class PropertyWrapperAcceleratedFilter : public PropertyWrapper<const FilterOperations&> {
567 public:
568     PropertyWrapperAcceleratedFilter()
569         : PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter)
570     {
571     }
572
573     virtual bool animationIsAccelerated() const { return true; }
574
575     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
576     {
577         dst->setFilter(blendFunc(anim, a->filter(), b->filter(), progress));
578     }
579 };
580 #endif
581 #endif // USE(ACCELERATED_COMPOSITING)
582
583 static inline size_t shadowListLength(const ShadowData* shadow)
584 {
585     size_t count;
586     for (count = 0; shadow; shadow = shadow->next())
587         ++count;
588     return count;
589 }
590
591 static inline const ShadowData* shadowForBlending(const ShadowData* srcShadow, const ShadowData* otherShadow)
592 {
593     DEFINE_STATIC_LOCAL(ShadowData, defaultShadowData, (IntPoint(), 0, 0, Normal, false, Color::transparent));
594     DEFINE_STATIC_LOCAL(ShadowData, defaultInsetShadowData, (IntPoint(), 0, 0, Inset, false, Color::transparent));
595
596     DEFINE_STATIC_LOCAL(ShadowData, defaultWebKitBoxShadowData, (IntPoint(), 0, 0, Normal, true, Color::transparent));
597     DEFINE_STATIC_LOCAL(ShadowData, defaultInsetWebKitBoxShadowData, (IntPoint(), 0, 0, Inset, true, Color::transparent));
598
599     if (srcShadow)
600         return srcShadow;
601
602     if (otherShadow->style() == Inset)
603         return otherShadow->isWebkitBoxShadow() ? &defaultInsetWebKitBoxShadowData : &defaultInsetShadowData;
604
605     return otherShadow->isWebkitBoxShadow() ? &defaultWebKitBoxShadowData : &defaultShadowData;
606 }
607
608 class PropertyWrapperShadow : public AnimationPropertyWrapperBase {
609 public:
610     PropertyWrapperShadow(CSSPropertyID prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassOwnPtr<ShadowData>, bool))
611         : AnimationPropertyWrapperBase(prop)
612         , m_getter(getter)
613         , m_setter(setter)
614     {
615     }
616
617     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
618     {
619         const ShadowData* shadowA = (a->*m_getter)();
620         const ShadowData* shadowB = (b->*m_getter)();
621
622         while (true) {
623             // end of both lists
624             if (!shadowA && !shadowB)
625                 return true;
626
627             // end of just one of the lists
628             if (!shadowA || !shadowB)
629                 return false;
630
631             if (*shadowA != *shadowB)
632                 return false;
633
634             shadowA = shadowA->next();
635             shadowB = shadowB->next();
636         }
637
638         return true;
639     }
640
641     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
642     {
643         const ShadowData* shadowA = (a->*m_getter)();
644         const ShadowData* shadowB = (b->*m_getter)();
645
646         int fromLength = shadowListLength(shadowA);
647         int toLength = shadowListLength(shadowB);
648
649         if (fromLength == toLength || (fromLength <= 1 && toLength <= 1)) {
650             (dst->*m_setter)(blendSimpleOrMatchedShadowLists(anim, progress, shadowA, shadowB), false);
651             return;
652         }
653
654         (dst->*m_setter)(blendMismatchedShadowLists(anim, progress, shadowA, shadowB, fromLength, toLength), false);
655     }
656
657 private:
658     PassOwnPtr<ShadowData> blendSimpleOrMatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB) const
659     {
660         OwnPtr<ShadowData> newShadowData;
661         ShadowData* lastShadow = 0;
662
663         while (shadowA || shadowB) {
664             const ShadowData* srcShadow = shadowForBlending(shadowA, shadowB);
665             const ShadowData* dstShadow = shadowForBlending(shadowB, shadowA);
666
667             OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
668             ShadowData* blendedShadowPtr = blendedShadow.get();
669
670             if (!lastShadow)
671                 newShadowData = blendedShadow.release();
672             else
673                 lastShadow->setNext(blendedShadow.release());
674
675             lastShadow = blendedShadowPtr;
676
677             shadowA = shadowA ? shadowA->next() : 0;
678             shadowB = shadowB ? shadowB->next() : 0;
679         }
680
681         return newShadowData.release();
682     }
683
684     PassOwnPtr<ShadowData> blendMismatchedShadowLists(const AnimationBase* anim, double progress, const ShadowData* shadowA, const ShadowData* shadowB, int fromLength, int toLength) const
685     {
686         // The shadows in ShadowData are stored in reverse order, so when animating mismatched lists,
687         // reverse them and match from the end.
688         Vector<const ShadowData*, 4> fromShadows(fromLength);
689         for (int i = fromLength - 1; i >= 0; --i) {
690             fromShadows[i] = shadowA;
691             shadowA = shadowA->next();
692         }
693
694         Vector<const ShadowData*, 4> toShadows(toLength);
695         for (int i = toLength - 1; i >= 0; --i) {
696             toShadows[i] = shadowB;
697             shadowB = shadowB->next();
698         }
699
700         OwnPtr<ShadowData> newShadowData;
701
702         int maxLength = std::max(fromLength, toLength);
703         for (int i = 0; i < maxLength; ++i) {
704             const ShadowData* fromShadow = i < fromLength ? fromShadows[i] : 0;
705             const ShadowData* toShadow = i < toLength ? toShadows[i] : 0;
706
707             const ShadowData* srcShadow = shadowForBlending(fromShadow, toShadow);
708             const ShadowData* dstShadow = shadowForBlending(toShadow, fromShadow);
709
710             OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
711             // Insert at the start of the list to preserve the order.
712             blendedShadow->setNext(newShadowData.release());
713             newShadowData = blendedShadow.release();
714         }
715
716         return newShadowData.release();
717     }
718
719     const ShadowData* (RenderStyle::*m_getter)() const;
720     void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
721 };
722
723 class PropertyWrapperMaybeInvalidColor : public AnimationPropertyWrapperBase {
724 public:
725     PropertyWrapperMaybeInvalidColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
726         : AnimationPropertyWrapperBase(prop)
727         , m_getter(getter)
728         , m_setter(setter)
729     {
730     }
731
732     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
733     {
734         Color fromColor = (a->*m_getter)();
735         Color toColor = (b->*m_getter)();
736
737         if (!fromColor.isValid() && !toColor.isValid())
738             return true;
739
740         if (!fromColor.isValid())
741             fromColor = a->color();
742         if (!toColor.isValid())
743             toColor = b->color();
744
745         return fromColor == toColor;
746     }
747
748     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
749     {
750         Color fromColor = (a->*m_getter)();
751         Color toColor = (b->*m_getter)();
752
753         if (!fromColor.isValid() && !toColor.isValid())
754             return;
755
756         if (!fromColor.isValid())
757             fromColor = a->color();
758         if (!toColor.isValid())
759             toColor = b->color();
760         (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
761     }
762
763 private:
764     Color (RenderStyle::*m_getter)() const;
765     void (RenderStyle::*m_setter)(const Color&);
766 };
767
768
769 enum MaybeInvalidColorTag { MaybeInvalidColor };
770 class PropertyWrapperVisitedAffectedColor : public AnimationPropertyWrapperBase {
771 public:
772     PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
773                                         Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
774         : AnimationPropertyWrapperBase(prop)
775         , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter)))
776         , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter, visitedSetter)))
777     {
778     }
779     PropertyWrapperVisitedAffectedColor(CSSPropertyID prop, MaybeInvalidColorTag, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&),
780                                         Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
781         : AnimationPropertyWrapperBase(prop)
782         , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter)))
783         , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, visitedGetter, visitedSetter)))
784     {
785     }
786     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
787     {
788         return m_wrapper->equals(a, b) && m_visitedWrapper->equals(a, b);
789     }
790     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
791     {
792         m_wrapper->blend(anim, dst, a, b, progress);
793         m_visitedWrapper->blend(anim, dst, a, b, progress);
794     }
795
796 private:
797     OwnPtr<AnimationPropertyWrapperBase> m_wrapper;
798     OwnPtr<AnimationPropertyWrapperBase> m_visitedWrapper;
799 };
800
801 // Wrapper base class for an animatable property in a FillLayer
802 class FillLayerAnimationPropertyWrapperBase {
803 public:
804     FillLayerAnimationPropertyWrapperBase()
805     {
806     }
807
808     virtual ~FillLayerAnimationPropertyWrapperBase() { }
809
810     virtual bool equals(const FillLayer*, const FillLayer*) const = 0;
811     virtual void blend(const AnimationBase*, FillLayer*, const FillLayer*, const FillLayer*, double) const = 0;
812 };
813
814 template <typename T>
815 class FillLayerPropertyWrapperGetter : public FillLayerAnimationPropertyWrapperBase {
816     WTF_MAKE_NONCOPYABLE(FillLayerPropertyWrapperGetter);
817 public:
818     FillLayerPropertyWrapperGetter(T (FillLayer::*getter)() const)
819         : m_getter(getter)
820     {
821     }
822
823     virtual bool equals(const FillLayer* a, const FillLayer* b) const
824     {
825        // If the style pointers are the same, don't bother doing the test.
826        // If either is null, return false. If both are null, return true.
827        if ((!a && !b) || a == b)
828            return true;
829        if (!a || !b)
830             return false;
831         return (a->*m_getter)() == (b->*m_getter)();
832     }
833
834 protected:
835     T (FillLayer::*m_getter)() const;
836 };
837
838 template <typename T>
839 class FillLayerPropertyWrapper : public FillLayerPropertyWrapperGetter<const T&> {
840 public:
841     FillLayerPropertyWrapper(const T& (FillLayer::*getter)() const, void (FillLayer::*setter)(T))
842         : FillLayerPropertyWrapperGetter<const T&>(getter)
843         , m_setter(setter)
844     {
845     }
846
847     virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
848     {
849         (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<const T&>::m_getter)(), progress));
850     }
851
852 protected:
853     void (FillLayer::*m_setter)(T);
854 };
855
856 template <typename T>
857 class FillLayerRefCountedPropertyWrapper : public FillLayerPropertyWrapperGetter<T*> {
858 public:
859     FillLayerRefCountedPropertyWrapper(T* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<T>))
860         : FillLayerPropertyWrapperGetter<T*>(getter)
861         , m_setter(setter)
862     {
863     }
864
865     virtual void blend(const AnimationBase* anim, FillLayer* dst, const FillLayer* a, const FillLayer* b, double progress) const
866     {
867         (dst->*m_setter)(blendFunc(anim, (a->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), (b->*FillLayerPropertyWrapperGetter<T*>::m_getter)(), progress));
868     }
869
870 protected:
871     void (FillLayer::*m_setter)(PassRefPtr<T>);
872 };
873
874 class FillLayerStyleImagePropertyWrapper : public FillLayerRefCountedPropertyWrapper<StyleImage> {
875 public:
876     FillLayerStyleImagePropertyWrapper(StyleImage* (FillLayer::*getter)() const, void (FillLayer::*setter)(PassRefPtr<StyleImage>))
877         : FillLayerRefCountedPropertyWrapper<StyleImage>(getter, setter)
878     {
879     }
880
881     virtual bool equals(const FillLayer* a, const FillLayer* b) const
882     {
883        // If the style pointers are the same, don't bother doing the test.
884        // If either is null, return false. If both are null, return true.
885        if (a == b)
886            return true;
887        if (!a || !b)
888             return false;
889
890         StyleImage* imageA = (a->*m_getter)();
891         StyleImage* imageB = (b->*m_getter)();
892         return StyleImage::imagesEquivalent(imageA, imageB);
893     }
894 };
895
896 class FillLayersPropertyWrapper : public AnimationPropertyWrapperBase {
897 public:
898     typedef const FillLayer* (RenderStyle::*LayersGetter)() const;
899     typedef FillLayer* (RenderStyle::*LayersAccessor)();
900
901     FillLayersPropertyWrapper(CSSPropertyID prop, LayersGetter getter, LayersAccessor accessor)
902         : AnimationPropertyWrapperBase(prop)
903         , m_layersGetter(getter)
904         , m_layersAccessor(accessor)
905     {
906         switch (prop) {
907         case CSSPropertyBackgroundPositionX:
908         case CSSPropertyWebkitMaskPositionX:
909             m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::xPosition, &FillLayer::setXPosition);
910             break;
911         case CSSPropertyBackgroundPositionY:
912         case CSSPropertyWebkitMaskPositionY:
913             m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<Length>(&FillLayer::yPosition, &FillLayer::setYPosition);
914             break;
915         case CSSPropertyBackgroundSize:
916         case CSSPropertyWebkitBackgroundSize:
917         case CSSPropertyWebkitMaskSize:
918             m_fillLayerPropertyWrapper = new FillLayerPropertyWrapper<LengthSize>(&FillLayer::sizeLength, &FillLayer::setSizeLength);
919             break;
920         case CSSPropertyBackgroundImage:
921             m_fillLayerPropertyWrapper = new FillLayerStyleImagePropertyWrapper(&FillLayer::image, &FillLayer::setImage);
922             break;
923         default:
924             break;
925         }
926     }
927
928     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
929     {
930         const FillLayer* fromLayer = (a->*m_layersGetter)();
931         const FillLayer* toLayer = (b->*m_layersGetter)();
932
933         while (fromLayer && toLayer) {
934             if (!m_fillLayerPropertyWrapper->equals(fromLayer, toLayer))
935                 return false;
936
937             fromLayer = fromLayer->next();
938             toLayer = toLayer->next();
939         }
940
941         return true;
942     }
943
944     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
945     {
946         const FillLayer* aLayer = (a->*m_layersGetter)();
947         const FillLayer* bLayer = (b->*m_layersGetter)();
948         FillLayer* dstLayer = (dst->*m_layersAccessor)();
949
950         while (aLayer && bLayer && dstLayer) {
951             m_fillLayerPropertyWrapper->blend(anim, dstLayer, aLayer, bLayer, progress);
952             aLayer = aLayer->next();
953             bLayer = bLayer->next();
954             dstLayer = dstLayer->next();
955         }
956     }
957
958 private:
959     FillLayerAnimationPropertyWrapperBase* m_fillLayerPropertyWrapper;
960
961     LayersGetter m_layersGetter;
962     LayersAccessor m_layersAccessor;
963 };
964
965 class ShorthandPropertyWrapper : public AnimationPropertyWrapperBase {
966 public:
967     ShorthandPropertyWrapper(CSSPropertyID property, Vector<AnimationPropertyWrapperBase*> longhandWrappers)
968         : AnimationPropertyWrapperBase(property)
969     {
970         m_propertyWrappers.swap(longhandWrappers);
971     }
972
973     virtual bool isShorthandWrapper() const { return true; }
974
975     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
976     {
977         Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
978         for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it) {
979             if (!(*it)->equals(a, b))
980                 return false;
981         }
982         return true;
983     }
984
985     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
986     {
987         Vector<AnimationPropertyWrapperBase*>::const_iterator end = m_propertyWrappers.end();
988         for (Vector<AnimationPropertyWrapperBase*>::const_iterator it = m_propertyWrappers.begin(); it != end; ++it)
989             (*it)->blend(anim, dst, a, b, progress);
990     }
991
992     const Vector<AnimationPropertyWrapperBase*> propertyWrappers() const { return m_propertyWrappers; }
993
994 private:
995     Vector<AnimationPropertyWrapperBase*> m_propertyWrappers;
996 };
997
998 class PropertyWrapperFlex : public AnimationPropertyWrapperBase {
999 public:
1000     PropertyWrapperFlex() : AnimationPropertyWrapperBase(CSSPropertyWebkitFlex)
1001     {
1002     }
1003
1004     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1005     {
1006         // If the style pointers are the same, don't bother doing the test.
1007         // If either is null, return false. If both are null, return true.
1008         if ((!a && !b) || a == b)
1009             return true;
1010         if (!a || !b)
1011             return false;
1012
1013         return a->flexBasis() == b->flexBasis() && a->flexGrow() == b->flexGrow() && a->flexShrink() == b->flexShrink();
1014     }
1015
1016     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1017     {
1018         dst->setFlexBasis(blendFunc(anim, a->flexBasis(), b->flexBasis(), progress));
1019         dst->setFlexGrow(blendFunc(anim, a->flexGrow(), b->flexGrow(), progress));
1020         dst->setFlexShrink(blendFunc(anim, a->flexShrink(), b->flexShrink(), progress));
1021     }
1022 };
1023
1024 #if ENABLE(SVG)
1025 class PropertyWrapperSVGPaint : public AnimationPropertyWrapperBase {
1026 public:
1027     PropertyWrapperSVGPaint(CSSPropertyID prop, const SVGPaint::SVGPaintType& (RenderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
1028         : AnimationPropertyWrapperBase(prop)
1029         , m_paintTypeGetter(paintTypeGetter)
1030         , m_getter(getter)
1031         , m_setter(setter)
1032     {
1033     }
1034
1035     virtual bool equals(const RenderStyle* a, const RenderStyle* b) const
1036     {
1037         if ((a->*m_paintTypeGetter)() != (b->*m_paintTypeGetter)())
1038             return false;
1039
1040         // We only support animations between SVGPaints that are pure Color values.
1041         // For everything else we must return true for this method, otherwise
1042         // we will try to animate between values forever.
1043         if ((a->*m_paintTypeGetter)() == SVGPaint::SVG_PAINTTYPE_RGBCOLOR) {
1044             Color fromColor = (a->*m_getter)();
1045             Color toColor = (b->*m_getter)();
1046
1047             if (!fromColor.isValid() && !toColor.isValid())
1048                 return true;
1049
1050             if (!fromColor.isValid())
1051                 fromColor = Color();
1052             if (!toColor.isValid())
1053                 toColor = Color();
1054
1055             return fromColor == toColor;
1056         }
1057         return true;
1058     }
1059
1060     virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
1061     {
1062         if ((a->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR
1063             || (b->*m_paintTypeGetter)() != SVGPaint::SVG_PAINTTYPE_RGBCOLOR)
1064             return;
1065
1066         Color fromColor = (a->*m_getter)();
1067         Color toColor = (b->*m_getter)();
1068
1069         if (!fromColor.isValid() && !toColor.isValid())
1070             return;
1071
1072         if (!fromColor.isValid())
1073             fromColor = Color();
1074         if (!toColor.isValid())
1075             toColor = Color();
1076         (dst->*m_setter)(blendFunc(anim, fromColor, toColor, progress));
1077     }
1078
1079 private:
1080     const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
1081     Color (RenderStyle::*m_getter)() const;
1082     void (RenderStyle::*m_setter)(const Color&);
1083 };
1084 #endif
1085
1086 class CSSPropertyAnimationWrapperMap {
1087 public:
1088     static CSSPropertyAnimationWrapperMap& instance()
1089     {
1090         // FIXME: This data is never destroyed. Maybe we should ref count it and toss it when the last AnimationController is destroyed?
1091         DEFINE_STATIC_LOCAL(OwnPtr<CSSPropertyAnimationWrapperMap>, map, ());
1092         if (!map)
1093             map = adoptPtr(new CSSPropertyAnimationWrapperMap);
1094         return *map;
1095     }
1096
1097     AnimationPropertyWrapperBase* wrapperForProperty(CSSPropertyID propertyID)
1098     {
1099         if (propertyID < firstCSSProperty || propertyID > lastCSSProperty)
1100             return 0;
1101
1102         unsigned wrapperIndex = indexFromPropertyID(propertyID);
1103         if (wrapperIndex == cInvalidPropertyWrapperIndex)
1104             return 0;
1105
1106         return m_propertyWrappers[wrapperIndex].get();
1107     }
1108
1109     AnimationPropertyWrapperBase* wrapperForIndex(unsigned index)
1110     {
1111         ASSERT(index < m_propertyWrappers.size());
1112         return m_propertyWrappers[index].get();
1113     }
1114
1115     unsigned size()
1116     {
1117         return m_propertyWrappers.size();
1118     }
1119
1120 private:
1121     CSSPropertyAnimationWrapperMap();
1122     unsigned char& indexFromPropertyID(CSSPropertyID propertyID)
1123     {
1124         return m_propertyToIdMap[propertyID - firstCSSProperty];
1125     }
1126
1127     Vector<OwnPtr<AnimationPropertyWrapperBase>> m_propertyWrappers;
1128     unsigned char m_propertyToIdMap[numCSSProperties];
1129
1130     static const unsigned char cInvalidPropertyWrapperIndex = UCHAR_MAX;
1131 };
1132
1133 CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap()
1134 {
1135     // build the list of property wrappers to do the comparisons and blends
1136     AnimationPropertyWrapperBase* animatableLonghandPropertyWrappers[] = {
1137         new LengthPropertyWrapper<Length>(CSSPropertyLeft, &RenderStyle::left, &RenderStyle::setLeft),
1138         new LengthPropertyWrapper<Length>(CSSPropertyRight, &RenderStyle::right, &RenderStyle::setRight),
1139         new LengthPropertyWrapper<Length>(CSSPropertyTop, &RenderStyle::top, &RenderStyle::setTop),
1140         new LengthPropertyWrapper<Length>(CSSPropertyBottom, &RenderStyle::bottom, &RenderStyle::setBottom),
1141
1142         new LengthPropertyWrapper<Length>(CSSPropertyWidth, &RenderStyle::width, &RenderStyle::setWidth),
1143         new LengthPropertyWrapper<Length>(CSSPropertyMinWidth, &RenderStyle::minWidth, &RenderStyle::setMinWidth),
1144         new LengthPropertyWrapper<Length>(CSSPropertyMaxWidth, &RenderStyle::maxWidth, &RenderStyle::setMaxWidth),
1145
1146         new LengthPropertyWrapper<Length>(CSSPropertyHeight, &RenderStyle::height, &RenderStyle::setHeight),
1147         new LengthPropertyWrapper<Length>(CSSPropertyMinHeight, &RenderStyle::minHeight, &RenderStyle::setMinHeight),
1148         new LengthPropertyWrapper<Length>(CSSPropertyMaxHeight, &RenderStyle::maxHeight, &RenderStyle::setMaxHeight),
1149
1150         new PropertyWrapperFlex(),
1151
1152         new PropertyWrapper<unsigned>(CSSPropertyBorderLeftWidth, &RenderStyle::borderLeftWidth, &RenderStyle::setBorderLeftWidth),
1153         new PropertyWrapper<unsigned>(CSSPropertyBorderRightWidth, &RenderStyle::borderRightWidth, &RenderStyle::setBorderRightWidth),
1154         new PropertyWrapper<unsigned>(CSSPropertyBorderTopWidth, &RenderStyle::borderTopWidth, &RenderStyle::setBorderTopWidth),
1155         new PropertyWrapper<unsigned>(CSSPropertyBorderBottomWidth, &RenderStyle::borderBottomWidth, &RenderStyle::setBorderBottomWidth),
1156         new LengthPropertyWrapper<Length>(CSSPropertyMarginLeft, &RenderStyle::marginLeft, &RenderStyle::setMarginLeft),
1157         new LengthPropertyWrapper<Length>(CSSPropertyMarginRight, &RenderStyle::marginRight, &RenderStyle::setMarginRight),
1158         new LengthPropertyWrapper<Length>(CSSPropertyMarginTop, &RenderStyle::marginTop, &RenderStyle::setMarginTop),
1159         new LengthPropertyWrapper<Length>(CSSPropertyMarginBottom, &RenderStyle::marginBottom, &RenderStyle::setMarginBottom),
1160         new LengthPropertyWrapper<Length>(CSSPropertyPaddingLeft, &RenderStyle::paddingLeft, &RenderStyle::setPaddingLeft),
1161         new LengthPropertyWrapper<Length>(CSSPropertyPaddingRight, &RenderStyle::paddingRight, &RenderStyle::setPaddingRight),
1162         new LengthPropertyWrapper<Length>(CSSPropertyPaddingTop, &RenderStyle::paddingTop, &RenderStyle::setPaddingTop),
1163         new LengthPropertyWrapper<Length>(CSSPropertyPaddingBottom, &RenderStyle::paddingBottom, &RenderStyle::setPaddingBottom),
1164         new PropertyWrapperVisitedAffectedColor(CSSPropertyColor, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::visitedLinkColor, &RenderStyle::setVisitedLinkColor),
1165
1166         new PropertyWrapperVisitedAffectedColor(CSSPropertyBackgroundColor, &RenderStyle::backgroundColor, &RenderStyle::setBackgroundColor, &RenderStyle::visitedLinkBackgroundColor, &RenderStyle::setVisitedLinkBackgroundColor),
1167
1168         new FillLayersPropertyWrapper(CSSPropertyBackgroundImage, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1169         new StyleImagePropertyWrapper(CSSPropertyListStyleImage, &RenderStyle::listStyleImage, &RenderStyle::setListStyleImage),
1170         new StyleImagePropertyWrapper(CSSPropertyWebkitMaskImage, &RenderStyle::maskImage, &RenderStyle::setMaskImage),
1171
1172         new StyleImagePropertyWrapper(CSSPropertyBorderImageSource, &RenderStyle::borderImageSource, &RenderStyle::setBorderImageSource),
1173         new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageSlice, &RenderStyle::borderImageSlices, &RenderStyle::setBorderImageSlices),
1174         new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageWidth, &RenderStyle::borderImageWidth, &RenderStyle::setBorderImageWidth),
1175         new LengthPropertyWrapper<LengthBox>(CSSPropertyBorderImageOutset, &RenderStyle::borderImageOutset, &RenderStyle::setBorderImageOutset),
1176
1177         new StyleImagePropertyWrapper(CSSPropertyWebkitMaskBoxImageSource, &RenderStyle::maskBoxImageSource, &RenderStyle::setMaskBoxImageSource),
1178         new PropertyWrapper<const NinePieceImage&>(CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage),
1179
1180         new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionX, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1181         new FillLayersPropertyWrapper(CSSPropertyBackgroundPositionY, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1182         new FillLayersPropertyWrapper(CSSPropertyBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1183         new FillLayersPropertyWrapper(CSSPropertyWebkitBackgroundSize, &RenderStyle::backgroundLayers, &RenderStyle::accessBackgroundLayers),
1184
1185         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionX, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1186         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskPositionY, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1187         new FillLayersPropertyWrapper(CSSPropertyWebkitMaskSize, &RenderStyle::maskLayers, &RenderStyle::accessMaskLayers),
1188
1189         new PropertyWrapper<float>(CSSPropertyFontSize,
1190             // Must pass a specified size to setFontSize if Text Autosizing is enabled, but a computed size
1191             // if text zoom is enabled (if neither is enabled it's irrelevant as they're probably the same).
1192             // FIXME: Find some way to assert that text zoom isn't activated when Text Autosizing is compiled in.
1193 #if ENABLE(TEXT_AUTOSIZING)
1194             &RenderStyle::specifiedFontSize,
1195 #else
1196             &RenderStyle::computedFontSize,
1197 #endif
1198             &RenderStyle::setFontSize),
1199         new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnRuleWidth, &RenderStyle::columnRuleWidth, &RenderStyle::setColumnRuleWidth),
1200         new PropertyWrapper<float>(CSSPropertyWebkitColumnGap, &RenderStyle::columnGap, &RenderStyle::setColumnGap),
1201         new PropertyWrapper<unsigned short>(CSSPropertyWebkitColumnCount, &RenderStyle::columnCount, &RenderStyle::setColumnCount),
1202         new PropertyWrapper<float>(CSSPropertyWebkitColumnWidth, &RenderStyle::columnWidth, &RenderStyle::setColumnWidth),
1203         new PropertyWrapper<short>(CSSPropertyWebkitBorderHorizontalSpacing, &RenderStyle::horizontalBorderSpacing, &RenderStyle::setHorizontalBorderSpacing),
1204         new PropertyWrapper<short>(CSSPropertyWebkitBorderVerticalSpacing, &RenderStyle::verticalBorderSpacing, &RenderStyle::setVerticalBorderSpacing),
1205         new PropertyWrapper<int>(CSSPropertyZIndex, &RenderStyle::zIndex, &RenderStyle::setZIndex),
1206         new PropertyWrapper<short>(CSSPropertyOrphans, &RenderStyle::orphans, &RenderStyle::setOrphans),
1207         new PropertyWrapper<short>(CSSPropertyWidows, &RenderStyle::widows, &RenderStyle::setWidows),
1208         new LengthPropertyWrapper<Length>(CSSPropertyLineHeight, &RenderStyle::specifiedLineHeight, &RenderStyle::setLineHeight),
1209         new PropertyWrapper<int>(CSSPropertyOutlineOffset, &RenderStyle::outlineOffset, &RenderStyle::setOutlineOffset),
1210         new PropertyWrapper<unsigned short>(CSSPropertyOutlineWidth, &RenderStyle::outlineWidth, &RenderStyle::setOutlineWidth),
1211         new PropertyWrapper<int>(CSSPropertyLetterSpacing, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing),
1212         new PropertyWrapper<int>(CSSPropertyWordSpacing, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing),
1213         new LengthPropertyWrapper<Length>(CSSPropertyTextIndent, &RenderStyle::textIndent, &RenderStyle::setTextIndent),
1214
1215         new PropertyWrapper<float>(CSSPropertyWebkitPerspective, &RenderStyle::perspective, &RenderStyle::setPerspective),
1216         new LengthPropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginX, &RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX),
1217         new LengthPropertyWrapper<Length>(CSSPropertyWebkitPerspectiveOriginY, &RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY),
1218         new LengthPropertyWrapper<Length>(CSSPropertyWebkitTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX),
1219         new LengthPropertyWrapper<Length>(CSSPropertyWebkitTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY),
1220         new PropertyWrapper<float>(CSSPropertyWebkitTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ),
1221         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius),
1222         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius),
1223         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius),
1224         new LengthPropertyWrapper<LengthSize>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius),
1225         new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility),
1226         new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoomWithoutReturnValue),
1227
1228         new LengthPropertyWrapper<LengthBox>(CSSPropertyClip, &RenderStyle::clip, &RenderStyle::setClip),
1229
1230 #if USE(ACCELERATED_COMPOSITING)
1231         new PropertyWrapperAcceleratedOpacity(),
1232         new PropertyWrapperAcceleratedTransform(),
1233 #if ENABLE(CSS_FILTERS)
1234         new PropertyWrapperAcceleratedFilter(),
1235 #endif
1236 #else
1237         new PropertyWrapper<float>(CSSPropertyOpacity, &RenderStyle::opacity, &RenderStyle::setOpacity),
1238         new PropertyWrapper<const TransformOperations&>(CSSPropertyWebkitTransform, &RenderStyle::transform, &RenderStyle::setTransform),
1239 #if ENABLE(CSS_FILTERS)
1240         new PropertyWrapper<const FilterOperations&>(CSSPropertyWebkitFilter, &RenderStyle::filter, &RenderStyle::setFilter),
1241 #endif
1242 #endif
1243
1244         new PropertyWrapperClipPath(CSSPropertyWebkitClipPath, &RenderStyle::clipPath, &RenderStyle::setClipPath),
1245
1246 #if ENABLE(CSS_SHAPES)
1247         new PropertyWrapperShape(CSSPropertyWebkitShapeInside, &RenderStyle::shapeInside, &RenderStyle::setShapeInside),
1248         new PropertyWrapperShape(CSSPropertyWebkitShapeOutside, &RenderStyle::shapeOutside, &RenderStyle::setShapeOutside),
1249         new LengthPropertyWrapper<Length>(CSSPropertyWebkitShapeMargin, &RenderStyle::shapeMargin, &RenderStyle::setShapeMargin),
1250         new PropertyWrapper<float>(CSSPropertyWebkitShapeImageThreshold, &RenderStyle::shapeImageThreshold, &RenderStyle::setShapeImageThreshold),
1251 #endif
1252
1253         new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitColumnRuleColor, MaybeInvalidColor, &RenderStyle::columnRuleColor, &RenderStyle::setColumnRuleColor, &RenderStyle::visitedLinkColumnRuleColor, &RenderStyle::setVisitedLinkColumnRuleColor),
1254         new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextStrokeColor, MaybeInvalidColor, &RenderStyle::textStrokeColor, &RenderStyle::setTextStrokeColor, &RenderStyle::visitedLinkTextStrokeColor, &RenderStyle::setVisitedLinkTextStrokeColor),
1255         new PropertyWrapperVisitedAffectedColor(CSSPropertyWebkitTextFillColor, MaybeInvalidColor, &RenderStyle::textFillColor, &RenderStyle::setTextFillColor, &RenderStyle::visitedLinkTextFillColor, &RenderStyle::setVisitedLinkTextFillColor),
1256         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderLeftColor, MaybeInvalidColor, &RenderStyle::borderLeftColor, &RenderStyle::setBorderLeftColor, &RenderStyle::visitedLinkBorderLeftColor, &RenderStyle::setVisitedLinkBorderLeftColor),
1257         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderRightColor, MaybeInvalidColor, &RenderStyle::borderRightColor, &RenderStyle::setBorderRightColor, &RenderStyle::visitedLinkBorderRightColor, &RenderStyle::setVisitedLinkBorderRightColor),
1258         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderTopColor, MaybeInvalidColor, &RenderStyle::borderTopColor, &RenderStyle::setBorderTopColor, &RenderStyle::visitedLinkBorderTopColor, &RenderStyle::setVisitedLinkBorderTopColor),
1259         new PropertyWrapperVisitedAffectedColor(CSSPropertyBorderBottomColor, MaybeInvalidColor, &RenderStyle::borderBottomColor, &RenderStyle::setBorderBottomColor, &RenderStyle::visitedLinkBorderBottomColor, &RenderStyle::setVisitedLinkBorderBottomColor),
1260         new PropertyWrapperVisitedAffectedColor(CSSPropertyOutlineColor, MaybeInvalidColor, &RenderStyle::outlineColor, &RenderStyle::setOutlineColor, &RenderStyle::visitedLinkOutlineColor, &RenderStyle::setVisitedLinkOutlineColor),
1261
1262         new PropertyWrapperShadow(CSSPropertyBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1263         new PropertyWrapperShadow(CSSPropertyWebkitBoxShadow, &RenderStyle::boxShadow, &RenderStyle::setBoxShadow),
1264         new PropertyWrapperShadow(CSSPropertyTextShadow, &RenderStyle::textShadow, &RenderStyle::setTextShadow),
1265
1266 #if ENABLE(SVG)
1267         new PropertyWrapperSVGPaint(CSSPropertyFill, &RenderStyle::fillPaintType, &RenderStyle::fillPaintColor, &RenderStyle::setFillPaintColor),
1268         new PropertyWrapper<float>(CSSPropertyFillOpacity, &RenderStyle::fillOpacity, &RenderStyle::setFillOpacity),
1269
1270         new PropertyWrapperSVGPaint(CSSPropertyStroke, &RenderStyle::strokePaintType, &RenderStyle::strokePaintColor, &RenderStyle::setStrokePaintColor),
1271         new PropertyWrapper<float>(CSSPropertyStrokeOpacity, &RenderStyle::strokeOpacity, &RenderStyle::setStrokeOpacity),
1272         new PropertyWrapper<SVGLength>(CSSPropertyStrokeWidth, &RenderStyle::strokeWidth, &RenderStyle::setStrokeWidth),
1273         new PropertyWrapper< Vector<SVGLength>>(CSSPropertyStrokeDasharray, &RenderStyle::strokeDashArray, &RenderStyle::setStrokeDashArray),
1274         new PropertyWrapper<SVGLength>(CSSPropertyStrokeDashoffset, &RenderStyle::strokeDashOffset, &RenderStyle::setStrokeDashOffset),
1275         new PropertyWrapper<float>(CSSPropertyStrokeMiterlimit, &RenderStyle::strokeMiterLimit, &RenderStyle::setStrokeMiterLimit),
1276
1277         new PropertyWrapper<float>(CSSPropertyFloodOpacity, &RenderStyle::floodOpacity, &RenderStyle::setFloodOpacity),
1278         new PropertyWrapperMaybeInvalidColor(CSSPropertyFloodColor, &RenderStyle::floodColor, &RenderStyle::setFloodColor),
1279
1280         new PropertyWrapper<float>(CSSPropertyStopOpacity, &RenderStyle::stopOpacity, &RenderStyle::setStopOpacity),
1281         new PropertyWrapperMaybeInvalidColor(CSSPropertyStopColor, &RenderStyle::stopColor, &RenderStyle::setStopColor),
1282
1283         new PropertyWrapperMaybeInvalidColor(CSSPropertyLightingColor, &RenderStyle::lightingColor, &RenderStyle::setLightingColor),
1284
1285         new PropertyWrapper<SVGLength>(CSSPropertyBaselineShift, &RenderStyle::baselineShiftValue, &RenderStyle::setBaselineShiftValue),
1286         new PropertyWrapper<SVGLength>(CSSPropertyKerning, &RenderStyle::kerning, &RenderStyle::setKerning),
1287 #endif
1288     };
1289     const unsigned animatableLonghandPropertiesCount = WTF_ARRAY_LENGTH(animatableLonghandPropertyWrappers);
1290
1291     static const CSSPropertyID animatableShorthandProperties[] = {
1292         CSSPropertyBackground, // for background-color, background-position, background-image
1293         CSSPropertyBackgroundPosition,
1294         CSSPropertyFont, // for font-size, font-weight
1295         CSSPropertyWebkitMask, // for mask-position
1296         CSSPropertyWebkitMaskPosition,
1297         CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft,
1298         CSSPropertyBorderColor,
1299         CSSPropertyBorderRadius,
1300         CSSPropertyBorderWidth,
1301         CSSPropertyBorder,
1302         CSSPropertyBorderImage,
1303         CSSPropertyBorderSpacing,
1304         CSSPropertyListStyle, // for list-style-image
1305         CSSPropertyMargin,
1306         CSSPropertyOutline,
1307         CSSPropertyPadding,
1308         CSSPropertyWebkitTextStroke,
1309         CSSPropertyWebkitColumnRule,
1310         CSSPropertyWebkitBorderRadius,
1311         CSSPropertyWebkitTransformOrigin
1312     };
1313     const unsigned animatableShorthandPropertiesCount = WTF_ARRAY_LENGTH(animatableShorthandProperties);
1314
1315     // TODO:
1316     //
1317     //  CSSPropertyVerticalAlign
1318     //
1319     // Compound properties that have components that should be animatable:
1320     //
1321     //  CSSPropertyWebkitColumns
1322     //  CSSPropertyWebkitBoxReflect
1323
1324     // Make sure unused slots have a value
1325     for (int i = 0; i < numCSSProperties; ++i)
1326         m_propertyToIdMap[i] = cInvalidPropertyWrapperIndex;
1327
1328     COMPILE_ASSERT(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount < UCHAR_MAX, numberOfAnimatablePropertiesMustBeLessThanUCharMax);
1329     m_propertyWrappers.reserveInitialCapacity(animatableLonghandPropertiesCount + animatableShorthandPropertiesCount);
1330
1331     // First we put the non-shorthand property wrappers into the map, so the shorthand-building
1332     // code can find them.
1333
1334     for (unsigned i = 0; i < animatableLonghandPropertiesCount; ++i) {
1335         AnimationPropertyWrapperBase* wrapper = animatableLonghandPropertyWrappers[i];
1336         m_propertyWrappers.uncheckedAppend(adoptPtr(wrapper));
1337         indexFromPropertyID(wrapper->property()) = i;
1338     }
1339
1340     for (size_t i = 0; i < animatableShorthandPropertiesCount; ++i) {
1341         CSSPropertyID propertyID = animatableShorthandProperties[i];
1342         StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
1343         if (!shorthand.length())
1344             continue;
1345
1346         Vector<AnimationPropertyWrapperBase*> longhandWrappers;
1347         longhandWrappers.reserveInitialCapacity(shorthand.length());
1348         const CSSPropertyID* properties = shorthand.properties();
1349         for (unsigned j = 0; j < shorthand.length(); ++j) {
1350             unsigned wrapperIndex = indexFromPropertyID(properties[j]);
1351             if (wrapperIndex == cInvalidPropertyWrapperIndex)
1352                 continue;
1353             ASSERT(m_propertyWrappers[wrapperIndex]);
1354             longhandWrappers.uncheckedAppend(m_propertyWrappers[wrapperIndex].get());
1355         }
1356
1357         m_propertyWrappers.uncheckedAppend(adoptPtr(new ShorthandPropertyWrapper(propertyID, longhandWrappers)));
1358         indexFromPropertyID(propertyID) = animatableLonghandPropertiesCount + i;
1359     }
1360 }
1361
1362 static bool gatherEnclosingShorthandProperties(CSSPropertyID property, AnimationPropertyWrapperBase* wrapper, HashSet<CSSPropertyID>& propertySet)
1363 {
1364     if (!wrapper->isShorthandWrapper())
1365         return false;
1366
1367     ShorthandPropertyWrapper* shorthandWrapper = static_cast<ShorthandPropertyWrapper*>(wrapper);
1368
1369     bool contained = false;
1370     for (size_t i = 0; i < shorthandWrapper->propertyWrappers().size(); ++i) {
1371         AnimationPropertyWrapperBase* currWrapper = shorthandWrapper->propertyWrappers()[i];
1372
1373         if (gatherEnclosingShorthandProperties(property, currWrapper, propertySet) || currWrapper->property() == property)
1374             contained = true;
1375     }
1376
1377     if (contained)
1378         propertySet.add(wrapper->property());
1379
1380     return contained;
1381 }
1382
1383 // Returns true if we need to start animation timers
1384 bool CSSPropertyAnimation::blendProperties(const AnimationBase* anim, CSSPropertyID prop, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress)
1385 {
1386     ASSERT(prop != CSSPropertyInvalid);
1387
1388     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1389     if (wrapper) {
1390         wrapper->blend(anim, dst, a, b, progress);
1391 #if USE(ACCELERATED_COMPOSITING)
1392         return !wrapper->animationIsAccelerated() || !anim->isAccelerated();
1393 #else
1394         return true;
1395 #endif
1396     }
1397
1398     return false;
1399 }
1400
1401 #if USE(ACCELERATED_COMPOSITING)
1402 bool CSSPropertyAnimation::animationOfPropertyIsAccelerated(CSSPropertyID prop)
1403 {
1404     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1405     return wrapper ? wrapper->animationIsAccelerated() : false;
1406 }
1407 #endif
1408
1409 // Note: this is inefficient. It's only called from pauseTransitionAtTime().
1410 HashSet<CSSPropertyID> CSSPropertyAnimation::animatableShorthandsAffectingProperty(CSSPropertyID property)
1411 {
1412     CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1413
1414     HashSet<CSSPropertyID> foundProperties;
1415     for (unsigned i = 0; i < map.size(); ++i)
1416         gatherEnclosingShorthandProperties(property, map.wrapperForIndex(i), foundProperties);
1417
1418     return foundProperties;
1419 }
1420
1421 bool CSSPropertyAnimation::propertiesEqual(CSSPropertyID prop, const RenderStyle* a, const RenderStyle* b)
1422 {
1423     AnimationPropertyWrapperBase* wrapper = CSSPropertyAnimationWrapperMap::instance().wrapperForProperty(prop);
1424     if (wrapper)
1425         return wrapper->equals(a, b);
1426     return true;
1427 }
1428
1429 CSSPropertyID CSSPropertyAnimation::getPropertyAtIndex(int i, bool& isShorthand)
1430 {
1431     CSSPropertyAnimationWrapperMap& map = CSSPropertyAnimationWrapperMap::instance();
1432
1433     if (i < 0 || static_cast<unsigned>(i) >= map.size())
1434         return CSSPropertyInvalid;
1435
1436     AnimationPropertyWrapperBase* wrapper = map.wrapperForIndex(i);
1437     isShorthand = wrapper->isShorthandWrapper();
1438     return wrapper->property();
1439 }
1440
1441 int CSSPropertyAnimation::getNumProperties()
1442 {
1443     return CSSPropertyAnimationWrapperMap::instance().size();
1444 }
1445
1446 }