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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return pixelsForKeyword(property, valueID, pixels); | 64 return pixelsForKeyword(property, valueID, pixels); |
65 } | 65 } |
66 | 66 |
67 CSSPrimitiveValue::LengthUnitType type; | 67 CSSPrimitiveValue::LengthUnitType type; |
68 // Only returns true if the type is a primitive length unit. | 68 // Only returns true if the type is a primitive length unit. |
69 return CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.primit
iveType(), type); | 69 return CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.primit
iveType(), type); |
70 } | 70 } |
71 return value.isCalcValue(); | 71 return value.isCalcValue(); |
72 } | 72 } |
73 | 73 |
74 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthStyleInterpolation::toInterpolab
leValue(const CSSValue& value, CSSPropertyID id) | 74 InterpolableValue* LengthStyleInterpolation::toInterpolableValue(const CSSValue&
value, CSSPropertyID id) |
75 { | 75 { |
76 ASSERT(canCreateFrom(value, id)); | 76 ASSERT(canCreateFrom(value, id)); |
77 OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList
::create(2); | 77 InterpolableList* listOfValuesAndTypes = InterpolableList::create(2); |
78 OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create
(CSSPrimitiveValue::LengthUnitTypeCount); | 78 InterpolableList* listOfValues = InterpolableList::create(CSSPrimitiveValue:
:LengthUnitTypeCount); |
79 OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create(
CSSPrimitiveValue::LengthUnitTypeCount); | 79 InterpolableList* listOfTypes = InterpolableList::create(CSSPrimitiveValue::
LengthUnitTypeCount); |
80 | 80 |
81 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); | 81 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); |
82 | 82 |
83 CSSLengthArray arrayOfValues; | 83 CSSLengthArray arrayOfValues; |
84 CSSPrimitiveValue::CSSLengthTypeArray arrayOfTypes; | 84 CSSPrimitiveValue::CSSLengthTypeArray arrayOfTypes; |
85 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) | 85 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) |
86 arrayOfValues.append(0); | 86 arrayOfValues.append(0); |
87 | 87 |
88 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount); | 88 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount); |
89 if (primitive.isValueID()) { | 89 if (primitive.isValueID()) { |
90 CSSValueID valueID = primitive.getValueID(); | 90 CSSValueID valueID = primitive.getValueID(); |
91 double pixels; | 91 double pixels; |
92 pixelsForKeyword(id, valueID, pixels); | 92 pixelsForKeyword(id, valueID, pixels); |
93 arrayOfTypes.set(CSSPrimitiveValue::UnitTypePixels); | 93 arrayOfTypes.set(CSSPrimitiveValue::UnitTypePixels); |
94 arrayOfValues[CSSPrimitiveValue::UnitTypePixels] = pixels; | 94 arrayOfValues[CSSPrimitiveValue::UnitTypePixels] = pixels; |
95 } else { | 95 } else { |
96 primitive.accumulateLengthArray(arrayOfValues, arrayOfTypes); | 96 primitive.accumulateLengthArray(arrayOfValues, arrayOfTypes); |
97 } | 97 } |
98 | 98 |
99 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { | 99 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
100 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i))); | 100 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i))); |
101 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i))); | 101 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i))); |
102 } | 102 } |
103 | 103 |
104 listOfValuesAndTypes->set(0, listOfValues.release()); | 104 listOfValuesAndTypes->set(0, listOfValues); |
105 listOfValuesAndTypes->set(1, listOfTypes.release()); | 105 listOfValuesAndTypes->set(1, listOfTypes); |
106 | 106 |
107 return listOfValuesAndTypes.release(); | 107 return listOfValuesAndTypes; |
108 } | 108 } |
109 | 109 |
110 bool LengthStyleInterpolation::isPixelsOrPercentOnly(const InterpolableValue& va
lue) | 110 bool LengthStyleInterpolation::isPixelsOrPercentOnly(const InterpolableValue& va
lue) |
111 { | 111 { |
112 const InterpolableList& types = *toInterpolableList(toInterpolableList(value
).get(1)); | 112 const InterpolableList& types = *toInterpolableList(toInterpolableList(value
).get(1)); |
113 bool result = false; | 113 bool result = false; |
114 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { | 114 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
115 bool typeIsPresent = toInterpolableNumber(types.get(i))->value(); | 115 bool typeIsPresent = toInterpolableNumber(types.get(i))->value(); |
116 if (i == CSSPrimitiveValue::UnitTypePixels) | 116 if (i == CSSPrimitiveValue::UnitTypePixels) |
117 result |= typeIsPresent; | 117 result |= typeIsPresent; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 ValueRange valueRange = (range == RangeNonNegative) ? ValueRangeNonNegat
ive : ValueRangeAll; | 310 ValueRange valueRange = (range == RangeNonNegative) ? ValueRangeNonNegat
ive : ValueRangeAll; |
311 return CSSPrimitiveValue::create(CSSCalcValue::create(constructCalcExpre
ssion(listOfValuesAndTypes), valueRange)); | 311 return CSSPrimitiveValue::create(CSSCalcValue::create(constructCalcExpre
ssion(listOfValuesAndTypes), valueRange)); |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 void LengthStyleInterpolation::apply(StyleResolverState& state) const | 315 void LengthStyleInterpolation::apply(StyleResolverState& state) const |
316 { | 316 { |
317 if (m_lengthSetter) { | 317 if (m_lengthSetter) { |
318 (state.style()->*m_lengthSetter)(lengthFromInterpolableValue(*m_cachedVa
lue, m_range, state.style()->effectiveZoom())); | 318 (state.style()->*m_lengthSetter)(lengthFromInterpolableValue(*m_cachedVa
lue, m_range, state.style()->effectiveZoom())); |
319 #if ENABLE(ASSERT) | 319 #if ENABLE(ASSERT) |
320 RefPtrWillBeRawPtr<AnimatableValue> before = CSSAnimatableValueFactory::
create(m_id, *state.style()); | 320 AnimatableValue* before = CSSAnimatableValueFactory::create(m_id, *state
.style()); |
321 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); | 321 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); |
322 RefPtrWillBeRawPtr<AnimatableValue> after = CSSAnimatableValueFactory::c
reate(m_id, *state.style()); | 322 AnimatableValue* after = CSSAnimatableValueFactory::create(m_id, *state.
style()); |
323 ASSERT(before->equals(*after)); | 323 ASSERT(before->equals(*after)); |
324 #endif | 324 #endif |
325 } else { | 325 } else { |
326 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); | 326 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cached
Value, m_range).get()); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 DEFINE_TRACE(LengthStyleInterpolation) | 330 DEFINE_TRACE(LengthStyleInterpolation) |
331 { | 331 { |
332 StyleInterpolation::trace(visitor); | 332 StyleInterpolation::trace(visitor); |
333 } | 333 } |
334 | 334 |
335 } | 335 } |
OLD | NEW |