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/animation/AnimationEffect.h"
35 #include "core/css/CSSValue.h"
36 #include "wtf/RefCounted.h"
40 class AnimatableValue : public AnimationEffect::CompositableValue {
42 virtual ~AnimatableValue() { }
44 static const AnimatableValue* neutralValue();
46 static PassRefPtr<AnimatableValue> interpolate(const AnimatableValue*, const AnimatableValue*, double fraction);
47 // For noncommutative values read add(A, B) to mean the value A with B composed onto it.
48 static PassRefPtr<AnimatableValue> add(const AnimatableValue*, const AnimatableValue*);
49 static bool usesDefaultInterpolation(const AnimatableValue* from, const AnimatableValue* to)
51 return !from->isSameType(to) || from->usesDefaultInterpolationWith(to);
54 bool equals(const AnimatableValue* value) const
56 return isSameType(value) && equalTo(value);
58 bool equals(const AnimatableValue& value) const
60 return equals(&value);
63 virtual bool dependsOnUnderlyingValue() const OVERRIDE FINAL { return false; }
64 virtual PassRefPtr<AnimatableValue> compositeOnto(const AnimatableValue*) const OVERRIDE FINAL { return takeConstRef(this); }
66 bool isClipPathOperation() const { return type() == TypeClipPathOperation; }
67 bool isColor() const { return type() == TypeColor; }
68 bool isDouble() const { return type() == TypeDouble; }
69 bool isFilterOperations() const { return type() == TypeFilterOperations; }
70 bool isImage() const { return type() == TypeImage; }
71 bool isLength() const { return type() == TypeLength; }
72 bool isLengthBox() const { return type() == TypeLengthBox; }
73 bool isLengthBoxAndBool() const { return type() == TypeLengthBoxAndBool; }
74 bool isLengthPoint() const { return type() == TypeLengthPoint; }
75 bool isLengthSize() const { return type() == TypeLengthSize; }
76 bool isNeutral() const { return type() == TypeNeutral; }
77 bool isRepeatable() const { return type() == TypeRepeatable; }
78 bool isSVGLength() const { return type() == TypeSVGLength; }
79 bool isSVGPaint() const { return type() == TypeSVGPaint; }
80 bool isShadow() const { return type() == TypeShadow; }
81 bool isShapeValue() const { return type() == TypeShapeValue; }
82 bool isStrokeDasharrayList() const { return type() == TypeStrokeDasharrayList; }
83 bool isTransform() const { return type() == TypeTransform; }
84 bool isUnknown() const { return type() == TypeUnknown; }
85 bool isVisibility() const { return type() == TypeVisibility; }
87 bool isSameType(const AnimatableValue* value) const
90 return value->type() == type();
95 TypeClipPathOperation,
102 TypeLengthBoxAndBool,
111 TypeStrokeDasharrayList,
117 virtual bool usesDefaultInterpolationWith(const AnimatableValue* value) const { return false; }
118 virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, double fraction) const = 0;
119 static PassRefPtr<AnimatableValue> defaultInterpolateTo(const AnimatableValue* left, const AnimatableValue* right, double fraction) { return takeConstRef((fraction < 0.5) ? left : right); }
121 // For noncommutative values read A->addWith(B) to mean the value A with B composed onto it.
122 virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const;
123 static PassRefPtr<AnimatableValue> defaultAddWith(const AnimatableValue* left, const AnimatableValue* right) { return takeConstRef(right); }
128 static PassRefPtr<T> takeConstRef(const T* value) { return PassRefPtr<T>(const_cast<T*>(value)); }
131 virtual AnimatableType type() const = 0;
132 // Implementations can assume that the object being compared has the same type as the object this is called on
133 virtual bool equalTo(const AnimatableValue*) const = 0;
135 friend class KeyframeEffectModel;
138 #define DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(thisType, predicate) \
139 DEFINE_TYPE_CASTS(thisType, AnimatableValue, value, value->predicate, value.predicate)
141 } // namespace WebCore
143 #endif // AnimatableValue_h