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"
35e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/RefCounted.h"
365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
39e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass AnimatableValue : public RefCounted<AnimatableValue> {
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
41e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    virtual ~AnimatableValue() { }
42e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
43e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    static const AnimatableValue* neutralValue();
4402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
45e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    static PassRefPtr<AnimatableValue> interpolate(const AnimatableValue*, const AnimatableValue*, double fraction);
46e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // For noncommutative values read add(A, B) to mean the value A with B composed onto it.
47e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    static PassRefPtr<AnimatableValue> add(const AnimatableValue*, const AnimatableValue*);
48e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool equals(const AnimatableValue* value) const
501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return isSameType(value) && equalTo(value);
521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool equals(const AnimatableValue& value) const
541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return equals(&value);
561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isClipPathOperation() const { return type() == TypeClipPathOperation; }
591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isColor() const { return type() == TypeColor; }
601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isDouble() const { return type() == TypeDouble; }
61f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    bool isFilterOperations() const { return type() == TypeFilterOperations; }
621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isImage() const { return type() == TypeImage; }
631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isLength() const { return type() == TypeLength; }
641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isLengthBox() const { return type() == TypeLengthBox; }
65bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    bool isLengthBoxAndBool() const { return type() == TypeLengthBoxAndBool; }
66bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    bool isLengthPoint() const { return type() == TypeLengthPoint; }
671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isLengthSize() const { return type() == TypeLengthSize; }
681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isNeutral() const { return type() == TypeNeutral; }
691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isRepeatable() const { return type() == TypeRepeatable; }
701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isSVGLength() const { return type() == TypeSVGLength; }
711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isSVGPaint() const { return type() == TypeSVGPaint; }
72f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    bool isShadow() const { return type() == TypeShadow; }
731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isShapeValue() const { return type() == TypeShapeValue; }
741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isStrokeDasharrayList() const { return type() == TypeStrokeDasharrayList; }
751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isTransform() const { return type() == TypeTransform; }
761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isUnknown() const { return type() == TypeUnknown; }
771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isVisibility() const { return type() == TypeVisibility; }
781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    bool isSameType(const AnimatableValue* value) const
801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    {
811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        ASSERT(value);
821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return value->type() == type();
831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
841fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch
85bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    bool usesNonDefaultInterpolationWith(const AnimatableValue* value) const
86bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    {
87bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        return isSameType(value) && !isUnknown();
88bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    }
89bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
90e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochprotected:
91e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    enum AnimatableType {
921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeClipPathOperation,
93c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        TypeColor,
941e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeDouble,
95f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        TypeFilterOperations,
96c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        TypeImage,
971e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeLength,
98c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)        TypeLengthBox,
99bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        TypeLengthBoxAndBool,
100bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)        TypeLengthPoint,
1011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeLengthSize,
102e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        TypeNeutral,
1031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeRepeatable,
1041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeSVGLength,
1051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeSVGPaint,
106f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)        TypeShadow,
1071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeShapeValue,
1081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        TypeStrokeDasharrayList,
109e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        TypeTransform,
110e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        TypeUnknown,
1118abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)        TypeVisibility,
112e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    };
113e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
114e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, double fraction) const = 0;
115e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    static PassRefPtr<AnimatableValue> defaultInterpolateTo(const AnimatableValue* left, const AnimatableValue* right, double fraction) { return takeConstRef((fraction < 0.5) ? left : right); }
116e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
117e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    // For noncommutative values read A->addWith(B) to mean the value A with B composed onto it.
1188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const;
119e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    static PassRefPtr<AnimatableValue> defaultAddWith(const AnimatableValue* left, const AnimatableValue* right) { return takeConstRef(right); }
120e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch
121e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    template <class T>
122e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    static PassRefPtr<T> takeConstRef(const T* value) { return PassRefPtr<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;
1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
130bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#define DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(thisType, predicate) \
131bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    DEFINE_TYPE_CASTS(thisType, AnimatableValue, value, value->predicate, value.predicate)
132bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)
1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore
1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif // AnimatableValue_h
136