| 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 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDo
uble(InterpolableValue* value, bool isNumber, InterpolationRange clamp) | 30 static double clampToRange(double value, InterpolationRange clamp) |
| 31 { | 31 { |
| 32 ASSERT(value->isNumber()); | |
| 33 double doubleValue = toInterpolableNumber(value)->value(); | |
| 34 | |
| 35 switch (clamp) { | 32 switch (clamp) { |
| 36 case RangeAll: | 33 case RangeAll: |
| 37 // Do nothing | 34 // Do nothing |
| 38 break; | 35 return value; |
| 39 case RangeZeroToOne: | 36 case RangeZeroToOne: |
| 40 doubleValue = clampTo<float>(doubleValue, 0, 1); | 37 return clampTo<float>(value, 0, 1); |
| 41 break; | |
| 42 case RangeOpacityFIXME: | 38 case RangeOpacityFIXME: |
| 43 doubleValue = clampTo<float>(doubleValue, 0, nextafterf(1, 0)); | 39 return clampTo<float>(value, 0, nextafterf(1, 0)); |
| 44 break; | |
| 45 case RangeFloor: | 40 case RangeFloor: |
| 46 doubleValue = floor(doubleValue); | 41 return floor(value); |
| 47 break; | |
| 48 case RangeRound: | 42 case RangeRound: |
| 49 doubleValue = round(doubleValue); | 43 return round(value); |
| 50 break; | |
| 51 case RangeRoundGreaterThanOrEqualToOne: | 44 case RangeRoundGreaterThanOrEqualToOne: |
| 52 doubleValue = clampTo<float>(round(doubleValue), 1); | 45 return clampTo<float>(round(value), 1); |
| 53 break; | |
| 54 case RangeGreaterThanOrEqualToOne: | 46 case RangeGreaterThanOrEqualToOne: |
| 55 doubleValue = clampTo<float>(doubleValue, 1); | 47 return clampTo<float>(value, 1); |
| 56 break; | |
| 57 case RangeNonNegative: | 48 case RangeNonNegative: |
| 58 doubleValue = clampTo<float>(doubleValue, 0); | 49 return clampTo<float>(value, 0); |
| 59 break; | |
| 60 default: | 50 default: |
| 61 ASSERT_NOT_REACHED(); | 51 ASSERT_NOT_REACHED(); |
| 52 return value; |
| 62 } | 53 } |
| 54 } |
| 55 |
| 56 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDo
uble(const InterpolableValue* value, bool isNumber, InterpolationRange clamp) |
| 57 { |
| 58 ASSERT(value->isNumber()); |
| 59 double doubleValue = clampToRange(toInterpolableNumber(value)->value(), clam
p); |
| 60 |
| 63 if (isNumber) | 61 if (isNumber) |
| 64 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM
BER); | 62 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM
BER); |
| 65 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); | 63 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void DoubleStyleInterpolation::apply(StyleResolverState& state) const | 66 void DoubleStyleInterpolation::apply(StyleResolverState& state) const |
| 69 { | 67 { |
| 70 if (m_id != CSSPropertyMotionRotation) { | 68 if (m_id != CSSPropertyMotionRotation) { |
| 71 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac
hedValue.get(), m_isNumber, m_clamp).get()); | 69 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac
hedValue.get(), m_isNumber, m_clamp).get()); |
| 72 return; | 70 return; |
| 73 } | 71 } |
| 74 | 72 |
| 75 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m
_cachedValue.get(), m_flag).get()); | 73 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m
_cachedValue.get(), m_flag).get()); |
| 76 } | 74 } |
| 77 | 75 |
| 78 DEFINE_TRACE(DoubleStyleInterpolation) | 76 DEFINE_TRACE(DoubleStyleInterpolation) |
| 79 { | 77 { |
| 80 StyleInterpolation::trace(visitor); | 78 StyleInterpolation::trace(visitor); |
| 81 } | 79 } |
| 82 | 80 |
| 81 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::toInterpolab
leValue(const CSSValue& value, CSSPropertyID property) |
| 82 { |
| 83 ASSERT(canCreateFrom(value)); |
| 84 return doubleToInterpolableValue(value); |
| 85 } |
| 86 |
| 87 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::fromInterpolableValue
(const InterpolableValue& value, InterpolationRange range) |
| 88 { |
| 89 return interpolableValueToDouble(&value, true, range); |
| 90 } |
| 91 |
| 83 namespace { | 92 namespace { |
| 84 | 93 |
| 85 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio
nType* rotationType) | 94 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio
nType* rotationType) |
| 86 { | 95 { |
| 87 *rotation = 0; | 96 *rotation = 0; |
| 88 *rotationType = MotionRotationFixed; | 97 *rotationType = MotionRotationFixed; |
| 89 | 98 |
| 90 if (!value.isValueList()) | 99 if (!value.isValueList()) |
| 91 return false; | 100 return false; |
| 92 const CSSValueList& list = toCSSValueList(value); | 101 const CSSValueList& list = toCSSValueList(value); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 || startRotationType != endRotationType) | 151 || startRotationType != endRotationType) |
| 143 return nullptr; | 152 return nullptr; |
| 144 | 153 |
| 145 return adoptRefWillBeNoop(new DoubleStyleInterpolation( | 154 return adoptRefWillBeNoop(new DoubleStyleInterpolation( |
| 146 motionRotationToInterpolableValue(start), | 155 motionRotationToInterpolableValue(start), |
| 147 motionRotationToInterpolableValue(end), | 156 motionRotationToInterpolableValue(end), |
| 148 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat
ionAuto)); | 157 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat
ionAuto)); |
| 149 } | 158 } |
| 150 | 159 |
| 151 } | 160 } |
| OLD | NEW |