15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#ifndef AnimatableValue_h
3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define AnimatableValue_h
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/css/CSSValue.h"
35f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "platform/heap/Handle.h"
36e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/RefCounted.h"
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochclass AnimatableValue : public RefCountedWillBeGarbageCollectedFinalized<AnimatableValue> {
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
42e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    virtual ~AnimatableValue() { }
43e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
44e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    static const AnimatableValue* neutralValue();
4502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
4607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    static PassRefPtrWillBeRawPtr<AnimatableValue> interpolate(const AnimatableValue*, const AnimatableValue*, double fraction);
47d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    static double distance(const AnimatableValue* from, const AnimatableValue* to);
4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    static bool usesDefaultInterpolation(const AnimatableValue* from, const AnimatableValue* to)
4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return !from->isSameType(to) || from->usesDefaultInterpolationWith(to);
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
52e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool equals(const AnimatableValue* value) const
541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return isSameType(value) && equalTo(value);
561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool equals(const AnimatableValue& value) const
581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return equals(&value);
601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isClipPathOperation() const { return type() == TypeClipPathOperation; }
631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isColor() const { return type() == TypeColor; }
641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isDouble() const { return type() == TypeDouble; }
65f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    bool isFilterOperations() const { return type() == TypeFilterOperations; }
661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isImage() const { return type() == TypeImage; }
671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isLength() const { return type() == TypeLength; }
681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isLengthBox() const { return type() == TypeLengthBox; }
69bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    bool isLengthBoxAndBool() const { return type() == TypeLengthBoxAndBool; }
70bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    bool isLengthPoint() const { return type() == TypeLengthPoint; }
71aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    bool isLengthPoint3D() const { return type() == TypeLengthPoint3D; }
721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isLengthSize() const { return type() == TypeLengthSize; }
731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isNeutral() const { return type() == TypeNeutral; }
741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isRepeatable() const { return type() == TypeRepeatable; }
751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isSVGLength() const { return type() == TypeSVGLength; }
761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isSVGPaint() const { return type() == TypeSVGPaint; }
77f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    bool isShadow() const { return type() == TypeShadow; }
781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isShapeValue() const { return type() == TypeShapeValue; }
791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isStrokeDasharrayList() const { return type() == TypeStrokeDasharrayList; }
801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isTransform() const { return type() == TypeTransform; }
811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isUnknown() const { return type() == TypeUnknown; }
821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isVisibility() const { return type() == TypeVisibility; }
831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isSameType(const AnimatableValue* value) const
851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        ASSERT(value);
871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return value->type() == type();
881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
891fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch
90323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    virtual void trace(Visitor*) { }
9107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch
92e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochprotected:
93e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    enum AnimatableType {
941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeClipPathOperation,
95c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        TypeColor,
961e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeDouble,
97f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        TypeFilterOperations,
98c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        TypeImage,
991e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeLength,
100c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        TypeLengthBox,
101bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        TypeLengthBoxAndBool,
102bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        TypeLengthPoint,
103aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch        TypeLengthPoint3D,
1041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeLengthSize,
105e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        TypeNeutral,
1061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeRepeatable,
1071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeSVGLength,
1081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeSVGPaint,
109f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        TypeShadow,
1101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeShapeValue,
1111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeStrokeDasharrayList,
112e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        TypeTransform,
113e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        TypeUnknown,
1148abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        TypeVisibility,
115e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    };
116e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
11709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual bool usesDefaultInterpolationWith(const AnimatableValue* value) const { return false; }
11807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    virtual PassRefPtrWillBeRawPtr<AnimatableValue> interpolateTo(const AnimatableValue*, double fraction) const = 0;
11907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    static PassRefPtrWillBeRawPtr<AnimatableValue> defaultInterpolateTo(const AnimatableValue* left, const AnimatableValue* right, double fraction) { return takeConstRef((fraction < 0.5) ? left : right); }
120e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
121e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    template <class T>
12207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    static PassRefPtrWillBeRawPtr<T> takeConstRef(const T* value) { return PassRefPtrWillBeRawPtr<T>(const_cast<T*>(value)); }
123e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
1241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)private:
1251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    virtual AnimatableType type() const = 0;
1261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    // Implementations can assume that the object being compared has the same type as the object this is called on
1271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    virtual bool equalTo(const AnimatableValue*) const = 0;
12809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
129d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    virtual double distanceTo(const AnimatableValue*) const;
130d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
131a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    template <class Keyframe> friend class KeyframeEffectModel;
1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
134bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#define DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(thisType, predicate) \
135bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    DEFINE_TYPE_CASTS(thisType, AnimatableValue, value, value->predicate, value.predicate)
136bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
137c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif // AnimatableValue_h
140