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" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 } | 115 } |
116 | 116 |
117 static std::unique_ptr<InterpolableList> create(size_t size) | 117 static std::unique_ptr<InterpolableList> create(size_t size) |
118 { | 118 { |
119 return wrapUnique(new InterpolableList(size)); | 119 return wrapUnique(new InterpolableList(size)); |
120 } | 120 } |
121 | 121 |
122 bool isList() const final { return true; } | 122 bool isList() const final { return true; } |
123 void set(size_t position, std::unique_ptr<InterpolableValue> value) | 123 void set(size_t position, std::unique_ptr<InterpolableValue> value) |
124 { | 124 { |
125 DCHECK_LT(position, m_size); | |
126 m_values[position] = std::move(value); | 125 m_values[position] = std::move(value); |
127 } | 126 } |
128 const InterpolableValue* get(size_t position) const | 127 const InterpolableValue* get(size_t position) const |
129 { | 128 { |
130 DCHECK_LT(position, m_size); | |
131 return m_values[position].get(); | 129 return m_values[position].get(); |
132 } | 130 } |
133 std::unique_ptr<InterpolableValue>& getMutable(size_t position) | 131 std::unique_ptr<InterpolableValue>& getMutable(size_t position) |
134 { | 132 { |
135 DCHECK_LT(position, m_size); | |
alancutter (OOO until 2018)
2016/08/25 02:03:53
These checks are already performed by Vector::at()
| |
136 return m_values[position]; | 133 return m_values[position]; |
137 } | 134 } |
138 size_t length() const { return m_size; } | 135 size_t length() const { return m_values.size(); } |
139 bool equals(const InterpolableValue& other) const final; | 136 bool equals(const InterpolableValue& other) const final; |
140 std::unique_ptr<InterpolableValue> clone() const final { return create(*this ); } | 137 std::unique_ptr<InterpolableValue> clone() const final { return create(*this ); } |
141 std::unique_ptr<InterpolableValue> cloneAndZero() const final; | 138 std::unique_ptr<InterpolableValue> cloneAndZero() const final; |
142 void scale(double scale) final; | 139 void scale(double scale) final; |
143 void scaleAndAdd(double scale, const InterpolableValue& other) final; | 140 void scaleAndAdd(double scale, const InterpolableValue& other) final; |
144 | 141 |
145 private: | 142 private: |
146 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final; | 143 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final; |
147 explicit InterpolableList(size_t size) | 144 explicit InterpolableList(size_t size) |
148 : m_size(size) | 145 : m_values(size) |
149 , m_values(m_size) | |
150 { | 146 { |
151 } | 147 } |
152 | 148 |
153 InterpolableList(const InterpolableList& other) | 149 InterpolableList(const InterpolableList& other) |
154 : m_size(other.m_size) | 150 : m_values(other.length()) |
155 , m_values(m_size) | |
156 { | 151 { |
157 for (size_t i = 0; i < m_size; i++) | 152 for (size_t i = 0; i < length(); i++) |
158 set(i, other.m_values[i]->clone()); | 153 set(i, other.m_values[i]->clone()); |
159 } | 154 } |
160 | 155 |
161 size_t m_size; | |
162 Vector<std::unique_ptr<InterpolableValue>> m_values; | 156 Vector<std::unique_ptr<InterpolableValue>> m_values; |
163 }; | 157 }; |
164 | 158 |
165 // FIXME: Remove this when we can. | 159 // FIXME: Remove this when we can. |
166 class InterpolableAnimatableValue : public InterpolableValue { | 160 class InterpolableAnimatableValue : public InterpolableValue { |
167 public: | 161 public: |
168 static std::unique_ptr<InterpolableAnimatableValue> create(PassRefPtr<Animat ableValue> value) | 162 static std::unique_ptr<InterpolableAnimatableValue> create(PassRefPtr<Animat ableValue> value) |
169 { | 163 { |
170 return wrapUnique(new InterpolableAnimatableValue(value)); | 164 return wrapUnique(new InterpolableAnimatableValue(value)); |
171 } | 165 } |
(...skipping 17 matching lines...) Expand all Loading... | |
189 }; | 183 }; |
190 | 184 |
191 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber()); | 185 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber()); |
192 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool()); | 186 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool()); |
193 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList()); | 187 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList()); |
194 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value-> isAnimatableValue(), value.isAnimatableValue()); | 188 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value-> isAnimatableValue(), value.isAnimatableValue()); |
195 | 189 |
196 } // namespace blink | 190 } // namespace blink |
197 | 191 |
198 #endif | 192 #endif |
OLD | NEW |