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 return value; | |
36 case RangeZeroToOne: | |
37 return clampTo<float>(value, 0, 1); | |
38 case RangeOpacityFIXME: | |
39 return clampTo<float>(value, 0, nextafterf(1, 0)); | |
40 case RangeFloor: | |
41 return floor(value); | |
42 case RangeRound: | |
43 return round(value); | |
44 case RangeRoundGreaterThanOrEqualToOne: | |
45 return clampTo<float>(round(value), 1); | |
46 case RangeGreaterThanOrEqualToOne: | |
47 return clampTo<float>(value, 1); | |
48 case RangeNonNegative: | |
49 return clampTo<float>(value, 0); | |
50 default: | |
51 ASSERT_NOT_REACHED(); | |
alancutter (OOO until 2018)
2015/06/25 01:33:09
You still need a return value here.
| |
52 } | |
53 } | |
54 | |
30 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDo uble(InterpolableValue* value, bool isNumber, InterpolationRange clamp) | 55 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToDo uble(InterpolableValue* value, bool isNumber, InterpolationRange clamp) |
31 { | 56 { |
32 ASSERT(value->isNumber()); | 57 ASSERT(value->isNumber()); |
33 double doubleValue = toInterpolableNumber(value)->value(); | 58 double doubleValue = clampToRange(toInterpolableNumber(value)->value(), clam p); |
34 | 59 |
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) | 60 if (isNumber) |
64 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM BER); | 61 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM BER); |
65 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); | 62 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); |
66 } | 63 } |
67 | 64 |
68 void DoubleStyleInterpolation::apply(StyleResolverState& state) const | 65 void DoubleStyleInterpolation::apply(StyleResolverState& state) const |
69 { | 66 { |
70 if (m_id != CSSPropertyMotionRotation) { | 67 if (m_id != CSSPropertyMotionRotation) { |
71 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac hedValue.get(), m_isNumber, m_clamp).get()); | 68 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac hedValue.get(), m_isNumber, m_clamp).get()); |
72 return; | 69 return; |
73 } | 70 } |
74 | 71 |
75 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m _cachedValue.get(), m_flag).get()); | 72 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m _cachedValue.get(), m_flag).get()); |
76 } | 73 } |
77 | 74 |
78 DEFINE_TRACE(DoubleStyleInterpolation) | 75 DEFINE_TRACE(DoubleStyleInterpolation) |
79 { | 76 { |
80 StyleInterpolation::trace(visitor); | 77 StyleInterpolation::trace(visitor); |
81 } | 78 } |
82 | 79 |
80 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::toInterpolab leValue(const CSSValue& value, CSSPropertyID property) | |
81 { | |
82 ASSERT(canCreateFrom(value)); | |
83 return doubleToInterpolableValue(value); | |
84 } | |
85 | |
86 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> DoubleStyleInterpolation::fromInterpol ableValue(const InterpolableValue& value, InterpolationRange range) | |
87 { | |
88 double doubleValue = clampToRange(toInterpolableNumber(value).value(), range ); | |
89 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUMBER) ; | |
alancutter (OOO until 2018)
2015/06/25 01:33:09
This can just call interpolableValueToDouble().
| |
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 |