OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 class CORE_EXPORT AnimatableValue : public RefCounted<AnimatableValue> { | 41 class CORE_EXPORT AnimatableValue : public RefCounted<AnimatableValue> { |
42 public: | 42 public: |
43 virtual ~AnimatableValue() {} | 43 virtual ~AnimatableValue() {} |
44 | 44 |
45 static PassRefPtr<AnimatableValue> Interpolate(const AnimatableValue*, | 45 static PassRefPtr<AnimatableValue> Interpolate(const AnimatableValue*, |
46 const AnimatableValue*, | 46 const AnimatableValue*, |
47 double fraction); | 47 double fraction); |
48 static bool UsesDefaultInterpolation(const AnimatableValue* from, | |
49 const AnimatableValue* to) { | |
50 return !from->IsSameType(to) || from->UsesDefaultInterpolationWith(to); | |
51 } | |
52 | |
53 bool Equals(const AnimatableValue* value) const { | |
54 return IsSameType(value) && EqualTo(value); | |
55 } | |
56 bool Equals(const AnimatableValue& value) const { return Equals(&value); } | |
57 | |
58 bool IsClipPathOperation() const { | |
59 return GetType() == kTypeClipPathOperation; | |
60 } | |
61 bool IsColor() const { return GetType() == kTypeColor; } | |
62 bool IsDouble() const { return GetType() == kTypeDouble; } | 48 bool IsDouble() const { return GetType() == kTypeDouble; } |
63 bool IsDoubleAndBool() const { return GetType() == kTypeDoubleAndBool; } | |
64 bool IsFilterOperations() const { return GetType() == kTypeFilterOperations; } | 49 bool IsFilterOperations() const { return GetType() == kTypeFilterOperations; } |
65 bool IsFontVariationSettings() const { | |
66 return GetType() == kTypeFontVariationSettings; | |
67 } | |
68 bool IsImage() const { return GetType() == kTypeImage; } | |
69 bool IsLength() const { return GetType() == kTypeLength; } | |
70 bool IsLengthBox() const { return GetType() == kTypeLengthBox; } | |
71 bool IsLengthBoxAndBool() const { return GetType() == kTypeLengthBoxAndBool; } | |
72 bool IsLengthPoint() const { return GetType() == kTypeLengthPoint; } | |
73 bool IsLengthPoint3D() const { return GetType() == kTypeLengthPoint3D; } | |
74 bool IsLengthSize() const { return GetType() == kTypeLengthSize; } | |
75 bool IsPath() const { return GetType() == kTypePath; } | |
76 bool IsRepeatable() const { return GetType() == kTypeRepeatable; } | |
77 bool IsSVGLength() const { return GetType() == kTypeSVGLength; } | |
78 bool IsSVGPaint() const { return GetType() == kTypeSVGPaint; } | |
79 bool IsShadow() const { return GetType() == kTypeShadow; } | |
80 bool IsShapeValue() const { return GetType() == kTypeShapeValue; } | |
81 bool IsStrokeDasharrayList() const { | |
82 return GetType() == kTypeStrokeDasharrayList; | |
83 } | |
84 bool IsTransform() const { return GetType() == kTypeTransform; } | 50 bool IsTransform() const { return GetType() == kTypeTransform; } |
85 bool IsUnknown() const { return GetType() == kTypeUnknown; } | 51 bool IsUnknown() const { return GetType() == kTypeUnknown; } |
86 bool IsVisibility() const { return GetType() == kTypeVisibility; } | |
87 | 52 |
88 bool IsSameType(const AnimatableValue* value) const { | 53 bool IsSameType(const AnimatableValue* value) const { |
89 DCHECK(value); | 54 DCHECK(value); |
90 return value->GetType() == GetType(); | 55 return value->GetType() == GetType(); |
91 } | 56 } |
92 | 57 |
93 protected: | 58 protected: |
94 enum AnimatableType { | 59 enum AnimatableType { |
95 kTypeClipPathOperation, | |
96 kTypeColor, | |
97 kTypeDouble, | 60 kTypeDouble, |
98 kTypeDoubleAndBool, | |
99 kTypeFilterOperations, | 61 kTypeFilterOperations, |
100 kTypeFontVariationSettings, | |
101 kTypeImage, | |
102 kTypeLength, | |
103 kTypeLengthBox, | |
104 kTypeLengthBoxAndBool, | |
105 kTypeLengthPoint, | |
106 kTypeLengthPoint3D, | |
107 kTypeLengthSize, | |
108 kTypePath, | |
109 kTypeRepeatable, | |
110 kTypeSVGLength, | |
111 kTypeSVGPaint, | |
112 kTypeShadow, | |
113 kTypeShapeValue, | |
114 kTypeStrokeDasharrayList, | |
115 kTypeTransform, | 62 kTypeTransform, |
116 kTypeUnknown, | 63 kTypeUnknown, |
117 kTypeVisibility, | |
118 }; | 64 }; |
119 | 65 |
120 virtual bool UsesDefaultInterpolationWith( | |
121 const AnimatableValue* value) const { | |
122 NOTREACHED(); | |
123 return false; | |
124 } | |
125 virtual PassRefPtr<AnimatableValue> InterpolateTo(const AnimatableValue*, | 66 virtual PassRefPtr<AnimatableValue> InterpolateTo(const AnimatableValue*, |
126 double fraction) const { | 67 double fraction) const { |
127 NOTREACHED(); | 68 NOTREACHED(); |
128 return nullptr; | 69 return nullptr; |
129 } | 70 } |
130 static PassRefPtr<AnimatableValue> DefaultInterpolateTo( | 71 static PassRefPtr<AnimatableValue> DefaultInterpolateTo( |
131 const AnimatableValue* left, | 72 const AnimatableValue* left, |
132 const AnimatableValue* right, | 73 const AnimatableValue* right, |
133 double fraction) { | 74 double fraction) { |
134 return TakeConstRef((fraction < 0.5) ? left : right); | 75 return TakeConstRef((fraction < 0.5) ? left : right); |
135 } | 76 } |
136 | 77 |
137 template <class T> | 78 template <class T> |
138 static PassRefPtr<T> TakeConstRef(const T* value) { | 79 static PassRefPtr<T> TakeConstRef(const T* value) { |
139 return PassRefPtr<T>(const_cast<T*>(value)); | 80 return PassRefPtr<T>(const_cast<T*>(value)); |
140 } | 81 } |
141 | 82 |
142 private: | 83 private: |
143 virtual AnimatableType GetType() const = 0; | 84 virtual AnimatableType GetType() const = 0; |
144 // Implementations can assume that the object being compared has the same type | |
145 // as the object this is called on | |
146 virtual bool EqualTo(const AnimatableValue*) const = 0; | |
147 | 85 |
148 template <class Keyframe> | 86 template <class Keyframe> |
149 friend class KeyframeEffectModel; | 87 friend class KeyframeEffectModel; |
150 }; | 88 }; |
151 | 89 |
152 #define DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(thisType, predicate) \ | 90 #define DEFINE_ANIMATABLE_VALUE_TYPE_CASTS(thisType, predicate) \ |
153 DEFINE_TYPE_CASTS(thisType, AnimatableValue, value, value->predicate, \ | 91 DEFINE_TYPE_CASTS(thisType, AnimatableValue, value, value->predicate, \ |
154 value.predicate) | 92 value.predicate) |
155 | 93 |
156 } // namespace blink | 94 } // namespace blink |
157 | 95 |
158 #endif // AnimatableValue_h | 96 #endif // AnimatableValue_h |
OLD | NEW |