Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: Source/core/animation/DoubleStyleInterpolation.cpp

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Some small fixes to (hopefully) fix some broken tests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CSSValue DoubleStyleInterpolation::interpolableValueToDouble(InterpolableValue* value, bool isNumber, InterpolationRange clamp)
31 { 31 {
32 ASSERT(value->isNumber()); 32 ASSERT(value->isNumber());
33 double doubleValue = toInterpolableNumber(value)->value(); 33 double doubleValue = toInterpolableNumber(value)->value();
34 34
35 switch (clamp) { 35 switch (clamp) {
36 case RangeAll: 36 case RangeAll:
37 // Do nothing 37 // Do nothing
38 break; 38 break;
39 case RangeZeroToOne: 39 case RangeZeroToOne:
40 doubleValue = clampTo<float>(doubleValue, 0, 1); 40 doubleValue = clampTo<float>(doubleValue, 0, 1);
(...skipping 20 matching lines...) Expand all
61 ASSERT_NOT_REACHED(); 61 ASSERT_NOT_REACHED();
62 } 62 }
63 if (isNumber) 63 if (isNumber)
64 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM BER); 64 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_NUM BER);
65 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG); 65 return CSSPrimitiveValue::create(doubleValue, CSSPrimitiveValue::CSS_DEG);
66 } 66 }
67 67
68 void DoubleStyleInterpolation::apply(StyleResolverState& state) const 68 void DoubleStyleInterpolation::apply(StyleResolverState& state) const
69 { 69 {
70 if (m_id != CSSPropertyMotionRotation) { 70 if (m_id != CSSPropertyMotionRotation) {
71 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac hedValue.get(), m_isNumber, m_clamp).get()); 71 StyleBuilder::applyProperty(m_id, state, interpolableValueToDouble(m_cac hedValue.get(), m_isNumber, m_clamp));
72 return; 72 return;
73 } 73 }
74 74
75 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m _cachedValue.get(), m_flag).get()); 75 StyleBuilder::applyProperty(m_id, state, interpolableValueToMotionRotation(m _cachedValue.get(), m_flag));
76 } 76 }
77 77
78 DEFINE_TRACE(DoubleStyleInterpolation) 78 DEFINE_TRACE(DoubleStyleInterpolation)
79 { 79 {
80 StyleInterpolation::trace(visitor); 80 StyleInterpolation::trace(visitor);
81 } 81 }
82 82
83 namespace { 83 namespace {
84 84
85 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio nType* rotationType) 85 bool extractMotionRotation(const CSSValue& value, float* rotation, MotionRotatio nType* rotationType)
86 { 86 {
87 *rotation = 0; 87 *rotation = 0;
88 *rotationType = MotionRotationFixed; 88 *rotationType = MotionRotationFixed;
89 89
90 if (!value.isValueList()) 90 if (!value.isValueList())
91 return false; 91 return false;
92 const CSSValueList& list = toCSSValueList(value); 92 const CSSValueList& list = toCSSValueList(value);
93 93
94 int len = list.length(); 94 int len = list.length();
95 for (int i = 0; i < len; i++) { 95 for (int i = 0; i < len; i++) {
96 const CSSValue* item = list.item(i); 96 const CSSValue item = list.item(i);
97 if (!item->isPrimitiveValue()) 97 if (!item.isPrimitiveValue())
98 return false; 98 return false;
99 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(item); 99 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(item);
100 if (primitiveValue->getValueID() == CSSValueAuto) { 100 if (primitiveValue.getValueID() == CSSValueAuto) {
101 *rotationType = MotionRotationAuto; 101 *rotationType = MotionRotationAuto;
102 } else if (primitiveValue->getValueID() == CSSValueReverse) { 102 } else if (primitiveValue.getValueID() == CSSValueReverse) {
103 *rotationType = MotionRotationAuto; 103 *rotationType = MotionRotationAuto;
104 *rotation += 180; 104 *rotation += 180;
105 } else if (primitiveValue->isAngle() || primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_DEG) { 105 } else if (primitiveValue.isAngle() || primitiveValue.primitiveType() == CSSPrimitiveValue::CSS_DEG) {
106 *rotation += primitiveValue->computeDegrees(); 106 *rotation += primitiveValue.computeDegrees();
107 } else { 107 } else {
108 return false; 108 return false;
109 } 109 }
110 } 110 }
111 return true; 111 return true;
112 } 112 }
113 113
114 } // namespace 114 } // namespace
115 115
116 PassRefPtrWillBeRawPtr<CSSValue> DoubleStyleInterpolation::interpolableValueToMo tionRotation(InterpolableValue* value, bool flag) 116 CSSValue DoubleStyleInterpolation::interpolableValueToMotionRotation(Interpolabl eValue* value, bool flag)
117 { 117 {
118 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated() ; 118 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated() ;
119 if (flag) 119 if (flag)
120 list->append(CSSPrimitiveValue::createIdentifier(CSSValueAuto)); 120 list->append(CSSPrimitiveValue::createIdentifier(CSSValueAuto));
121 ASSERT(value->isNumber()); 121 ASSERT(value->isNumber());
122 list->append(CSSPrimitiveValue::create(toInterpolableNumber(value)->value(), CSSPrimitiveValue::CSS_DEG)); 122 list->append(CSSPrimitiveValue::create(toInterpolableNumber(value)->value(), CSSPrimitiveValue::CSS_DEG));
123 return list.release(); 123 return list.release();
124 } 124 }
125 125
126 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::motionRotati onToInterpolableValue(const CSSValue& value) 126 PassOwnPtrWillBeRawPtr<InterpolableValue> DoubleStyleInterpolation::motionRotati onToInterpolableValue(const CSSValue& value)
(...skipping 15 matching lines...) Expand all
142 || startRotationType != endRotationType) 142 || startRotationType != endRotationType)
143 return nullptr; 143 return nullptr;
144 144
145 return adoptRefWillBeNoop(new DoubleStyleInterpolation( 145 return adoptRefWillBeNoop(new DoubleStyleInterpolation(
146 motionRotationToInterpolableValue(start), 146 motionRotationToInterpolableValue(start),
147 motionRotationToInterpolableValue(end), 147 motionRotationToInterpolableValue(end),
148 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat ionAuto)); 148 id, true, InterpolationRange::RangeAll, startRotationType == MotionRotat ionAuto));
149 } 149 }
150 150
151 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698