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