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

Side by Side Diff: third_party/WebKit/Source/core/animation/LengthSVGInterpolation.cpp

Issue 1421533006: Make SVGLength wrap a CSSPrimitiveValue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/LengthSVGInterpolation.h" 6 #include "core/animation/LengthSVGInterpolation.h"
7 7
8 #include "core/css/CSSHelper.h" 8 #include "core/css/CSSHelper.h"
9 #include "core/svg/SVGAnimatedLength.h" 9 #include "core/svg/SVGAnimatedLength.h"
10 #include "core/svg/SVGAnimatedLengthList.h" 10 #include "core/svg/SVGAnimatedLengthList.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 enum LengthInterpolatedUnit { 54 enum LengthInterpolatedUnit {
55 LengthInterpolatedNumber, 55 LengthInterpolatedNumber,
56 LengthInterpolatedPercentage, 56 LengthInterpolatedPercentage,
57 LengthInterpolatedEMS, 57 LengthInterpolatedEMS,
58 LengthInterpolatedEXS, 58 LengthInterpolatedEXS,
59 LengthInterpolatedREMS, 59 LengthInterpolatedREMS,
60 LengthInterpolatedCHS, 60 LengthInterpolatedCHS,
61 }; 61 };
62 62
63 static const SVGLengthType unitTypes[] = { LengthTypeNumber, LengthTypePercentag e, LengthTypeEMS, LengthTypeEXS, LengthTypeREMS, LengthTypeCHS }; 63 static const CSSPrimitiveValue::UnitType unitTypes[] = {
64 CSSPrimitiveValue::UnitType::Number,
65 CSSPrimitiveValue::UnitType::Percentage,
66 CSSPrimitiveValue::UnitType::Ems,
67 CSSPrimitiveValue::UnitType::Exs,
68 CSSPrimitiveValue::UnitType::Rems,
69 CSSPrimitiveValue::UnitType::Chs };
64 70
65 const size_t numLengthInterpolatedUnits = WTF_ARRAY_LENGTH(unitTypes); 71 const size_t numLengthInterpolatedUnits = WTF_ARRAY_LENGTH(unitTypes);
66 72
67 LengthInterpolatedUnit convertToInterpolatedUnit(SVGLengthType lengthType, doubl e& value) 73 LengthInterpolatedUnit convertToInterpolatedUnit(CSSPrimitiveValue::UnitType uni tType, double& value)
68 { 74 {
69 switch (lengthType) { 75 switch (unitType) {
70 case LengthTypeUnknown: 76 case CSSPrimitiveValue::UnitType::Unknown:
71 default: 77 default:
72 ASSERT_NOT_REACHED(); 78 ASSERT_NOT_REACHED();
73 case LengthTypePX: 79 case CSSPrimitiveValue::UnitType::Pixels:
74 case LengthTypeNumber: 80 case CSSPrimitiveValue::UnitType::Number:
75 return LengthInterpolatedNumber; 81 return LengthInterpolatedNumber;
76 case LengthTypePercentage: 82 case CSSPrimitiveValue::UnitType::Percentage:
77 return LengthInterpolatedPercentage; 83 return LengthInterpolatedPercentage;
78 case LengthTypeEMS: 84 case CSSPrimitiveValue::UnitType::Ems:
79 return LengthInterpolatedEMS; 85 return LengthInterpolatedEMS;
80 case LengthTypeEXS: 86 case CSSPrimitiveValue::UnitType::Exs:
81 return LengthInterpolatedEXS; 87 return LengthInterpolatedEXS;
82 case LengthTypeCM: 88 case CSSPrimitiveValue::UnitType::Centimeters:
83 value *= cssPixelsPerCentimeter; 89 value *= cssPixelsPerCentimeter;
84 return LengthInterpolatedNumber; 90 return LengthInterpolatedNumber;
85 case LengthTypeMM: 91 case CSSPrimitiveValue::UnitType::Millimeters:
86 value *= cssPixelsPerMillimeter; 92 value *= cssPixelsPerMillimeter;
87 return LengthInterpolatedNumber; 93 return LengthInterpolatedNumber;
88 case LengthTypeIN: 94 case CSSPrimitiveValue::UnitType::Inches:
89 value *= cssPixelsPerInch; 95 value *= cssPixelsPerInch;
90 return LengthInterpolatedNumber; 96 return LengthInterpolatedNumber;
91 case LengthTypePT: 97 case CSSPrimitiveValue::UnitType::Points:
92 value *= cssPixelsPerPoint; 98 value *= cssPixelsPerPoint;
93 return LengthInterpolatedNumber; 99 return LengthInterpolatedNumber;
94 case LengthTypePC: 100 case CSSPrimitiveValue::UnitType::Picas:
95 value *= cssPixelsPerPica; 101 value *= cssPixelsPerPica;
96 return LengthInterpolatedNumber; 102 return LengthInterpolatedNumber;
97 case LengthTypeREMS: 103 case CSSPrimitiveValue::UnitType::Rems:
98 return LengthInterpolatedREMS; 104 return LengthInterpolatedREMS;
99 case LengthTypeCHS: 105 case CSSPrimitiveValue::UnitType::Chs:
100 return LengthInterpolatedCHS; 106 return LengthInterpolatedCHS;
101 } 107 }
102 } 108 }
103 109
104 } // namespace 110 } // namespace
105 111
106 PassOwnPtr<InterpolableValue> LengthSVGInterpolation::toInterpolableValue(SVGLen gth* length, const SVGAnimatedPropertyBase* attribute, NonInterpolableType* ptrM odeData) 112 PassOwnPtr<InterpolableValue> LengthSVGInterpolation::toInterpolableValue(SVGLen gth* length, const SVGAnimatedPropertyBase* attribute, NonInterpolableType* ptrM odeData)
107 { 113 {
108 if (ptrModeData) 114 if (ptrModeData)
109 populateModeData(attribute, ptrModeData); 115 populateModeData(attribute, ptrModeData);
110 116
111 double value = length->valueInSpecifiedUnits(); 117 double value = length->valueInSpecifiedUnits();
112 LengthInterpolatedUnit unitType = convertToInterpolatedUnit(length->unitType (), value); 118 LengthInterpolatedUnit unitType = convertToInterpolatedUnit(length->typeWith CalcResolved(), value);
113 119
114 double values[numLengthInterpolatedUnits] = { }; 120 double values[numLengthInterpolatedUnits] = { };
115 values[unitType] = value; 121 values[unitType] = value;
116 122
117 OwnPtr<InterpolableList> listOfValues = InterpolableList::create(numLengthIn terpolatedUnits); 123 OwnPtr<InterpolableList> listOfValues = InterpolableList::create(numLengthIn terpolatedUnits);
118 for (size_t i = 0; i < numLengthInterpolatedUnits; ++i) 124 for (size_t i = 0; i < numLengthInterpolatedUnits; ++i)
119 listOfValues->set(i, InterpolableNumber::create(values[i])); 125 listOfValues->set(i, InterpolableNumber::create(values[i]));
120 return listOfValues.release(); 126 return listOfValues.release();
121 } 127 }
122 128
123 PassRefPtrWillBeRawPtr<SVGLength> LengthSVGInterpolation::fromInterpolableValue( const InterpolableValue& interpolableValue, const NonInterpolableType& modeData, const SVGElement* element) 129 PassRefPtrWillBeRawPtr<SVGLength> LengthSVGInterpolation::fromInterpolableValue( const InterpolableValue& interpolableValue, const NonInterpolableType& modeData, const SVGElement* element)
124 { 130 {
125 const InterpolableList& listOfValues = toInterpolableList(interpolableValue) ; 131 const InterpolableList& listOfValues = toInterpolableList(interpolableValue) ;
126 ASSERT(element); 132 ASSERT(element);
127 133
128 double value = 0; 134 double value = 0;
129 SVGLengthType lengthType = LengthTypeNumber; 135 CSSPrimitiveValue::UnitType unitType = CSSPrimitiveValue::UnitType::Number;
130 unsigned unitTypeCount = 0; 136 unsigned unitTypeCount = 0;
131 // We optimise for the common case where only one unit type is involved. 137 // We optimise for the common case where only one unit type is involved.
132 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) { 138 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) {
133 double entry = toInterpolableNumber(listOfValues.get(i))->value(); 139 double entry = toInterpolableNumber(listOfValues.get(i))->value();
134 if (!entry) 140 if (!entry)
135 continue; 141 continue;
136 unitTypeCount++; 142 unitTypeCount++;
137 if (unitTypeCount > 1) 143 if (unitTypeCount > 1)
138 break; 144 break;
139 145
140 value = entry; 146 value = entry;
141 lengthType = unitTypes[i]; 147 unitType = unitTypes[i];
142 } 148 }
143 149
144 if (unitTypeCount > 1) { 150 if (unitTypeCount > 1) {
145 value = 0; 151 value = 0;
146 lengthType = LengthTypeNumber; 152 unitType = CSSPrimitiveValue::UnitType::Number;
147 153
148 // SVGLength does not support calc expressions, so we convert to canonic al units. 154 // SVGLength does not support calc expressions, so we convert to canonic al units.
149 SVGLengthContext lengthContext(element); 155 SVGLengthContext lengthContext(element);
150 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) { 156 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) {
151 double entry = toInterpolableNumber(listOfValues.get(i))->value(); 157 double entry = toInterpolableNumber(listOfValues.get(i))->value();
152 if (entry) 158 if (entry)
153 value += lengthContext.convertValueToUserUnits(entry, modeData.u nitMode, unitTypes[i]); 159 value += lengthContext.convertValueToUserUnits(entry, modeData.u nitMode, unitTypes[i]);
154 } 160 }
155 } 161 }
156 162
157 if (modeData.negativeValuesMode == ForbidNegativeLengths && value < 0) 163 if (modeData.negativeValuesMode == ForbidNegativeLengths && value < 0)
158 value = 0; 164 value = 0;
159 165
160 RefPtrWillBeRawPtr<SVGLength> result = SVGLength::create(modeData.unitMode); // defaults to the length 0 166 RefPtrWillBeRawPtr<SVGLength> result = SVGLength::create(modeData.unitMode); // defaults to the length 0
161 result->setUnitType(lengthType); 167 result->newValueSpecifiedUnits(unitType, value);
162 result->setValueInSpecifiedUnits(value);
163 return result.release(); 168 return result.release();
164 } 169 }
165 170
166 PassRefPtrWillBeRawPtr<SVGPropertyBase> LengthSVGInterpolation::interpolatedValu e(SVGElement& targetElement) const 171 PassRefPtrWillBeRawPtr<SVGPropertyBase> LengthSVGInterpolation::interpolatedValu e(SVGElement& targetElement) const
167 { 172 {
168 return fromInterpolableValue(*m_cachedValue, m_modeData, &targetElement); 173 return fromInterpolableValue(*m_cachedValue, m_modeData, &targetElement);
169 } 174 }
170 175
171 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698