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 "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
10 #include "wtf/OwnPtr.h" | 10 #include "wtf/OwnPtr.h" |
11 #include "wtf/PassOwnPtr.h" | 11 #include "wtf/PassOwnPtr.h" |
12 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class InterpolableValue : public NoBaseWillBeGarbageCollected<InterpolableValue>
{ | 16 class InterpolableValue : public NoBaseWillBeGarbageCollected<InterpolableValue>
{ |
17 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValue); | 17 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValue); |
18 public: | 18 public: |
19 virtual bool isNumber() const { return false; } | 19 virtual bool isNumber() const { return false; } |
20 virtual bool isBool() const { return false; } | 20 virtual bool isBool() const { return false; } |
21 virtual bool isList() const { return false; } | 21 virtual bool isList() const { return false; } |
22 virtual bool isAnimatableValue() const { return false; } | 22 virtual bool isAnimatableValue() const { return false; } |
23 | 23 |
| 24 bool typesMatch(const InterpolableValue& other) const; |
| 25 |
24 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const = 0; | 26 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const = 0; |
25 | 27 |
26 virtual void trace(Visitor*) { } | 28 virtual void trace(Visitor*) { } |
27 | 29 |
| 30 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst = 0; |
| 31 virtual void multiply(double scalar, InterpolableValue& result) const = 0; |
28 private: | 32 private: |
29 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const = 0; | 33 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const = 0; |
30 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst = 0; | |
31 virtual void multiply(double scalar, InterpolableValue& result) const = 0; | |
32 | 34 |
33 friend class Interpolation; | 35 friend class Interpolation; |
34 | 36 |
35 // Keep interpolate private, but allow calls within the hierarchy without | 37 // Keep interpolate private, but allow calls within the hierarchy without |
36 // knowledge of type. | 38 // knowledge of type. |
37 friend class DeferredLegacyStyleInterpolation; | 39 friend class DeferredLegacyStyleInterpolation; |
38 friend class InterpolableNumber; | 40 friend class InterpolableNumber; |
39 friend class InterpolableBool; | 41 friend class InterpolableBool; |
40 friend class InterpolableList; | 42 friend class InterpolableList; |
41 | 43 |
42 friend class AnimationInterpolableValueTest; | 44 friend class AnimationInterpolableValueTest; |
43 }; | 45 }; |
44 | 46 |
45 class InterpolableNumber final : public InterpolableValue { | 47 class InterpolableNumber final : public InterpolableValue { |
46 public: | 48 public: |
47 static PassOwnPtrWillBeRawPtr<InterpolableNumber> create(double value) | 49 static PassOwnPtrWillBeRawPtr<InterpolableNumber> create(double value) |
48 { | 50 { |
49 return adoptPtrWillBeNoop(new InterpolableNumber(value)); | 51 return adoptPtrWillBeNoop(new InterpolableNumber(value)); |
50 } | 52 } |
51 | 53 |
52 virtual bool isNumber() const override final { return true; } | 54 virtual bool isNumber() const override final { return true; } |
53 double value() const { return m_value; } | 55 double value() const { return m_value; } |
54 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } | 56 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } |
55 | 57 |
| 58 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final; |
| 59 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final; |
56 private: | 60 private: |
57 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; | 61 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; |
58 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final; | |
59 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final; | |
60 double m_value; | 62 double m_value; |
61 | 63 |
62 explicit InterpolableNumber(double value) | 64 explicit InterpolableNumber(double value) |
63 : m_value(value) | 65 : m_value(value) |
64 { | 66 { |
65 } | 67 } |
66 | 68 |
67 }; | 69 }; |
68 | 70 |
69 class InterpolableBool final : public InterpolableValue { | 71 class InterpolableBool final : public InterpolableValue { |
70 public: | 72 public: |
71 static PassOwnPtrWillBeRawPtr<InterpolableBool> create(bool value) | 73 static PassOwnPtrWillBeRawPtr<InterpolableBool> create(bool value) |
72 { | 74 { |
73 return adoptPtrWillBeNoop(new InterpolableBool(value)); | 75 return adoptPtrWillBeNoop(new InterpolableBool(value)); |
74 } | 76 } |
75 | 77 |
76 virtual bool isBool() const override final { return true; } | 78 virtual bool isBool() const override final { return true; } |
77 bool value() const { return m_value; } | 79 bool value() const { return m_value; } |
78 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } | 80 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } |
79 | 81 |
| 82 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final; |
| 83 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final { ASSERT_NOT_REACHED(); } |
80 private: | 84 private: |
81 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; | 85 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; |
82 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final; | |
83 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final { ASSERT_NOT_REACHED(); } | |
84 bool m_value; | 86 bool m_value; |
85 | 87 |
86 explicit InterpolableBool(bool value) | 88 explicit InterpolableBool(bool value) |
87 : m_value(value) | 89 : m_value(value) |
88 { | 90 { |
89 } | 91 } |
90 | 92 |
91 }; | 93 }; |
92 | 94 |
93 class InterpolableList : public InterpolableValue { | 95 class InterpolableList : public InterpolableValue { |
(...skipping 17 matching lines...) Expand all Loading... |
111 const InterpolableValue* get(size_t position) const | 113 const InterpolableValue* get(size_t position) const |
112 { | 114 { |
113 ASSERT(position < m_size); | 115 ASSERT(position < m_size); |
114 return m_values[position].get(); | 116 return m_values[position].get(); |
115 } | 117 } |
116 size_t length() const { return m_size; } | 118 size_t length() const { return m_size; } |
117 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(*this); } | 119 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(*this); } |
118 | 120 |
119 virtual void trace(Visitor*) override; | 121 virtual void trace(Visitor*) override; |
120 | 122 |
| 123 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final; |
| 124 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final; |
121 private: | 125 private: |
122 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; | 126 virtual void interpolate(const InterpolableValue& to, const double progress,
InterpolableValue& result) const override final; |
123 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final; | |
124 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final; | |
125 explicit InterpolableList(size_t size) | 127 explicit InterpolableList(size_t size) |
126 : m_size(size) | 128 : m_size(size) |
127 , m_values(m_size) | 129 , m_values(m_size) |
128 { | 130 { |
129 } | 131 } |
130 | 132 |
131 InterpolableList(const InterpolableList& other) | 133 InterpolableList(const InterpolableList& other) |
132 : m_size(other.m_size) | 134 : m_size(other.m_size) |
133 , m_values(m_size) | 135 , m_values(m_size) |
134 { | 136 { |
(...skipping 12 matching lines...) Expand all Loading... |
147 { | 149 { |
148 return adoptPtrWillBeNoop(new InterpolableAnimatableValue(value)); | 150 return adoptPtrWillBeNoop(new InterpolableAnimatableValue(value)); |
149 } | 151 } |
150 | 152 |
151 virtual bool isAnimatableValue() const override final { return true; } | 153 virtual bool isAnimatableValue() const override final { return true; } |
152 AnimatableValue* value() const { return m_value.get(); } | 154 AnimatableValue* value() const { return m_value.get(); } |
153 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } | 155 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const override fin
al { return create(m_value); } |
154 | 156 |
155 virtual void trace(Visitor*) override; | 157 virtual void trace(Visitor*) override; |
156 | 158 |
| 159 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final { ASSERT_NOT_REACHED(); } |
| 160 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final { ASSERT_NOT_REACHED(); } |
157 private: | 161 private: |
158 virtual void interpolate(const InterpolableValue &to, const double progress,
InterpolableValue& result) const override final; | 162 virtual void interpolate(const InterpolableValue &to, const double progress,
InterpolableValue& result) const override final; |
159 virtual void add(const InterpolableValue& rhs, InterpolableValue& result) co
nst override final { ASSERT_NOT_REACHED(); } | |
160 virtual void multiply(double scalar, InterpolableValue& result) const overri
de final { ASSERT_NOT_REACHED(); } | |
161 RefPtrWillBeMember<AnimatableValue> m_value; | 163 RefPtrWillBeMember<AnimatableValue> m_value; |
162 | 164 |
163 InterpolableAnimatableValue(PassRefPtrWillBeRawPtr<AnimatableValue> value) | 165 InterpolableAnimatableValue(PassRefPtrWillBeRawPtr<AnimatableValue> value) |
164 : m_value(value) | 166 : m_value(value) |
165 { | 167 { |
166 } | 168 } |
167 }; | 169 }; |
168 | 170 |
169 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); | 171 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber(
), value.isNumber()); |
170 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); | 172 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v
alue.isBool()); |
171 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); | 173 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v
alue.isList()); |
172 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); | 174 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value->
isAnimatableValue(), value.isAnimatableValue()); |
173 | 175 |
174 } | 176 } |
175 | 177 |
176 #endif | 178 #endif |
OLD | NEW |