| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 case RangeGreaterThanOrEqualToOne: | 46 case RangeGreaterThanOrEqualToOne: |
| 47 return clampTo<float>(value, 1); | 47 return clampTo<float>(value, 1); |
| 48 case RangeNonNegative: | 48 case RangeNonNegative: |
| 49 return clampTo<float>(value, 0); | 49 return clampTo<float>(value, 0); |
| 50 default: | 50 default: |
| 51 ASSERT_NOT_REACHED(); | 51 ASSERT_NOT_REACHED(); |
| 52 return value; | 52 return value; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDo
uble(const InterpolableValue* value, bool isNumber, InterpolationRange clamp) | 56 CSSValue DoubleStyleInterpolation::interpolableValueToDouble(const InterpolableV
alue* value, bool isNumber, InterpolationRange clamp) |
| 57 { | 57 { |
| 58 ASSERT(value->isNumber()); | 58 ASSERT(value->isNumber()); |
| 59 double doubleValue = clampToRange(toInterpolableNumber(value)->value(), clam
p); | 59 double doubleValue = clampToRange(toInterpolableNumber(value)->value(), clam
p); |
| 60 | 60 |
| 61 if (isNumber) | 61 if (isNumber) |
| 62 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM
BER); | 62 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM
BER); |
| 63 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); | 63 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void DoubleStyleInterpolation::apply(StyleResolverState& state) const | 66 void DoubleStyleInterpolation::apply(StyleResolverState& state) const |
| 67 { | 67 { |
| 68 if (m_id != CSSPropertyMotionRotation) { | 68 if (m_id != CSSPropertyMotionRotation) { |
| 69 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)); |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 | 72 |
| 73 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m
_cachedValue.get(), m_flag).get()); | 73 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m
_cachedValue.get(), m_flag)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 DEFINE_TRACE(DoubleStyleInterpolation) | 76 DEFINE_TRACE(DoubleStyleInterpolation) |
| 77 { | 77 { |
| 78 StyleInterpolation::trace(visitor); | 78 StyleInterpolation::trace(visitor); |
| 79 } | 79 } |
| 80 | 80 |
| 81 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::toInterpolab
leValue(const CSSValue& value, CSSPropertyID property) | 81 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::toInterpolab
leValue(const CSSValue& value, CSSPropertyID property) |
| 82 { | 82 { |
| 83 ASSERT(canCreateFrom(value)); | 83 ASSERT(canCreateFrom(value)); |
| 84 return doubleToInterpolableValue(value); | 84 return doubleToInterpolableValue(value); |
| 85 } | 85 } |
| 86 | 86 |
| 87 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::fromInterpolableValue
(const InterpolableValue& value, InterpolationRange range) | 87 CSSValue DoubleStyleInterpolation::fromInterpolableValue(const InterpolableValue
& value, InterpolationRange range) |
| 88 { | 88 { |
| 89 return interpolableValueToDouble(&value, true, range); | 89 return interpolableValueToDouble(&value, true, range); |
| 90 } | 90 } |
| 91 | 91 |
| 92 namespace { | 92 namespace { |
| 93 | 93 |
| 94 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio
nType* rotationType) | 94 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio
nType* rotationType) |
| 95 { | 95 { |
| 96 *rotation = 0; | 96 *rotation = 0; |
| 97 *rotationType = MotionRotationFixed; | 97 *rotationType = MotionRotationFixed; |
| 98 | 98 |
| 99 if (!value.isValueList()) | 99 if (!value.isValueList()) |
| 100 return false; | 100 return false; |
| 101 const CSSValueList& list = toCSSValueList(value); | 101 const CSSValueList& list = toCSSValueList(value); |
| 102 | 102 |
| 103 int len = list.length(); | 103 int len = list.length(); |
| 104 for (int i = 0; i < len; i++) { | 104 for (int i = 0; i < len; i++) { |
| 105 const CSSValue* item = list.item(i); | 105 const CSSValue item = list.item(i); |
| 106 if (!item->isPrimitiveValue()) | 106 if (!item.isPrimitiveValue()) |
| 107 return false; | 107 return false; |
| 108 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(item); | 108 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(item); |
| 109 if (primitiveValue->getValueID() == CSSValueAuto) { | 109 if (primitiveValue.getValueID() == CSSValueAuto) { |
| 110 *rotationType = MotionRotationAuto; | 110 *rotationType = MotionRotationAuto; |
| 111 } else if (primitiveValue->getValueID() == CSSValueReverse) { | 111 } else if (primitiveValue.getValueID() == CSSValueReverse) { |
| 112 *rotationType = MotionRotationAuto; | 112 *rotationType = MotionRotationAuto; |
| 113 *rotation += 180; | 113 *rotation += 180; |
| 114 } else if (primitiveValue->isAngle()) { | 114 } else if (primitiveValue.isAngle()) { |
| 115 *rotation += primitiveValue->computeDegrees(); | 115 *rotation += primitiveValue.computeDegrees(); |
| 116 } else { | 116 } else { |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 return true; | 120 return true; |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace | 123 } // namespace |
| 124 | 124 |
| 125 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToMo
tionRotation(InterpolableValue* value, bool flag) | 125 CSSValue DoubleStyleInterpolation::interpolableValueToMotionRotation(Interpolabl
eValue* value, bool flag) |
| 126 { | 126 { |
| 127 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated()
; | 127 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated()
; |
| 128 if (flag) | 128 if (flag) |
| 129 list->append(CSSPrimitiveValue::createIdentifier(CSSValueAuto)); | 129 list->append(CSSPrimitiveValue::createIdentifier(CSSValueAuto)); |
| 130 ASSERT(value->isNumber()); | 130 ASSERT(value->isNumber()); |
| 131 list->append(CSSPrimitiveValue::create(toInterpolableNumber(value)->value(),
CSSPrimitiveValue::CSS_DEG)); | 131 list->append(CSSPrimitiveValue::create(toInterpolableNumber(value)->value(),
CSSPrimitiveValue::CSS_DEG)); |
| 132 return list.release(); | 132 return list.release(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::motionRotati
onToInterpolableValue(const CSSValue& value) | 135 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::motionRotati
onToInterpolableValue(const CSSValue& value) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 151 || startRotationType != endRotationType) | 151 || startRotationType != endRotationType) |
| 152 return nullptr; | 152 return nullptr; |
| 153 | 153 |
| 154 return adoptRefWillBeNoop(new DoubleStyleInterpolation( | 154 return adoptRefWillBeNoop(new DoubleStyleInterpolation( |
| 155 motionRotationToInterpolableValue(start), | 155 motionRotationToInterpolableValue(start), |
| 156 motionRotationToInterpolableValue(end), | 156 motionRotationToInterpolableValue(end), |
| 157 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat
ionAuto)); | 157 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat
ionAuto)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } | 160 } |
| OLD | NEW |