| 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/animation/animatable/AnimatableValue.h" | 8 #include "core/animation/animatable/AnimatableValue.h" |
| 9 #include "wtf/OwnPtr.h" | 9 #include "wtf/OwnPtr.h" |
| 10 #include "wtf/PassOwnPtr.h" | 10 #include "wtf/PassOwnPtr.h" |
| 11 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 class InterpolableValue : public NoBaseWillBeGarbageCollected<InterpolableValue>
{ | 15 class InterpolableValue : public NoBaseWillBeGarbageCollected<InterpolableValue>
{ |
| 16 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValue); | 16 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValue); |
| 17 public: | 17 public: |
| 18 virtual bool isNumber() const { return false; } | 18 virtual bool isNumber() const { return false; } |
| 19 virtual bool isBool() const { return false; } | 19 virtual bool isBool() const { return false; } |
| 20 virtual bool isList() const { return false; } | 20 virtual bool isList() const { return false; } |
| 21 virtual bool isAnimatableValue() const { return false; } | 21 virtual bool isAnimatableValue() const { return false; } |
| 22 | 22 |
| 23 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const = 0; | 23 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const = 0; |
| 24 | 24 |
| 25 virtual void trace(Visitor*) { } | 25 virtual void trace(Visitor*) { } |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol
ableValue &to, const double progress) const = 0; | 28 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const = 0; |
| 29 | 29 |
| 30 friend class Interpolation; | 30 friend class Interpolation; |
| 31 | 31 |
| 32 // Keep interpolate private, but allow calls within the hierarchy without | 32 // Keep interpolate private, but allow calls within the hierarchy without |
| 33 // knowledge of type. | 33 // knowledge of type. |
| 34 friend class DeferredLegacyStyleInterpolation; | 34 friend class DeferredLegacyStyleInterpolation; |
| 35 friend class InterpolableNumber; | 35 friend class InterpolableNumber; |
| 36 friend class InterpolableBool; | 36 friend class InterpolableBool; |
| 37 friend class InterpolableList; | 37 friend class InterpolableList; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 class InterpolableNumber : public InterpolableValue { | 40 class InterpolableNumber : public InterpolableValue { |
| 41 public: | 41 public: |
| 42 static PassOwnPtrWillBeRawPtr<InterpolableNumber> create(double value) | 42 static PassOwnPtrWillBeRawPtr<InterpolableNumber> create(double value) |
| 43 { | 43 { |
| 44 return adoptPtrWillBeNoop(new InterpolableNumber(value)); | 44 return adoptPtrWillBeNoop(new InterpolableNumber(value)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 virtual bool isNumber() const override final { return true; } | 47 virtual bool isNumber() const override final { return true; } |
| 48 double value() const { return m_value; } | 48 double value() const { return m_value; } |
| 49 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } | 49 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } |
| 50 | 50 |
| 51 virtual void trace(Visitor* visitor) override { InterpolableValue::trace(vis
itor); } | 51 virtual void trace(Visitor* visitor) override { InterpolableValue::trace(vis
itor); } |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol
ableValue &to, const double progress) const override final; | 54 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; |
| 55 double m_value; | 55 double m_value; |
| 56 | 56 |
| 57 explicit InterpolableNumber(double value) | 57 explicit InterpolableNumber(double value) |
| 58 : m_value(value) | 58 : m_value(value) |
| 59 { | 59 { |
| 60 } | 60 } |
| 61 | 61 |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class InterpolableBool : public InterpolableValue { | 64 class InterpolableBool : public InterpolableValue { |
| 65 public: | 65 public: |
| 66 static PassOwnPtrWillBeRawPtr<InterpolableBool> create(bool value) | 66 static PassOwnPtrWillBeRawPtr<InterpolableBool> create(bool value) |
| 67 { | 67 { |
| 68 return adoptPtrWillBeNoop(new InterpolableBool(value)); | 68 return adoptPtrWillBeNoop(new InterpolableBool(value)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual bool isBool() const override final { return true; } | 71 virtual bool isBool() const override final { return true; } |
| 72 bool value() const { return m_value; } | 72 bool value() const { return m_value; } |
| 73 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } | 73 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } |
| 74 | 74 |
| 75 virtual void trace(Visitor* visitor) override { InterpolableValue::trace(vis
itor); } | 75 virtual void trace(Visitor* visitor) override { InterpolableValue::trace(vis
itor); } |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol
ableValue &to, const double progress) const override final; | 78 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; |
| 79 bool m_value; | 79 bool m_value; |
| 80 | 80 |
| 81 explicit InterpolableBool(bool value) | 81 explicit InterpolableBool(bool value) |
| 82 : m_value(value) | 82 : m_value(value) |
| 83 { | 83 { |
| 84 } | 84 } |
| 85 | 85 |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 class InterpolableList : public InterpolableValue { | 88 class InterpolableList : public InterpolableValue { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 107 { | 107 { |
| 108 ASSERT(position < m_size); | 108 ASSERT(position < m_size); |
| 109 return m_values[position].get(); | 109 return m_values[position].get(); |
| 110 } | 110 } |
| 111 size_t length() const { return m_size; } | 111 size_t length() const { return m_size; } |
| 112 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(*this); } | 112 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(*this); } |
| 113 | 113 |
| 114 virtual void trace(Visitor*) override; | 114 virtual void trace(Visitor*) override; |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol
ableValue &other, const double progress) const override final; | 117 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; |
| 118 explicit InterpolableList(size_t size) | 118 explicit InterpolableList(size_t size) |
| 119 : m_size(size) | 119 : m_size(size) |
| 120 , m_values(m_size) | 120 , m_values(m_size) |
| 121 { | 121 { |
| 122 } | 122 } |
| 123 | 123 |
| 124 InterpolableList(const InterpolableList& other) | 124 InterpolableList(const InterpolableList& other) |
| 125 : m_size(other.m_size) | 125 : m_size(other.m_size) |
| 126 , m_values(m_size) | 126 , m_values(m_size) |
| 127 { | 127 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 return adoptPtrWillBeNoop(new InterpolableAnimatableValue(value)); | 141 return adoptPtrWillBeNoop(new InterpolableAnimatableValue(value)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 virtual bool isAnimatableValue() const override final { return true; } | 144 virtual bool isAnimatableValue() const override final { return true; } |
| 145 AnimatableValue* value() const { return m_value.get(); } | 145 AnimatableValue* value() const { return m_value.get(); } |
| 146 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } | 146 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } |
| 147 | 147 |
| 148 virtual void trace(Visitor*) override; | 148 virtual void trace(Visitor*) override; |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol
ableValue &other, const double progress) const override final; | 151 virtual void interpolate(const InterpolableValue &to, const double progress,
InterpolableValue& result) const override final; |
| 152 RefPtrWillBeMember<AnimatableValue> m_value; | 152 RefPtrWillBeMember<AnimatableValue> m_value; |
| 153 | 153 |
| 154 InterpolableAnimatableValue(PassRefPtrWillBeRawPtr<AnimatableValue> value) | 154 InterpolableAnimatableValue(PassRefPtrWillBeRawPtr<AnimatableValue> value) |
| 155 : m_value(value) | 155 : m_value(value) |
| 156 { | 156 { |
| 157 } | 157 } |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); | 160 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); |
| 161 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); | 161 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); |
| 162 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); | 162 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); |
| 163 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); | 163 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); |
| 164 | 164 |
| 165 } | 165 } |
| 166 | 166 |
| 167 #endif | 167 #endif |
| OLD | NEW |