| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef InterpolableValue_h | 5 #ifndef InterpolableValue_h |
| 6 #define InterpolableValue_h | 6 #define InterpolableValue_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/animation/animatable/AnimatableValue.h" | 9 #include "core/animation/animatable/AnimatableValue.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "wtf/OwnPtr.h" | 11 #include "wtf/OwnPtr.h" |
| 12 #include "wtf/PassOwnPtr.h" | 12 #include "wtf/PassOwnPtr.h" |
| 13 #include "wtf/Vector.h" | 13 #include "wtf/Vector.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class CORE_EXPORT InterpolableValue : public NoBaseWillBeGarbageCollected<Interp
olableValue> { | 17 class CORE_EXPORT InterpolableValue { |
| 18 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValue); | 18 WTF_MAKE_FAST_ALLOCATED(InterpolableValue); |
| 19 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(InterpolableValue); | |
| 20 public: | 19 public: |
| 20 virtual ~InterpolableValue() { } |
| 21 |
| 21 virtual bool isNumber() const { return false; } | 22 virtual bool isNumber() const { return false; } |
| 22 virtual bool isBool() const { return false; } | 23 virtual bool isBool() const { return false; } |
| 23 virtual bool isList() const { return false; } | 24 virtual bool isList() const { return false; } |
| 24 virtual bool isAnimatableValue() const { return false; } | 25 virtual bool isAnimatableValue() const { return false; } |
| 25 | 26 |
| 26 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const = 0; | 27 virtual PassOwnPtr<InterpolableValue> clone() const = 0; |
| 27 | |
| 28 DEFINE_INLINE_VIRTUAL_TRACE() { } | |
| 29 | 28 |
| 30 private: | 29 private: |
| 31 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const = 0; | 30 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const = 0; |
| 32 virtual void scaleAndAdd(double scale, const InterpolableValue& other) = 0; | 31 virtual void scaleAndAdd(double scale, const InterpolableValue& other) = 0; |
| 33 | 32 |
| 34 friend class Interpolation; | 33 friend class Interpolation; |
| 35 friend class PairwisePrimitiveInterpolation; | 34 friend class PairwisePrimitiveInterpolation; |
| 36 friend class InvalidatableStyleInterpolation; | 35 friend class InvalidatableStyleInterpolation; |
| 37 | 36 |
| 38 // Keep interpolate private, but allow calls within the hierarchy without | 37 // Keep interpolate private, but allow calls within the hierarchy without |
| 39 // knowledge of type. | 38 // knowledge of type. |
| 40 friend class DeferredLegacyStyleInterpolation; | 39 friend class DeferredLegacyStyleInterpolation; |
| 41 friend class InterpolableNumber; | 40 friend class InterpolableNumber; |
| 42 friend class InterpolableBool; | 41 friend class InterpolableBool; |
| 43 friend class InterpolableList; | 42 friend class InterpolableList; |
| 44 | 43 |
| 45 friend class AnimationInterpolableValueTest; | 44 friend class AnimationInterpolableValueTest; |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 class CORE_EXPORT InterpolableNumber final : public InterpolableValue { | 47 class CORE_EXPORT InterpolableNumber final : public InterpolableValue { |
| 49 public: | 48 public: |
| 50 static PassOwnPtrWillBeRawPtr<InterpolableNumber> create(double value) | 49 static PassOwnPtr<InterpolableNumber> create(double value) |
| 51 { | 50 { |
| 52 return adoptPtrWillBeNoop(new InterpolableNumber(value)); | 51 return adoptPtr(new InterpolableNumber(value)); |
| 53 } | 52 } |
| 54 | 53 |
| 55 bool isNumber() const final { return true; } | 54 bool isNumber() const final { return true; } |
| 56 double value() const { return m_value; } | 55 double value() const { return m_value; } |
| 57 PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const final { return creat
e(m_value); } | 56 PassOwnPtr<InterpolableValue> clone() const final { return create(m_value);
} |
| 58 | 57 |
| 59 private: | 58 private: |
| 60 void interpolate(const InterpolableValue& to, const double progress, Interpo
lableValue& result) const final; | 59 void interpolate(const InterpolableValue& to, const double progress, Interpo
lableValue& result) const final; |
| 61 void scaleAndAdd(double scale, const InterpolableValue& other) final; | 60 void scaleAndAdd(double scale, const InterpolableValue& other) final; |
| 62 double m_value; | 61 double m_value; |
| 63 | 62 |
| 64 explicit InterpolableNumber(double value) | 63 explicit InterpolableNumber(double value) |
| 65 : m_value(value) | 64 : m_value(value) |
| 66 { | 65 { |
| 67 } | 66 } |
| 68 | 67 |
| 69 }; | 68 }; |
| 70 | 69 |
| 71 class CORE_EXPORT InterpolableBool final : public InterpolableValue { | 70 class CORE_EXPORT InterpolableBool final : public InterpolableValue { |
| 72 public: | 71 public: |
| 73 static PassOwnPtrWillBeRawPtr<InterpolableBool> create(bool value) | 72 static PassOwnPtr<InterpolableBool> create(bool value) |
| 74 { | 73 { |
| 75 return adoptPtrWillBeNoop(new InterpolableBool(value)); | 74 return adoptPtr(new InterpolableBool(value)); |
| 76 } | 75 } |
| 77 | 76 |
| 78 bool isBool() const final { return true; } | 77 bool isBool() const final { return true; } |
| 79 bool value() const { return m_value; } | 78 bool value() const { return m_value; } |
| 80 PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const final { return creat
e(m_value); } | 79 PassOwnPtr<InterpolableValue> clone() const final { return create(m_value);
} |
| 81 | 80 |
| 82 private: | 81 private: |
| 83 void interpolate(const InterpolableValue& to, const double progress, Interpo
lableValue& result) const final; | 82 void interpolate(const InterpolableValue& to, const double progress, Interpo
lableValue& result) const final; |
| 84 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER
T_NOT_REACHED(); } | 83 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER
T_NOT_REACHED(); } |
| 85 bool m_value; | 84 bool m_value; |
| 86 | 85 |
| 87 explicit InterpolableBool(bool value) | 86 explicit InterpolableBool(bool value) |
| 88 : m_value(value) | 87 : m_value(value) |
| 89 { | 88 { |
| 90 } | 89 } |
| 91 | 90 |
| 92 }; | 91 }; |
| 93 | 92 |
| 94 class CORE_EXPORT InterpolableList : public InterpolableValue { | 93 class CORE_EXPORT InterpolableList : public InterpolableValue { |
| 95 public: | 94 public: |
| 96 // Explicitly delete operator= because MSVC automatically generate | 95 // Explicitly delete operator= because MSVC automatically generate |
| 97 // copy constructors and operator= for dll-exported classes. | 96 // copy constructors and operator= for dll-exported classes. |
| 98 // Since InterpolableList is not copyable, automatically generated | 97 // Since InterpolableList is not copyable, automatically generated |
| 99 // operator= causes MSVC compiler error. | 98 // operator= causes MSVC compiler error. |
| 100 // However, we cannot use WTF_MAKE_NONCOPYABLE because InterpolableList | 99 // However, we cannot use WTF_MAKE_NONCOPYABLE because InterpolableList |
| 101 // has its own copy constructor. So just delete operator= here. | 100 // has its own copy constructor. So just delete operator= here. |
| 102 InterpolableList& operator=(const InterpolableList&) = delete; | 101 InterpolableList& operator=(const InterpolableList&) = delete; |
| 103 | 102 |
| 104 static PassOwnPtrWillBeRawPtr<InterpolableList> create(const InterpolableLis
t &other) | 103 static PassOwnPtr<InterpolableList> create(const InterpolableList &other) |
| 105 { | 104 { |
| 106 return adoptPtrWillBeNoop(new InterpolableList(other)); | 105 return adoptPtr(new InterpolableList(other)); |
| 107 } | 106 } |
| 108 | 107 |
| 109 static PassOwnPtrWillBeRawPtr<InterpolableList> create(size_t size) | 108 static PassOwnPtr<InterpolableList> create(size_t size) |
| 110 { | 109 { |
| 111 return adoptPtrWillBeNoop(new InterpolableList(size)); | 110 return adoptPtr(new InterpolableList(size)); |
| 112 } | 111 } |
| 113 | 112 |
| 114 bool isList() const final { return true; } | 113 bool isList() const final { return true; } |
| 115 void set(size_t position, PassOwnPtrWillBeRawPtr<InterpolableValue> value) | 114 void set(size_t position, PassOwnPtr<InterpolableValue> value) |
| 116 { | 115 { |
| 117 ASSERT(position < m_size); | 116 ASSERT(position < m_size); |
| 118 m_values[position] = value; | 117 m_values[position] = value; |
| 119 } | 118 } |
| 120 const InterpolableValue* get(size_t position) const | 119 const InterpolableValue* get(size_t position) const |
| 121 { | 120 { |
| 122 ASSERT(position < m_size); | 121 ASSERT(position < m_size); |
| 123 return m_values[position].get(); | 122 return m_values[position].get(); |
| 124 } | 123 } |
| 125 InterpolableValue* get(size_t position) | 124 InterpolableValue* get(size_t position) |
| 126 { | 125 { |
| 127 ASSERT(position < m_size); | 126 ASSERT(position < m_size); |
| 128 return m_values[position].get(); | 127 return m_values[position].get(); |
| 129 } | 128 } |
| 130 size_t length() const { return m_size; } | 129 size_t length() const { return m_size; } |
| 131 PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const final { return creat
e(*this); } | 130 PassOwnPtr<InterpolableValue> clone() const final { return create(*this); } |
| 132 | |
| 133 DECLARE_VIRTUAL_TRACE(); | |
| 134 | 131 |
| 135 private: | 132 private: |
| 136 void interpolate(const InterpolableValue& to, const double progress, Interpo
lableValue& result) const final; | 133 void interpolate(const InterpolableValue& to, const double progress, Interpo
lableValue& result) const final; |
| 137 void scaleAndAdd(double scale, const InterpolableValue& other) final; | 134 void scaleAndAdd(double scale, const InterpolableValue& other) final; |
| 138 explicit InterpolableList(size_t size) | 135 explicit InterpolableList(size_t size) |
| 139 : m_size(size) | 136 : m_size(size) |
| 140 , m_values(m_size) | 137 , m_values(m_size) |
| 141 { | 138 { |
| 142 } | 139 } |
| 143 | 140 |
| 144 InterpolableList(const InterpolableList& other) | 141 InterpolableList(const InterpolableList& other) |
| 145 : m_size(other.m_size) | 142 : m_size(other.m_size) |
| 146 , m_values(m_size) | 143 , m_values(m_size) |
| 147 { | 144 { |
| 148 for (size_t i = 0; i < m_size; i++) | 145 for (size_t i = 0; i < m_size; i++) |
| 149 set(i, other.m_values[i]->clone()); | 146 set(i, other.m_values[i]->clone()); |
| 150 } | 147 } |
| 151 | 148 |
| 152 size_t m_size; | 149 size_t m_size; |
| 153 WillBeHeapVector<OwnPtrWillBeMember<InterpolableValue>> m_values; | 150 Vector<OwnPtr<InterpolableValue>> m_values; |
| 154 }; | 151 }; |
| 155 | 152 |
| 156 // FIXME: Remove this when we can. | 153 // FIXME: Remove this when we can. |
| 157 class InterpolableAnimatableValue : public InterpolableValue { | 154 class InterpolableAnimatableValue : public InterpolableValue { |
| 158 public: | 155 public: |
| 159 static PassOwnPtrWillBeRawPtr<InterpolableAnimatableValue> create(PassRefPtr
WillBeRawPtr<AnimatableValue> value) | 156 static PassOwnPtr<InterpolableAnimatableValue> create(PassRefPtr<AnimatableV
alue> value) |
| 160 { | 157 { |
| 161 return adoptPtrWillBeNoop(new InterpolableAnimatableValue(value)); | 158 return adoptPtr(new InterpolableAnimatableValue(value)); |
| 162 } | 159 } |
| 163 | 160 |
| 164 bool isAnimatableValue() const final { return true; } | 161 bool isAnimatableValue() const final { return true; } |
| 165 AnimatableValue* value() const { return m_value.get(); } | 162 AnimatableValue* value() const { return m_value.get(); } |
| 166 PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const final { return creat
e(m_value); } | 163 PassOwnPtr<InterpolableValue> clone() const final { return create(m_value);
} |
| 167 | |
| 168 DECLARE_VIRTUAL_TRACE(); | |
| 169 | 164 |
| 170 private: | 165 private: |
| 171 void interpolate(const InterpolableValue &to, const double progress, Interpo
lableValue& result) const final; | 166 void interpolate(const InterpolableValue &to, const double progress, Interpo
lableValue& result) const final; |
| 172 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER
T_NOT_REACHED(); } | 167 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER
T_NOT_REACHED(); } |
| 173 RefPtrWillBeMember<AnimatableValue> m_value; | 168 RefPtr<AnimatableValue> m_value; |
| 174 | 169 |
| 175 InterpolableAnimatableValue(PassRefPtrWillBeRawPtr<AnimatableValue> value) | 170 InterpolableAnimatableValue(PassRefPtr<AnimatableValue> value) |
| 176 : m_value(value) | 171 : m_value(value) |
| 177 { | 172 { |
| 178 } | 173 } |
| 179 }; | 174 }; |
| 180 | 175 |
| 181 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); | 176 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); |
| 182 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); | 177 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); |
| 183 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); | 178 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); |
| 184 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); | 179 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); |
| 185 | 180 |
| 186 } | 181 } |
| 187 | 182 |
| 188 #endif | 183 #endif |
| OLD | NEW |