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

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

Issue 1544673003: Refactor propagation of parsing errors for SVG attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "core/svg/SVGLength.h" 22 #include "core/svg/SVGLength.h"
23 23
24 #include "bindings/core/v8/ExceptionState.h"
25 #include "core/SVGNames.h" 24 #include "core/SVGNames.h"
26 #include "core/css/CSSPrimitiveValue.h" 25 #include "core/css/CSSPrimitiveValue.h"
27 #include "core/css/CSSValue.h" 26 #include "core/css/CSSValue.h"
28 #include "core/css/CSSValuePool.h" 27 #include "core/css/CSSValuePool.h"
29 #include "core/css/parser/CSSParser.h" 28 #include "core/css/parser/CSSParser.h"
30 #include "core/dom/ExceptionCode.h"
31 #include "core/svg/SVGAnimationElement.h" 29 #include "core/svg/SVGAnimationElement.h"
32 #include "core/svg/SVGParserUtilities.h"
33 #include "platform/animation/AnimationUtilities.h"
34 #include "wtf/MathExtras.h" 30 #include "wtf/MathExtras.h"
35 #include "wtf/text/WTFString.h" 31 #include "wtf/text/WTFString.h"
36 32
37 namespace blink { 33 namespace blink {
38 34
39 SVGLength::SVGLength(SVGLengthMode mode) 35 SVGLength::SVGLength(SVGLengthMode mode)
40 : SVGPropertyBase(classType()) 36 : SVGPropertyBase(classType())
41 , m_value(cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::UserUni ts)) 37 , m_value(cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::UserUni ts))
42 , m_unitMode(static_cast<unsigned>(mode)) 38 , m_unitMode(static_cast<unsigned>(mode))
43 { 39 {
(...skipping 14 matching lines...) Expand all
58 } 54 }
59 55
60 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::clone() const 56 PassRefPtrWillBeRawPtr<SVGLength> SVGLength::clone() const
61 { 57 {
62 return adoptRefWillBeNoop(new SVGLength(*this)); 58 return adoptRefWillBeNoop(new SVGLength(*this));
63 } 59 }
64 60
65 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLength::cloneForAnimation(const Strin g& value) const 61 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLength::cloneForAnimation(const Strin g& value) const
66 { 62 {
67 RefPtrWillBeRawPtr<SVGLength> length = create(); 63 RefPtrWillBeRawPtr<SVGLength> length = create();
68
69 length->m_unitMode = m_unitMode; 64 length->m_unitMode = m_unitMode;
70 65
71 TrackExceptionState exceptionState; 66 SVGParsingError status = length->setValueAsString(value);
72 length->setValueAsString(value, exceptionState); 67 if (status != NoError)
73 if (exceptionState.hadException()) { 68 length->m_value = cssValuePool().createValue(0, CSSPrimitiveValue::UnitT ype::UserUnits);
74 length->m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitTy pe::UserUnits);
75 }
76 69
77 return length.release(); 70 return length.release();
78 } 71 }
79 72
80 bool SVGLength::operator==(const SVGLength& other) const 73 bool SVGLength::operator==(const SVGLength& other) const
81 { 74 {
82 return m_unitMode == other.m_unitMode && m_value == other.m_value; 75 return m_unitMode == other.m_unitMode && m_value == other.m_value;
83 } 76 }
84 77
85 float SVGLength::value(const SVGLengthContext& context) const 78 float SVGLength::value(const SVGLengthContext& context) const
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 float SVGLength::scaleByPercentage(float input) const 125 float SVGLength::scaleByPercentage(float input) const
133 { 126 {
134 float result = input * m_value->getFloatValue(); 127 float result = input * m_value->getFloatValue();
135 if (m_value->isPercentage()) { 128 if (m_value->isPercentage()) {
136 // Delaying division by 100 as long as possible since it introduces floa ting point errors. 129 // Delaying division by 100 as long as possible since it introduces floa ting point errors.
137 result = result / 100; 130 result = result / 100;
138 } 131 }
139 return result; 132 return result;
140 } 133 }
141 134
142 void SVGLength::setValueAsString(const String& string, ExceptionState& exception State) 135 SVGParsingError SVGLength::setValueAsString(const String& string)
143 { 136 {
144 if (string.isEmpty()) { 137 if (string.isEmpty()) {
145 m_value = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Use rUnits); 138 m_value = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Use rUnits);
146 return; 139 return NoError;
147 } 140 }
148 141
149 CSSParserContext svgParserContext(SVGAttributeMode, 0); 142 CSSParserContext svgParserContext(SVGAttributeMode, 0);
150 RefPtrWillBeRawPtr<CSSValue> parsed = CSSParser::parseSingleValue(CSSPropert yX, string, svgParserContext); 143 RefPtrWillBeRawPtr<CSSValue> parsed = CSSParser::parseSingleValue(CSSPropert yX, string, svgParserContext);
151 if (!parsed || !parsed->isPrimitiveValue()) { 144 if (!parsed || !parsed->isPrimitiveValue())
152 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid."); 145 return ParsingAttributeFailedError;
153 return;
154 }
155 146
156 CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed.get()); 147 CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed.get());
157 // TODO(fs): Enable calc for SVG lengths 148 // TODO(fs): Enable calc for SVG lengths
158 if (newValue->isCalculated() || !isSupportedCSSUnitType(newValue->typeWithCa lcResolved())) { 149 if (newValue->isCalculated() || !isSupportedCSSUnitType(newValue->typeWithCa lcResolved()))
159 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid."); 150 return ParsingAttributeFailedError;
160 return;
161 }
162 151
163 m_value = newValue; 152 m_value = newValue;
153 return NoError;
164 } 154 }
165 155
166 String SVGLength::valueAsString() const 156 String SVGLength::valueAsString() const
167 { 157 {
168 return m_value->customCSSText(); 158 return m_value->customCSSText();
169 } 159 }
170 160
171 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, float v alue) 161 void SVGLength::newValueSpecifiedUnits(CSSPrimitiveValue::UnitType type, float v alue)
172 { 162 {
173 m_value = CSSPrimitiveValue::create(value, type); 163 m_value = CSSPrimitiveValue::create(value, type);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 262
273 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal ue, SVGElement* contextElement) 263 float SVGLength::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> toVal ue, SVGElement* contextElement)
274 { 264 {
275 SVGLengthContext lengthContext(contextElement); 265 SVGLengthContext lengthContext(contextElement);
276 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue); 266 RefPtrWillBeRawPtr<SVGLength> toLength = toSVGLength(toValue);
277 267
278 return fabsf(toLength->value(lengthContext) - value(lengthContext)); 268 return fabsf(toLength->value(lengthContext) - value(lengthContext));
279 } 269 }
280 270
281 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698