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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGLength.cpp

Issue 2097383002: Added support of calc() for SVGLength (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 5 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 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return length; 66 return length;
67 } 67 }
68 68
69 bool SVGLength::operator==(const SVGLength& other) const 69 bool SVGLength::operator==(const SVGLength& other) const
70 { 70 {
71 return m_unitMode == other.m_unitMode && m_value == other.m_value; 71 return m_unitMode == other.m_unitMode && m_value == other.m_value;
72 } 72 }
73 73
74 float SVGLength::value(const SVGLengthContext& context) const 74 float SVGLength::value(const SVGLengthContext& context) const
75 { 75 {
76 if (isCalculated())
77 return context.resolveValue(asCSSPrimitiveValue(), unitMode());
78
76 return context.convertValueToUserUnits( 79 return context.convertValueToUserUnits(
77 m_value->getFloatValue(), unitMode(), m_value->typeWithCalcResolved()); 80 m_value->getFloatValue(), unitMode(), m_value->typeWithCalcResolved());
78 } 81 }
79 82
83 void SVGLength::setValueAsNumber(float value)
84 {
85 m_value = CSSPrimitiveValue::create(value, CSSPrimitiveValue::UnitType::User Units);
86 }
87
80 void SVGLength::setValue(float value, const SVGLengthContext& context) 88 void SVGLength::setValue(float value, const SVGLengthContext& context)
81 { 89 {
82 m_value = CSSPrimitiveValue::create( 90 m_value = CSSPrimitiveValue::create(
83 context.convertValueFromUserUnits(value, unitMode(), m_value->typeWithCa lcResolved()), 91 context.convertValueFromUserUnits(value, unitMode(), m_value->typeWithCa lcResolved()),
84 m_value->typeWithCalcResolved()); 92 m_value->typeWithCalcResolved());
85 } 93 }
86 94
87 bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type) 95 static bool isCalcCSSUnitType(CSSPrimitiveValue::UnitType type)
88 { 96 {
89 return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::Unit Type::Number || type == CSSPrimitiveValue::UnitType::Percentage) 97 return type >= CSSPrimitiveValue::UnitType::Calc && type <= CSSPrimitiveValu e::UnitType::CalcPercentageWithLengthAndNumber;
98 }
99
100 static bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type)
101 {
102 return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::Unit Type::Number
103 || type == CSSPrimitiveValue::UnitType::Percentage || isCalcCSSUnitType( type))
90 && type != CSSPrimitiveValue::UnitType::QuirkyEms; 104 && type != CSSPrimitiveValue::UnitType::QuirkyEms;
91 } 105 }
92 106
93 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type) 107 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type)
94 { 108 {
95 ASSERT(isSupportedCSSUnitType(type)); 109 ASSERT(isSupportedCSSUnitType(type));
96 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type); 110 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type);
97 } 111 }
98 112
99 float SVGLength::valueAsPercentage() const 113 float SVGLength::valueAsPercentage() const
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::User Units); 146 m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::User Units);
133 return SVGParseStatus::NoError; 147 return SVGParseStatus::NoError;
134 } 148 }
135 149
136 CSSParserContext svgParserContext(SVGAttributeMode, nullptr); 150 CSSParserContext svgParserContext(SVGAttributeMode, nullptr);
137 CSSValue* parsed = CSSParser::parseSingleValue(CSSPropertyX, string, svgPars erContext); 151 CSSValue* parsed = CSSParser::parseSingleValue(CSSPropertyX, string, svgPars erContext);
138 if (!parsed || !parsed->isPrimitiveValue()) 152 if (!parsed || !parsed->isPrimitiveValue())
139 return SVGParseStatus::ExpectedLength; 153 return SVGParseStatus::ExpectedLength;
140 154
141 CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed); 155 CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed);
142 // TODO(fs): Enable calc for SVG lengths 156 if (!isSupportedCSSUnitType(newValue->typeWithCalcResolved()))
143 if (newValue->isCalculated() || !isSupportedCSSUnitType(newValue->typeWithCa lcResolved()))
144 return SVGParseStatus::ExpectedLength; 157 return SVGParseStatus::ExpectedLength;
145 158
146 m_value = newValue; 159 m_value = newValue;
147 return SVGParseStatus::NoError; 160 return SVGParseStatus::NoError;
148 } 161 }
149 162
150 String SVGLength::valueAsString() const 163 String SVGLength::valueAsString() const
151 { 164 {
152 return m_value->customCSSText(); 165 return m_value->customCSSText();
153 } 166 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 SVGLength* toLength = toSVGLength(toValue); 252 SVGLength* toLength = toSVGLength(toValue);
240 SVGLength* toAtEndOfDurationLength = toSVGLength(toAtEndOfDurationValue); 253 SVGLength* toAtEndOfDurationLength = toSVGLength(toAtEndOfDurationValue);
241 254
242 SVGLengthContext lengthContext(contextElement); 255 SVGLengthContext lengthContext(contextElement);
243 float animatedNumber = value(lengthContext); 256 float animatedNumber = value(lengthContext);
244 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext), 257 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext),
245 toLength->value(lengthContext), toAtEndOfDurationLength->value(lengthCon text), animatedNumber); 258 toLength->value(lengthContext), toAtEndOfDurationLength->value(lengthCon text), animatedNumber);
246 259
247 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName())); 260 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName()));
248 261
249 CSSPrimitiveValue::UnitType newUnit = percentage < 0.5 ? fromLength->typeWit hCalcResolved() : toLength->typeWithCalcResolved(); 262 CSSPrimitiveValue::UnitType newUnit = CSSPrimitiveValue::UnitType::UserUnits ;
263 if (percentage < 0.5) {
264 if (!fromLength->isCalculated())
265 newUnit = fromLength->typeWithCalcResolved();
266 } else {
267 if (!toLength->isCalculated())
268 newUnit = toLength->typeWithCalcResolved();
269 }
250 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, uni tMode(), newUnit); 270 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, uni tMode(), newUnit);
251 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit); 271 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit);
252 } 272 }
253 273
254 float SVGLength::calculateDistance(SVGPropertyBase* toValue, SVGElement* context Element) 274 float SVGLength::calculateDistance(SVGPropertyBase* toValue, SVGElement* context Element)
255 { 275 {
256 SVGLengthContext lengthContext(contextElement); 276 SVGLengthContext lengthContext(contextElement);
257 SVGLength* toLength = toSVGLength(toValue); 277 SVGLength* toLength = toSVGLength(toValue);
258 278
259 return fabsf(toLength->value(lengthContext) - value(lengthContext)); 279 return fabsf(toLength->value(lengthContext) - value(lengthContext));
260 } 280 }
261 281
262 } // namespace blink 282 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698