Chromium Code Reviews| 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/DoubleStyleInterpolation.h" | 6 #include "core/animation/DoubleStyleInterpolation.h" |
| 7 | 7 |
| 8 #include "core/css/CSSCalculationValue.h" | 8 #include "core/css/CSSCalculationValue.h" |
| 9 #include "core/css/resolver/StyleBuilder.h" | 9 #include "core/css/resolver/StyleBuilder.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 bool DoubleStyleInterpolation::canCreateFrom(const CSSValue& value) | 13 bool DoubleStyleInterpolation::canCreateFrom(const CSSValue& value) |
| 14 { | 14 { |
| 15 return value.isPrimitiveValue() && (toCSSPrimitiveValue(value).isNumber() || toCSSPrimitiveValue(value).isAngle()); | 15 return value.isPrimitiveValue() && (toCSSPrimitiveValue(value).isNumber() || toCSSPrimitiveValue(value).isAngle()); |
| 16 } | 16 } |
| 17 | 17 |
| 18 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::doubleToInte rpolableValue(const CSSValue& value) | 18 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::doubleToInte rpolableValue(const CSSValue& value) |
| 19 { | 19 { |
| 20 ASSERT(canCreateFrom(value)); | 20 ASSERT(canCreateFrom(value)); |
| 21 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); | 21 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); |
| 22 if (primitive.isNumber()) | 22 if (primitive.isNumber()) |
| 23 return InterpolableNumber::create(primitive.getDoubleValue()); | 23 return InterpolableNumber::create(primitive.getDoubleValue()); |
| 24 if (primitive.isAngle()) | 24 if (primitive.isAngle()) |
| 25 return InterpolableNumber::create(primitive.computeDegrees()); | 25 return InterpolableNumber::create(primitive.computeDegrees()); |
| 26 ASSERT_NOT_REACHED(); | 26 ASSERT_NOT_REACHED(); |
| 27 return nullptr; | 27 return nullptr; |
| 28 } | 28 } |
| 29 | 29 |
| 30 static double clampToRange(double value, InterpolationRange clamp) | |
| 31 { | |
| 32 switch (clamp) { | |
| 33 case RangeAll: | |
| 34 // Do nothing | |
| 35 break; | |
| 36 case RangeZeroToOne: | |
| 37 value = clampTo<float>(value, 0, 1); | |
| 38 break; | |
| 39 case RangeOpacityFIXME: | |
| 40 value = clampTo<float>(value, 0, nextafterf(1, 0)); | |
| 41 break; | |
| 42 case RangeFloor: | |
| 43 value = floor(value); | |
| 44 break; | |
| 45 case RangeRound: | |
| 46 value = round(value); | |
| 47 break; | |
| 48 case RangeRoundGreaterThanOrEqualToOne: | |
| 49 value = clampTo<float>(round(value), 1); | |
| 50 break; | |
| 51 case RangeGreaterThanOrEqualToOne: | |
| 52 value = clampTo<float>(value, 1); | |
| 53 break; | |
| 54 case RangeNonNegative: | |
| 55 value = clampTo<float>(value, 0); | |
| 56 break; | |
| 57 default: | |
| 58 ASSERT_NOT_REACHED(); | |
| 59 } | |
| 60 return value; | |
| 61 } | |
| 62 | |
| 30 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDo uble(InterpolableValue* value, bool isNumber, InterpolationRange clamp) | 63 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDo uble(InterpolableValue* value, bool isNumber, InterpolationRange clamp) |
| 31 { | 64 { |
| 32 ASSERT(value->isNumber()); | 65 ASSERT(value->isNumber()); |
| 33 double doubleValue = toInterpolableNumber(value)->value(); | 66 double doubleValue = clampToRange(toInterpolableNumber(value)->value(), clam p); |
| 34 | 67 |
| 35 switch (clamp) { | |
| 36 case RangeAll: | |
| 37 // Do nothing | |
| 38 break; | |
| 39 case RangeZeroToOne: | |
| 40 doubleValue = clampTo<float>(doubleValue, 0, 1); | |
| 41 break; | |
| 42 case RangeOpacityFIXME: | |
| 43 doubleValue = clampTo<float>(doubleValue, 0, nextafterf(1, 0)); | |
| 44 break; | |
| 45 case RangeFloor: | |
| 46 doubleValue = floor(doubleValue); | |
| 47 break; | |
| 48 case RangeRound: | |
| 49 doubleValue = round(doubleValue); | |
| 50 break; | |
| 51 case RangeRoundGreaterThanOrEqualToOne: | |
| 52 doubleValue = clampTo<float>(round(doubleValue), 1); | |
| 53 break; | |
| 54 case RangeGreaterThanOrEqualToOne: | |
| 55 doubleValue = clampTo<float>(doubleValue, 1); | |
| 56 break; | |
| 57 case RangeNonNegative: | |
| 58 doubleValue = clampTo<float>(doubleValue, 0); | |
| 59 break; | |
| 60 default: | |
| 61 ASSERT_NOT_REACHED(); | |
| 62 } | |
| 63 if (isNumber) | 68 if (isNumber) |
| 64 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM BER); | 69 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM BER); |
| 65 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); | 70 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); |
| 66 } | 71 } |
| 67 | 72 |
| 68 void DoubleStyleInterpolation::apply(StyleResolverState& state) const | 73 void DoubleStyleInterpolation::apply(StyleResolverState& state) const |
| 69 { | 74 { |
| 70 if (m_id != CSSPropertyMotionRotation) { | 75 if (m_id != CSSPropertyMotionRotation) { |
| 71 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac hedValue.get(), m_isNumber, m_clamp).get()); | 76 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac hedValue.get(), m_isNumber, m_clamp).get()); |
| 72 return; | 77 return; |
| 73 } | 78 } |
| 74 | 79 |
| 75 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m _cachedValue.get(), m_flag).get()); | 80 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m _cachedValue.get(), m_flag).get()); |
| 76 } | 81 } |
| 77 | 82 |
| 78 DEFINE_TRACE(DoubleStyleInterpolation) | 83 DEFINE_TRACE(DoubleStyleInterpolation) |
| 79 { | 84 { |
| 80 StyleInterpolation::trace(visitor); | 85 StyleInterpolation::trace(visitor); |
| 81 } | 86 } |
| 82 | 87 |
| 88 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::toInterpolab leValue(const CSSValue& value, CSSPropertyID property) | |
|
Eric Willigers
2015/06/23 06:50:48
I am not certain I understand how these DoubleStyl
soonm
2015/06/24 00:26:44
I added these interface to make ListStyleInterpola
| |
| 89 { | |
| 90 ASSERT(canCreateFrom(value)); | |
| 91 return doubleToInterpolableValue(value); | |
| 92 } | |
| 93 | |
| 94 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> DoubleStyleInterpolation::fromInterpol ableValue(const InterpolableValue& value, InterpolationRange range) | |
| 95 { | |
| 96 // TODO Get the correct angle or double unit type | |
| 97 double doubleValue = clampToRange(toInterpolableNumber(value).value(), range ); | |
| 98 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUMBER) ; | |
| 99 } | |
| 100 | |
| 83 namespace { | 101 namespace { |
| 84 | 102 |
| 85 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio nType* rotationType) | 103 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio nType* rotationType) |
| 86 { | 104 { |
| 87 *rotation = 0; | 105 *rotation = 0; |
| 88 *rotationType = MotionRotationFixed; | 106 *rotationType = MotionRotationFixed; |
| 89 | 107 |
| 90 if (!value.isValueList()) | 108 if (!value.isValueList()) |
| 91 return false; | 109 return false; |
| 92 const CSSValueList& list = toCSSValueList(value); | 110 const CSSValueList& list = toCSSValueList(value); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 || startRotationType != endRotationType) | 160 || startRotationType != endRotationType) |
| 143 return nullptr; | 161 return nullptr; |
| 144 | 162 |
| 145 return adoptRefWillBeNoop(new DoubleStyleInterpolation( | 163 return adoptRefWillBeNoop(new DoubleStyleInterpolation( |
| 146 motionRotationToInterpolableValue(start), | 164 motionRotationToInterpolableValue(start), |
| 147 motionRotationToInterpolableValue(end), | 165 motionRotationToInterpolableValue(end), |
| 148 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat ionAuto)); | 166 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat ionAuto)); |
| 149 } | 167 } |
| 150 | 168 |
| 151 } | 169 } |
| OLD | NEW |