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 #include "config.h" | 5 #include "config.h" |
6 #include "core/animation/LengthStyleInterpolation.h" | 6 #include "core/animation/LengthStyleInterpolation.h" |
7 | 7 |
8 #include "core/animation/css/CSSAnimatableValueFactory.h" | 8 #include "core/animation/css/CSSAnimatableValueFactory.h" |
9 #include "core/css/CSSCalculationValue.h" | 9 #include "core/css/CSSCalculationValue.h" |
10 #include "core/css/resolver/StyleBuilder.h" | 10 #include "core/css/resolver/StyleBuilder.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 namespace { | 198 namespace { |
199 | 199 |
200 static CSSPrimitiveValue::UnitType toUnitType(int lengthUnitType) | 200 static CSSPrimitiveValue::UnitType toUnitType(int lengthUnitType) |
201 { | 201 { |
202 return static_cast<CSSPrimitiveValue::UnitType>(CSSPrimitiveValue::lengthUni
tTypeToUnitType(static_cast<CSSPrimitiveValue::LengthUnitType>(lengthUnitType)))
; | 202 return static_cast<CSSPrimitiveValue::UnitType>(CSSPrimitiveValue::lengthUni
tTypeToUnitType(static_cast<CSSPrimitiveValue::LengthUnitType>(lengthUnitType)))
; |
203 } | 203 } |
204 | 204 |
205 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> constructCalcExpression(Pas
sRefPtrWillBeRawPtr<CSSCalcExpressionNode> previous, const InterpolableList* lis
t, size_t position) | 205 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> constructCalcExpression(con
st InterpolableList* list) |
206 { | 206 { |
207 const InterpolableList* listOfValues = toInterpolableList(list->get(0)); | 207 const InterpolableList* listOfValues = toInterpolableList(list->get(0)); |
208 const InterpolableList* listOfTypes = toInterpolableList(list->get(1)); | 208 const InterpolableList* listOfTypes = toInterpolableList(list->get(1)); |
209 while (position != CSSPrimitiveValue::LengthUnitTypeCount) { | 209 RefPtrWillBeRawPtr<CSSCalcExpressionNode> expression; |
| 210 for (size_t position = 0; position < CSSPrimitiveValue::LengthUnitTypeCount;
position++) { |
210 const InterpolableNumber *subValueType = toInterpolableNumber(listOfType
s->get(position)); | 211 const InterpolableNumber *subValueType = toInterpolableNumber(listOfType
s->get(position)); |
211 if (subValueType->value()) { | 212 if (!subValueType->value()) |
212 RefPtrWillBeRawPtr<CSSCalcExpressionNode> next; | 213 continue; |
213 double value = toInterpolableNumber(listOfValues->get(position))->va
lue(); | 214 double value = toInterpolableNumber(listOfValues->get(position))->value(
); |
214 if (previous) | 215 RefPtrWillBeRawPtr<CSSCalcExpressionNode> currentTerm = CSSCalcValue::cr
eateExpressionNode(CSSPrimitiveValue::create(value, toUnitType(position))); |
215 next = CSSCalcValue::createExpressionNode(previous, CSSCalcValue
::createExpressionNode(CSSPrimitiveValue::create(value, toUnitType(position))),
CalcAdd); | 216 if (expression) |
216 else | 217 expression = CSSCalcValue::createExpressionNode(expression.release()
, currentTerm.release(), CalcAdd); |
217 next = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::cre
ate(value, toUnitType(position))); | 218 else |
218 return constructCalcExpression(next, list, position + 1); | 219 expression = currentTerm.release(); |
219 } | |
220 position++; | |
221 } | 220 } |
222 return previous; | 221 return expression.release(); |
223 } | 222 } |
224 | 223 |
225 static double clampToRange(double x, ValueRange range) | 224 static double clampToRange(double x, ValueRange range) |
226 { | 225 { |
227 return (range == ValueRangeNonNegative && x < 0) ? 0 : x; | 226 return (range == ValueRangeNonNegative && x < 0) ? 0 : x; |
228 } | 227 } |
229 | 228 |
230 static Length lengthFromInterpolableValue(const InterpolableValue& value, Interp
olationRange interpolationRange, float zoom) | 229 static Length lengthFromInterpolableValue(const InterpolableValue& value, Interp
olationRange interpolationRange, float zoom) |
231 { | 230 { |
232 const InterpolableList& values = *toInterpolableList(toInterpolableList(valu
e).get(0)); | 231 const InterpolableList& values = *toInterpolableList(toInterpolableList(valu
e).get(0)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 if (subValueType->value()) { | 275 if (subValueType->value()) { |
277 double value = toInterpolableNumber(listOfValues->get(i))->value
(); | 276 double value = toInterpolableNumber(listOfValues->get(i))->value
(); |
278 if (range == RangeNonNegative && value < 0) | 277 if (range == RangeNonNegative && value < 0) |
279 value = 0; | 278 value = 0; |
280 return CSSPrimitiveValue::create(value, toUnitType(i)); | 279 return CSSPrimitiveValue::create(value, toUnitType(i)); |
281 } | 280 } |
282 } | 281 } |
283 ASSERT_NOT_REACHED(); | 282 ASSERT_NOT_REACHED(); |
284 default: | 283 default: |
285 ValueRange valueRange = (range == RangeNonNegative) ? ValueRangeNonNegat
ive : ValueRangeAll; | 284 ValueRange valueRange = (range == RangeNonNegative) ? ValueRangeNonNegat
ive : ValueRangeAll; |
286 return CSSPrimitiveValue::create(CSSCalcValue::create(constructCalcExpre
ssion(nullptr, listOfValuesAndTypes, 0), valueRange)); | 285 return CSSPrimitiveValue::create(CSSCalcValue::create(constructCalcExpre
ssion(listOfValuesAndTypes), valueRange)); |
287 } | 286 } |
288 } | 287 } |
289 | 288 |
290 void LengthStyleInterpolation::apply(StyleResolverState& state) const | 289 void LengthStyleInterpolation::apply(StyleResolverState& state) const |
291 { | 290 { |
292 if (m_lengthSetter) { | 291 if (m_lengthSetter) { |
293 (state.style()->*m_lengthSetter)(lengthFromInterpolableValue(*m_cachedVa
lue, m_range, state.style()->effectiveZoom())); | 292 (state.style()->*m_lengthSetter)(lengthFromInterpolableValue(*m_cachedVa
lue, m_range, state.style()->effectiveZoom())); |
294 #if ENABLE(ASSERT) | 293 #if ENABLE(ASSERT) |
295 RefPtrWillBeRawPtr<AnimatableValue> before = CSSAnimatableValueFactory::
create(m_id, *state.style()); | 294 RefPtrWillBeRawPtr<AnimatableValue> before = CSSAnimatableValueFactory::
create(m_id, *state.style()); |
296 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); | 295 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); |
297 RefPtrWillBeRawPtr<AnimatableValue> after = CSSAnimatableValueFactory::c
reate(m_id, *state.style()); | 296 RefPtrWillBeRawPtr<AnimatableValue> after = CSSAnimatableValueFactory::c
reate(m_id, *state.style()); |
298 ASSERT(before->equals(*after)); | 297 ASSERT(before->equals(*after)); |
299 #endif | 298 #endif |
300 } else { | 299 } else { |
301 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); | 300 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); |
302 } | 301 } |
303 } | 302 } |
304 | 303 |
305 DEFINE_TRACE(LengthStyleInterpolation) | 304 DEFINE_TRACE(LengthStyleInterpolation) |
306 { | 305 { |
307 StyleInterpolation::trace(visitor); | 306 StyleInterpolation::trace(visitor); |
308 } | 307 } |
309 | 308 |
310 } | 309 } |
OLD | NEW |