2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef AnimatableValue_h
32 #define AnimatableValue_h
34 #include "core/css/CSSValue.h"
35 #include "platform/heap/Handle.h"
36 #include "wtf/RefCounted.h"
40 class AnimatableValue : public RefCountedWillBeGarbageCollectedFinalized<AnimatableValue> {
42 virtual ~AnimatableValue() { }
44 static const AnimatableValue* neutralValue();
46 static PassRefPtrWillBeRawPtr<AnimatableValue> interpolate(const AnimatableValue*, const AnimatableValue*, double fraction);
47 static double distance(const AnimatableValue* from, const AnimatableValue* to);
48 static bool usesDefaultInterpolation(const AnimatableValue* from, const AnimatableValue* to)
50 return !from->isSameType(to) || from->usesDefaultInterpolationWith(to);
53 bool equals(const AnimatableValue* value) const
55 return isSameType(value) && equalTo(value);
57 bool equals(const AnimatableValue& value) const
59 return equals(&value);
62 bool isClipPathOperation() const { return type() == TypeClipPathOperation; }
63 bool isColor() const { return type() == TypeColor; }
64 bool isDouble() const { return type() == TypeDouble; }
65 bool isFilterOperations() const { return type() == TypeFilterOperations; }
66 bool isImage() const { return type() == TypeImage; }
67 bool isLength() const { return type() == TypeLength; }
68 bool isLengthBox() const { return type() == TypeLengthBox; }
69 bool isLengthBoxAndBool() const { return type() == TypeLengthBoxAndBool; }
70 bool isLengthPoint() const { return type() == TypeLengthPoint; }
71 bool isLengthPoint3D() const { return type() == TypeLengthPoint3D; }
72 bool isLengthSize() const { return type() == TypeLengthSize; }
73 bool isNeutral() const { return type() == TypeNeutral; }
74 bool isRepeatable() const { return type() == TypeRepeatable; }
75 bool isSVGLength() const { return type() == TypeSVGLength; }
76 bool isSVGPaint() const { return type() == TypeSVGPaint; }
77 bool isShadow() const { return type() == TypeShadow; }
78 bool isShapeValue() const { return type() == TypeShapeValue; }
79 bool isStrokeDasharrayList() const { return type() == TypeStrokeDasharrayList; }
80 bool isTransform() const { return type() == TypeTransform; }
81 bool isUnknown() const { return type() == TypeUnknown; }
82 bool isVisibility() const { return type() == TypeVisibility; }
84 bool isSameType(const AnimatableValue* value) const
87 return value->type() == type();
90 virtual void trace(Visitor*) { }
94 TypeClipPathOperation,
101 TypeLengthBoxAndBool,
111 TypeStrokeDasharrayList,
117 virtual bool usesDefaultInterpolationWith(const AnimatableValue* value) const { return false; }
118 virtual PassRefPtrWillBeRawPtr<AnimatableValue> interpolateTo(const AnimatableValue*, double fraction) const = 0;
119 static PassRefPtrWillBeRawPtr<AnimatableValue> defaultInterpolateTo(const AnimatableValue* left, const AnimatableValue* right, double fraction) { return takeConstRef((fraction < 0.5) ? left : right); }
122 static PassRefPtrWillBeRawPtr<T> takeConstRef(const T* value) { return PassRefPtrWillBeRawPtr<T>(const_cast<T*>(value)); }
125 virtual AnimatableType type() const = 0;
126 // Implementations can assume that the object being compared has the same type as the object this is called on
127 virtual bool equalTo(const AnimatableValue*) const = 0;
129 virtual double distanceTo(const AnimatableValue*) const;
131 template <class Keyframe> friend class KeyframeEffectModel;
134 #define DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(thisType, predicate) \
135 DEFINE_TYPE_CASTS(thisType, AnimatableValue, value, value->predicate, value.predicate)
139 #endif // AnimatableValue_h