OLD | NEW |
---|---|
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 length->m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitTy pe::UserUnits); | 64 length->m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitTy pe::UserUnits); |
65 | 65 |
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 bool isCalcCSSUnitType(CSSPrimitiveValue::UnitType type) | |
fs
2016/07/16 21:13:02
Make this static (and isSupportedCSSUnitType too,
Shanmuga Pandi
2016/07/18 13:35:33
Done.
| |
75 { | |
76 return (type >= CSSPrimitiveValue::UnitType::Calc && type <= CSSPrimitiveVal ue::UnitType::CalcPercentageWithLengthAndNumber); | |
fs
2016/07/16 21:13:02
Drop parenthesis.
Shanmuga Pandi
2016/07/18 13:35:33
Done.
| |
77 } | |
78 | |
79 float SVGLength::resolveCalcValue(const SVGLengthContext& context) const | |
fs
2016/07/16 21:13:02
We could consider going through CSSPrimitiveValue:
Shanmuga Pandi
2016/07/18 13:35:33
Done.
| |
80 { | |
81 CSSLengthArray lengthArray; | |
82 m_value->accumulateLengthArray(lengthArray); | |
83 float value = 0; | |
fs
2016/07/16 21:13:02
If we end up keeping this I suggest making this 'd
| |
84 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { | |
85 double entry = lengthArray.values[i]; | |
86 if (entry) | |
87 value += context.convertValueToUserUnits(entry, unitMode(), SVGLengt h::toUnitType(i)); | |
88 } | |
89 return value; | |
90 } | |
91 | |
74 float SVGLength::value(const SVGLengthContext& context) const | 92 float SVGLength::value(const SVGLengthContext& context) const |
75 { | 93 { |
94 if (isCalculated()) | |
95 return resolveCalcValue(context); | |
96 | |
76 return context.convertValueToUserUnits( | 97 return context.convertValueToUserUnits( |
77 m_value->getFloatValue(), unitMode(), m_value->typeWithCalcResolved()); | 98 m_value->getFloatValue(), unitMode(), m_value->typeWithCalcResolved()); |
78 } | 99 } |
79 | 100 |
101 void SVGLength::setValueAsNumber(float value) | |
102 { | |
103 m_value = CSSPrimitiveValue::create(value, CSSPrimitiveValue::UnitType::User Units); | |
104 } | |
105 | |
80 void SVGLength::setValue(float value, const SVGLengthContext& context) | 106 void SVGLength::setValue(float value, const SVGLengthContext& context) |
81 { | 107 { |
82 m_value = CSSPrimitiveValue::create( | 108 m_value = CSSPrimitiveValue::create( |
83 context.convertValueFromUserUnits(value, unitMode(), m_value->typeWithCa lcResolved()), | 109 context.convertValueFromUserUnits(value, unitMode(), m_value->typeWithCa lcResolved()), |
84 m_value->typeWithCalcResolved()); | 110 m_value->typeWithCalcResolved()); |
85 } | 111 } |
86 | 112 |
87 bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type) | 113 bool isSupportedCSSUnitType(CSSPrimitiveValue::UnitType type) |
88 { | 114 { |
89 return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::Unit Type::Number || type == CSSPrimitiveValue::UnitType::Percentage) | 115 return (CSSPrimitiveValue::isLength(type) || type == CSSPrimitiveValue::Unit Type::Number |
116 || type == CSSPrimitiveValue::UnitType::Percentage || isCalcCSSUnitType( type)) | |
90 && type != CSSPrimitiveValue::UnitType::QuirkyEms; | 117 && type != CSSPrimitiveValue::UnitType::QuirkyEms; |
91 } | 118 } |
92 | 119 |
93 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type) | 120 void SVGLength::setUnitType(CSSPrimitiveValue::UnitType type) |
94 { | 121 { |
95 ASSERT(isSupportedCSSUnitType(type)); | 122 ASSERT(isSupportedCSSUnitType(type)); |
96 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type); | 123 m_value = CSSPrimitiveValue::create(m_value->getFloatValue(), type); |
97 } | 124 } |
98 | 125 |
99 float SVGLength::valueAsPercentage() const | 126 float SVGLength::valueAsPercentage() const |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::User Units); | 159 m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::User Units); |
133 return SVGParseStatus::NoError; | 160 return SVGParseStatus::NoError; |
134 } | 161 } |
135 | 162 |
136 CSSParserContext svgParserContext(SVGAttributeMode, nullptr); | 163 CSSParserContext svgParserContext(SVGAttributeMode, nullptr); |
137 CSSValue* parsed = CSSParser::parseSingleValue(CSSPropertyX, string, svgPars erContext); | 164 CSSValue* parsed = CSSParser::parseSingleValue(CSSPropertyX, string, svgPars erContext); |
138 if (!parsed || !parsed->isPrimitiveValue()) | 165 if (!parsed || !parsed->isPrimitiveValue()) |
139 return SVGParseStatus::ExpectedLength; | 166 return SVGParseStatus::ExpectedLength; |
140 | 167 |
141 CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed); | 168 CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed); |
142 // TODO(fs): Enable calc for SVG lengths | 169 if (!isSupportedCSSUnitType(newValue->typeWithCalcResolved())) |
143 if (newValue->isCalculated() || !isSupportedCSSUnitType(newValue->typeWithCa lcResolved())) | |
144 return SVGParseStatus::ExpectedLength; | 170 return SVGParseStatus::ExpectedLength; |
145 | 171 |
146 m_value = newValue; | 172 m_value = newValue; |
173 | |
fs
2016/07/16 21:13:02
Drop.
Shanmuga Pandi
2016/07/18 13:35:32
Done.
| |
147 return SVGParseStatus::NoError; | 174 return SVGParseStatus::NoError; |
148 } | 175 } |
149 | 176 |
150 String SVGLength::valueAsString() const | 177 String SVGLength::valueAsString() const |
151 { | 178 { |
152 return m_value->customCSSText(); | 179 return m_value->customCSSText(); |
153 } | 180 } |
154 | 181 |
155 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, float v alue) | 182 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, float v alue) |
156 { | 183 { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 SVGLength* toLength = toSVGLength(toValue); | 266 SVGLength* toLength = toSVGLength(toValue); |
240 SVGLength* toAtEndOfDurationLength = toSVGLength(toAtEndOfDurationValue); | 267 SVGLength* toAtEndOfDurationLength = toSVGLength(toAtEndOfDurationValue); |
241 | 268 |
242 SVGLengthContext lengthContext(contextElement); | 269 SVGLengthContext lengthContext(contextElement); |
243 float animatedNumber = value(lengthContext); | 270 float animatedNumber = value(lengthContext); |
244 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext), | 271 animationElement->animateAdditiveNumber(percentage, repeatCount, fromLength- >value(lengthContext), |
245 toLength->value(lengthContext), toAtEndOfDurationLength->value(lengthCon text), animatedNumber); | 272 toLength->value(lengthContext), toAtEndOfDurationLength->value(lengthCon text), animatedNumber); |
246 | 273 |
247 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName())); | 274 ASSERT(unitMode() == lengthModeForAnimatedLengthAttribute(animationElement-> attributeName())); |
248 | 275 |
249 CSSPrimitiveValue::UnitType newUnit = percentage < 0.5 ? fromLength->typeWit hCalcResolved() : toLength->typeWithCalcResolved(); | 276 CSSPrimitiveValue::UnitType newUnit = CSSPrimitiveValue::UnitType::UserUnits ; |
277 if (percentage < 0.5) { | |
278 if (!fromLength->isCalculated()) | |
fs
2016/07/16 21:13:02
Test for this code? (Preferably i think this would
Shanmuga Pandi
2016/07/18 13:35:32
Yes. We could just construct a calc_expression lat
fs
2016/07/18 13:56:48
Please add a TODO about constructing a calc() expr
| |
279 newUnit = fromLength->typeWithCalcResolved(); | |
280 } else { | |
281 if (!toLength->isCalculated()) | |
282 newUnit = toLength->typeWithCalcResolved(); | |
283 } | |
250 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, uni tMode(), newUnit); | 284 animatedNumber = lengthContext.convertValueFromUserUnits(animatedNumber, uni tMode(), newUnit); |
251 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit); | 285 m_value = CSSPrimitiveValue::create(animatedNumber, newUnit); |
252 } | 286 } |
253 | 287 |
254 float SVGLength::calculateDistance(SVGPropertyBase* toValue, SVGElement* context Element) | 288 float SVGLength::calculateDistance(SVGPropertyBase* toValue, SVGElement* context Element) |
255 { | 289 { |
256 SVGLengthContext lengthContext(contextElement); | 290 SVGLengthContext lengthContext(contextElement); |
257 SVGLength* toLength = toSVGLength(toValue); | 291 SVGLength* toLength = toSVGLength(toValue); |
258 | 292 |
259 return fabsf(toLength->value(lengthContext) - value(lengthContext)); | 293 return fabsf(toLength->value(lengthContext) - value(lengthContext)); |
260 } | 294 } |
261 | 295 |
262 } // namespace blink | 296 } // namespace blink |
OLD | NEW |