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

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

Issue 1491023003: Refactor SVGAnimatedLength negative values mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace SVGLengthNegativeValuesMode enum with bool Created 5 years 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 19 matching lines...) Expand all
30 } 30 }
31 31
32 namespace { 32 namespace {
33 33
34 void populateModeData(const SVGAnimatedPropertyBase* attribute, LengthSVGInterpo lation::NonInterpolableType* ptrModeData) 34 void populateModeData(const SVGAnimatedPropertyBase* attribute, LengthSVGInterpo lation::NonInterpolableType* ptrModeData)
35 { 35 {
36 switch (attribute->type()) { 36 switch (attribute->type()) {
37 case AnimatedLength: { 37 case AnimatedLength: {
38 const SVGAnimatedLength& animatedLength = static_cast<const SVGAnimatedL ength&>(*attribute); 38 const SVGAnimatedLength& animatedLength = static_cast<const SVGAnimatedL ength&>(*attribute);
39 ptrModeData->unitMode = animatedLength.currentValue()->unitMode(); 39 ptrModeData->unitMode = animatedLength.currentValue()->unitMode();
40 ptrModeData->negativeValuesMode = animatedLength.negativeValuesMode();
41 break; 40 break;
42 } 41 }
43 case AnimatedLengthList: { 42 case AnimatedLengthList: {
44 const SVGAnimatedLengthList& animatedLengthList = static_cast<const SVGA nimatedLengthList&>(*attribute); 43 const SVGAnimatedLengthList& animatedLengthList = static_cast<const SVGA nimatedLengthList&>(*attribute);
45 ptrModeData->unitMode = animatedLengthList.currentValue()->unitMode(); 44 ptrModeData->unitMode = animatedLengthList.currentValue()->unitMode();
46 ptrModeData->negativeValuesMode = AllowNegativeLengths;
47 break; 45 break;
48 } 46 }
49 default: 47 default:
50 ASSERT_NOT_REACHED(); 48 ASSERT_NOT_REACHED();
51 } 49 }
52 } 50 }
53 51
54 enum LengthInterpolatedUnit { 52 enum LengthInterpolatedUnit {
55 LengthInterpolatedNumber, 53 LengthInterpolatedNumber,
56 LengthInterpolatedPercentage, 54 LengthInterpolatedPercentage,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 120
123 double values[numLengthInterpolatedUnits] = { }; 121 double values[numLengthInterpolatedUnits] = { };
124 values[unitType] = value; 122 values[unitType] = value;
125 123
126 OwnPtr<InterpolableList> listOfValues = InterpolableList::create(numLengthIn terpolatedUnits); 124 OwnPtr<InterpolableList> listOfValues = InterpolableList::create(numLengthIn terpolatedUnits);
127 for (size_t i = 0; i < numLengthInterpolatedUnits; ++i) 125 for (size_t i = 0; i < numLengthInterpolatedUnits; ++i)
128 listOfValues->set(i, InterpolableNumber::create(values[i])); 126 listOfValues->set(i, InterpolableNumber::create(values[i]));
129 return listOfValues.release(); 127 return listOfValues.release();
130 } 128 }
131 129
132 PassRefPtrWillBeRawPtr<SVGLength> LengthSVGInterpolation::fromInterpolableValue( const InterpolableValue& interpolableValue, const NonInterpolableType& modeData, const SVGElement* element) 130 PassRefPtrWillBeRawPtr<SVGLength> LengthSVGInterpolation::fromInterpolableValue( const InterpolableValue& interpolableValue, const NonInterpolableType& modeData, const SVGElement* element, const QualifiedName& attributeName)
133 { 131 {
134 const InterpolableList& listOfValues = toInterpolableList(interpolableValue) ; 132 const InterpolableList& listOfValues = toInterpolableList(interpolableValue) ;
135 ASSERT(element); 133 ASSERT(element);
136 134
137 double value = 0; 135 double value = 0;
138 CSSPrimitiveValue::UnitType unitType = CSSPrimitiveValue::UnitType::UserUnit s; 136 CSSPrimitiveValue::UnitType unitType = CSSPrimitiveValue::UnitType::UserUnit s;
139 unsigned unitTypeCount = 0; 137 unsigned unitTypeCount = 0;
140 // We optimise for the common case where only one unit type is involved. 138 // We optimise for the common case where only one unit type is involved.
141 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) { 139 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) {
142 double entry = toInterpolableNumber(listOfValues.get(i))->value(); 140 double entry = toInterpolableNumber(listOfValues.get(i))->value();
(...skipping 13 matching lines...) Expand all
156 154
157 // SVGLength does not support calc expressions, so we convert to canonic al units. 155 // SVGLength does not support calc expressions, so we convert to canonic al units.
158 SVGLengthContext lengthContext(element); 156 SVGLengthContext lengthContext(element);
159 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) { 157 for (size_t i = 0; i < numLengthInterpolatedUnits; i++) {
160 double entry = toInterpolableNumber(listOfValues.get(i))->value(); 158 double entry = toInterpolableNumber(listOfValues.get(i))->value();
161 if (entry) 159 if (entry)
162 value += lengthContext.convertValueToUserUnits(entry, modeData.u nitMode, unitTypes[i]); 160 value += lengthContext.convertValueToUserUnits(entry, modeData.u nitMode, unitTypes[i]);
163 } 161 }
164 } 162 }
165 163
166 if (modeData.negativeValuesMode == ForbidNegativeLengths && value < 0) 164 if (SVGLength::negativeValuesForbiddenForAnimatedLengthAttribute(attributeNa me) && value < 0)
167 value = 0; 165 value = 0;
168 166
169 RefPtrWillBeRawPtr<SVGLength> result = SVGLength::create(modeData.unitMode); // defaults to the length 0 167 RefPtrWillBeRawPtr<SVGLength> result = SVGLength::create(modeData.unitMode); // defaults to the length 0
170 result->newValueSpecifiedUnits(unitType, value); 168 result->newValueSpecifiedUnits(unitType, value);
171 return result.release(); 169 return result.release();
172 } 170 }
173 171
174 PassRefPtrWillBeRawPtr<SVGPropertyBase> LengthSVGInterpolation::interpolatedValu e(SVGElement& targetElement) const 172 PassRefPtrWillBeRawPtr<SVGPropertyBase> LengthSVGInterpolation::interpolatedValu e(SVGElement& targetElement) const
175 { 173 {
176 return fromInterpolableValue(*m_cachedValue, m_modeData, &targetElement); 174 return fromInterpolableValue(*m_cachedValue, m_modeData, &targetElement, att ributeName());
177 } 175 }
178 176
179 } 177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698