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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGRect.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/SVGRect.h" 22 #include "core/svg/SVGRect.h"
23 23
24 #include "bindings/core/v8/ExceptionState.h"
25 #include "core/dom/ExceptionCode.h"
26 #include "core/svg/SVGAnimationElement.h" 24 #include "core/svg/SVGAnimationElement.h"
27 #include "core/svg/SVGParserUtilities.h" 25 #include "core/svg/SVGParserUtilities.h"
28 #include "wtf/text/StringBuilder.h" 26 #include "wtf/text/StringBuilder.h"
29 #include "wtf/text/WTFString.h" 27 #include "wtf/text/WTFString.h"
30 28
31 namespace blink { 29 namespace blink {
32 30
33 SVGRect::SVGRect() 31 SVGRect::SVGRect()
34 : m_isValid(true) 32 : m_isValid(true)
35 { 33 {
36 } 34 }
37 35
38 SVGRect::SVGRect(const FloatRect& rect) 36 SVGRect::SVGRect(const FloatRect& rect)
39 : m_isValid(true) 37 : m_isValid(true)
40 , m_value(rect) 38 , m_value(rect)
41 { 39 {
42 } 40 }
43 41
44 PassRefPtrWillBeRawPtr<SVGRect> SVGRect::clone() const 42 PassRefPtrWillBeRawPtr<SVGRect> SVGRect::clone() const
45 { 43 {
46 return SVGRect::create(m_value); 44 return SVGRect::create(m_value);
47 } 45 }
48 46
49 template<typename CharType> 47 template<typename CharType>
50 void SVGRect::parse(const CharType*& ptr, const CharType* end, ExceptionState& e xceptionState) 48 bool SVGRect::parse(const CharType*& ptr, const CharType* end)
51 { 49 {
52 const CharType* start = ptr;
53
54 skipOptionalSVGSpaces(ptr, end); 50 skipOptionalSVGSpaces(ptr, end);
55 51
56 float x = 0.0f; 52 float x = 0.0f;
57 float y = 0.0f; 53 float y = 0.0f;
58 float width = 0.0f; 54 float width = 0.0f;
59 float height = 0.0f; 55 float height = 0.0f;
60 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && parseNu mber(ptr, end, width) && parseNumber(ptr, end, height, DisallowWhitespace); 56 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && parseNu mber(ptr, end, width) && parseNumber(ptr, end, height, DisallowWhitespace);
61 57
62 if (!valid) { 58 if (!valid)
63 exceptionState.throwDOMException(SyntaxError, "Problem parsing rect \"" + String(start, end - start) + "\""); 59 return false;
64 setInvalid();
65 return;
66 }
67 60
68 skipOptionalSVGSpaces(ptr, end); 61 if (skipOptionalSVGSpaces(ptr, end)) {
69 if (ptr < end) { // nothing should come after the last, fourth number 62 // Nothing should come after the last, fourth number.
70 exceptionState.throwDOMException(SyntaxError, "Problem parsing rect \"" + String(start, end - start) + "\""); 63 return false;
71 setInvalid();
72 return;
73 } 64 }
74 65
75 m_value = FloatRect(x, y, width, height); 66 m_value = FloatRect(x, y, width, height);
76 m_isValid = true; 67 m_isValid = true;
68 return true;
77 } 69 }
78 70
79 void SVGRect::setValueAsString(const String& string, ExceptionState& exceptionSt ate) 71 SVGParsingError SVGRect::setValueAsString(const String& string)
80 { 72 {
81 if (string.isNull()) { 73 setInvalid();
82 setInvalid(); 74
83 return; 75 if (string.isNull())
84 } 76 return NoError;
77
85 if (string.isEmpty()) { 78 if (string.isEmpty()) {
86 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f); 79 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f);
87 m_isValid = true; 80 m_isValid = true;
88 return; 81 return NoError;
89 } 82 }
90 83
84 bool valid;
91 if (string.is8Bit()) { 85 if (string.is8Bit()) {
92 const LChar* ptr = string.characters8(); 86 const LChar* ptr = string.characters8();
93 const LChar* end = ptr + string.length(); 87 const LChar* end = ptr + string.length();
94 parse(ptr, end, exceptionState); 88 valid = parse(ptr, end);
95 return; 89 } else {
90 const UChar* ptr = string.characters16();
91 const UChar* end = ptr + string.length();
92 valid = parse(ptr, end);
96 } 93 }
97 94 return valid ? NoError : ParsingAttributeFailedError;
98 const UChar* ptr = string.characters16();
99 const UChar* end = ptr + string.length();
100 parse(ptr, end, exceptionState);
101 } 95 }
102 96
103 String SVGRect::valueAsString() const 97 String SVGRect::valueAsString() const
104 { 98 {
105 StringBuilder builder; 99 StringBuilder builder;
106 builder.appendNumber(x()); 100 builder.appendNumber(x());
107 builder.append(' '); 101 builder.append(' ');
108 builder.appendNumber(y()); 102 builder.appendNumber(y());
109 builder.append(' '); 103 builder.append(' ');
110 builder.appendNumber(width()); 104 builder.appendNumber(width());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return -1; 137 return -1;
144 } 138 }
145 139
146 void SVGRect::setInvalid() 140 void SVGRect::setInvalid()
147 { 141 {
148 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f); 142 m_value = FloatRect(0.0f, 0.0f, 0.0f, 0.0f);
149 m_isValid = false; 143 m_isValid = false;
150 } 144 }
151 145
152 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698