| 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 { | 15 class 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 PassOwnPtr<InterpolableValue> clone() const = 0; | 23 virtual PassOwnPtr<InterpolableValue> clone() const = 0; |
| 24 | 24 |
| 25 virtual void trace(Visitor*) { } | |
| 26 | |
| 27 private: | 25 private: |
| 28 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t
o, const double progress) const = 0; | 26 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t
o, const double progress) const = 0; |
| 29 | 27 |
| 30 friend class Interpolation; | 28 friend class Interpolation; |
| 31 | 29 |
| 32 // Keep interpolate private, but allow calls within the hierarchy without | 30 // Keep interpolate private, but allow calls within the hierarchy without |
| 33 // knowledge of type. | 31 // knowledge of type. |
| 34 friend class DeferredLegacyStyleInterpolation; | 32 friend class DeferredLegacyStyleInterpolation; |
| 35 friend class InterpolableNumber; | 33 friend class InterpolableNumber; |
| 36 friend class InterpolableBool; | 34 friend class InterpolableBool; |
| 37 friend class InterpolableList; | 35 friend class InterpolableList; |
| 38 }; | 36 }; |
| 39 | 37 |
| 40 class InterpolableNumber : public InterpolableValue { | 38 class InterpolableNumber : public InterpolableValue { |
| 41 public: | 39 public: |
| 42 static PassOwnPtr<InterpolableNumber> create(double value) | 40 static PassOwnPtr<InterpolableNumber> create(double value) |
| 43 { | 41 { |
| 44 return adoptPtr(new InterpolableNumber(value)); | 42 return adoptPtr(new InterpolableNumber(value)); |
| 45 } | 43 } |
| 46 | 44 |
| 47 virtual bool isNumber() const override final { return true; } | 45 virtual bool isNumber() const override final { return true; } |
| 48 double value() const { return m_value; } | 46 double value() const { return m_value; } |
| 49 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(m_value); } | 47 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(m_value); } |
| 50 | 48 |
| 51 virtual void trace(Visitor* visitor) override { InterpolableValue::trace(vis
itor); } | |
| 52 | |
| 53 private: | 49 private: |
| 54 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t
o, const double progress) const override final; | 50 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t
o, const double progress) const override final; |
| 55 double m_value; | 51 double m_value; |
| 56 | 52 |
| 57 explicit InterpolableNumber(double value) | 53 explicit InterpolableNumber(double value) |
| 58 : m_value(value) | 54 : m_value(value) |
| 59 { | 55 { |
| 60 } | 56 } |
| 61 | 57 |
| 62 }; | 58 }; |
| 63 | 59 |
| 64 class InterpolableBool : public InterpolableValue { | 60 class InterpolableBool : public InterpolableValue { |
| 65 public: | 61 public: |
| 66 static PassOwnPtr<InterpolableBool> create(bool value) | 62 static PassOwnPtr<InterpolableBool> create(bool value) |
| 67 { | 63 { |
| 68 return adoptPtr(new InterpolableBool(value)); | 64 return adoptPtr(new InterpolableBool(value)); |
| 69 } | 65 } |
| 70 | 66 |
| 71 virtual bool isBool() const override final { return true; } | 67 virtual bool isBool() const override final { return true; } |
| 72 bool value() const { return m_value; } | 68 bool value() const { return m_value; } |
| 73 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(m_value); } | 69 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(m_value); } |
| 74 | 70 |
| 75 virtual void trace(Visitor* visitor) override { InterpolableValue::trace(vis
itor); } | |
| 76 | |
| 77 private: | 71 private: |
| 78 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t
o, const double progress) const override final; | 72 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t
o, const double progress) const override final; |
| 79 bool m_value; | 73 bool m_value; |
| 80 | 74 |
| 81 explicit InterpolableBool(bool value) | 75 explicit InterpolableBool(bool value) |
| 82 : m_value(value) | 76 : m_value(value) |
| 83 { | 77 { |
| 84 } | 78 } |
| 85 | 79 |
| 86 }; | 80 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 104 m_values[position] = value; | 98 m_values[position] = value; |
| 105 } | 99 } |
| 106 const InterpolableValue* get(size_t position) const | 100 const InterpolableValue* get(size_t position) const |
| 107 { | 101 { |
| 108 ASSERT(position < m_size); | 102 ASSERT(position < m_size); |
| 109 return m_values[position].get(); | 103 return m_values[position].get(); |
| 110 } | 104 } |
| 111 size_t length() const { return m_size; } | 105 size_t length() const { return m_size; } |
| 112 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(*this); } | 106 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(*this); } |
| 113 | 107 |
| 114 virtual void trace(Visitor*) override; | |
| 115 | |
| 116 private: | 108 private: |
| 117 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o
ther, const double progress) const override final; | 109 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o
ther, const double progress) const override final; |
| 118 explicit InterpolableList(size_t size) | 110 explicit InterpolableList(size_t size) |
| 119 : m_size(size) | 111 : m_size(size) |
| 120 , m_values(m_size) | 112 , m_values(m_size) |
| 121 { | 113 { |
| 122 } | 114 } |
| 123 | 115 |
| 124 InterpolableList(const InterpolableList& other) | 116 InterpolableList(const InterpolableList& other) |
| 125 : m_size(other.m_size) | 117 : m_size(other.m_size) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 public: | 130 public: |
| 139 static PassOwnPtr<InterpolableAnimatableValue> create(PassRefPtr<AnimatableV
alue> value) | 131 static PassOwnPtr<InterpolableAnimatableValue> create(PassRefPtr<AnimatableV
alue> value) |
| 140 { | 132 { |
| 141 return adoptPtr(new InterpolableAnimatableValue(value)); | 133 return adoptPtr(new InterpolableAnimatableValue(value)); |
| 142 } | 134 } |
| 143 | 135 |
| 144 virtual bool isAnimatableValue() const override final { return true; } | 136 virtual bool isAnimatableValue() const override final { return true; } |
| 145 AnimatableValue* value() const { return m_value.get(); } | 137 AnimatableValue* value() const { return m_value.get(); } |
| 146 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(m_value); } | 138 virtual PassOwnPtr<InterpolableValue> clone() const override final { return
create(m_value); } |
| 147 | 139 |
| 148 virtual void trace(Visitor*) override; | |
| 149 | |
| 150 private: | 140 private: |
| 151 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o
ther, const double progress) const override final; | 141 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o
ther, const double progress) const override final; |
| 152 RefPtr<AnimatableValue> m_value; | 142 RefPtr<AnimatableValue> m_value; |
| 153 | 143 |
| 154 InterpolableAnimatableValue(PassRefPtr<AnimatableValue> value) | 144 InterpolableAnimatableValue(PassRefPtr<AnimatableValue> value) |
| 155 : m_value(value) | 145 : m_value(value) |
| 156 { | 146 { |
| 157 } | 147 } |
| 158 }; | 148 }; |
| 159 | 149 |
| 160 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); | 150 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); |
| 161 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); | 151 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); |
| 162 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); | 152 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); |
| 163 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); | 153 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); |
| 164 | 154 |
| 165 } | 155 } |
| 166 | 156 |
| 167 #endif | 157 #endif |
| OLD | NEW |