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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGLengthList.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 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 /* 1 /*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "core/svg/SVGLengthList.h" 21 #include "core/svg/SVGLengthList.h"
22 22
23 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
24 #include "core/svg/SVGAnimationElement.h" 23 #include "core/svg/SVGAnimationElement.h"
25 #include "core/svg/SVGParserUtilities.h" 24 #include "core/svg/SVGParserUtilities.h"
26 #include "wtf/text/StringBuilder.h" 25 #include "wtf/text/StringBuilder.h"
27 26
28 namespace blink { 27 namespace blink {
29 28
30 DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGLengthList); 29 DEFINE_SVG_PROPERTY_TYPE_CASTS(SVGLengthList);
31 30
32 SVGLengthList::SVGLengthList(SVGLengthMode mode) 31 SVGLengthList::SVGLengthList(SVGLengthMode mode)
33 : m_mode(mode) 32 : m_mode(mode)
34 { 33 {
35 } 34 }
36 35
37 SVGLengthList::~SVGLengthList() 36 SVGLengthList::~SVGLengthList()
38 { 37 {
39 } 38 }
40 39
41 PassRefPtrWillBeRawPtr<SVGLengthList> SVGLengthList::clone() 40 PassRefPtrWillBeRawPtr<SVGLengthList> SVGLengthList::clone()
42 { 41 {
43 RefPtrWillBeRawPtr<SVGLengthList> ret = SVGLengthList::create(m_mode); 42 RefPtrWillBeRawPtr<SVGLengthList> ret = SVGLengthList::create(m_mode);
44 ret->deepCopy(this); 43 ret->deepCopy(this);
45 return ret.release(); 44 return ret.release();
46 } 45 }
47 46
48 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLengthList::cloneForAnimation(const S tring& value) const 47 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGLengthList::cloneForAnimation(const S tring& value) const
49 { 48 {
50 RefPtrWillBeRawPtr<SVGLengthList> ret = SVGLengthList::create(m_mode); 49 RefPtrWillBeRawPtr<SVGLengthList> ret = SVGLengthList::create(m_mode);
51 ret->setValueAsString(value, IGNORE_EXCEPTION); 50 ret->setValueAsString(value);
52 return ret.release(); 51 return ret.release();
53 } 52 }
54 53
55 String SVGLengthList::valueAsString() const 54 String SVGLengthList::valueAsString() const
56 { 55 {
57 StringBuilder builder; 56 StringBuilder builder;
58 57
59 ConstIterator it = begin(); 58 ConstIterator it = begin();
60 ConstIterator itEnd = end(); 59 ConstIterator itEnd = end();
61 if (it != itEnd) { 60 if (it != itEnd) {
62 builder.append(it->valueAsString()); 61 builder.append(it->valueAsString());
63 ++it; 62 ++it;
64 63
65 for (; it != itEnd; ++it) { 64 for (; it != itEnd; ++it) {
66 builder.append(' '); 65 builder.append(' ');
67 builder.append(it->valueAsString()); 66 builder.append(it->valueAsString());
68 } 67 }
69 } 68 }
70 69
71 return builder.toString(); 70 return builder.toString();
72 } 71 }
73 72
74 template <typename CharType> 73 template <typename CharType>
75 void SVGLengthList::parseInternal(const CharType*& ptr, const CharType* end, Exc eptionState& exceptionState) 74 SVGParsingError SVGLengthList::parseInternal(const CharType*& ptr, const CharTyp e* end)
76 { 75 {
77 clear(); 76 clear();
78 while (ptr < end) { 77 while (ptr < end) {
79 const CharType* start = ptr; 78 const CharType* start = ptr;
80 while (ptr < end && *ptr != ',' && !isHTMLSpace<CharType>(*ptr)) 79 while (ptr < end && *ptr != ',' && !isHTMLSpace<CharType>(*ptr))
81 ptr++; 80 ptr++;
82 if (ptr == start) 81 if (ptr == start)
83 break; 82 break;
83 String valueString(start, ptr - start);
84 if (valueString.isEmpty())
85 break;
84 86
85 RefPtrWillBeRawPtr<SVGLength> length = SVGLength::create(m_mode); 87 RefPtrWillBeRawPtr<SVGLength> length = SVGLength::create(m_mode);
86 String valueString(start, ptr - start); 88 SVGParsingError lengthParseStatus = length->setValueAsString(valueString );
87 if (valueString.isEmpty()) 89 if (lengthParseStatus != NoError)
88 return; 90 return lengthParseStatus;
89 length->setValueAsString(valueString, exceptionState);
90 if (exceptionState.hadException())
91 return;
92 append(length); 91 append(length);
93 skipOptionalSVGSpacesOrDelimiter(ptr, end); 92 skipOptionalSVGSpacesOrDelimiter(ptr, end);
94 } 93 }
94 return NoError;
95 } 95 }
96 96
97 void SVGLengthList::setValueAsString(const String& value, ExceptionState& except ionState) 97 SVGParsingError SVGLengthList::setValueAsString(const String& value)
98 { 98 {
99 if (value.isEmpty()) { 99 if (value.isEmpty()) {
100 clear(); 100 clear();
101 return; 101 return NoError;
102 } 102 }
103
104 SVGParsingError parseStatus;
103 if (value.is8Bit()) { 105 if (value.is8Bit()) {
104 const LChar* ptr = value.characters8(); 106 const LChar* ptr = value.characters8();
105 const LChar* end = ptr + value.length(); 107 const LChar* end = ptr + value.length();
106 parseInternal(ptr, end, exceptionState); 108 parseStatus = parseInternal(ptr, end);
107 } else { 109 } else {
108 const UChar* ptr = value.characters16(); 110 const UChar* ptr = value.characters16();
109 const UChar* end = ptr + value.length(); 111 const UChar* end = ptr + value.length();
110 parseInternal(ptr, end, exceptionState); 112 parseStatus = parseInternal(ptr, end);
111 } 113 }
114 return parseStatus;
112 } 115 }
113 116
114 void SVGLengthList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElemen t* contextElement) 117 void SVGLengthList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElemen t* contextElement)
115 { 118 {
116 RefPtrWillBeRawPtr<SVGLengthList> otherList = toSVGLengthList(other); 119 RefPtrWillBeRawPtr<SVGLengthList> otherList = toSVGLengthList(other);
117 120
118 if (length() != otherList->length()) 121 if (length() != otherList->length())
119 return; 122 return;
120 123
121 SVGLengthContext lengthContext(contextElement); 124 SVGLengthContext lengthContext(contextElement);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 at(i)->setValue(animatedNumber, lengthContext); 164 at(i)->setValue(animatedNumber, lengthContext);
162 } 165 }
163 } 166 }
164 167
165 float SVGLengthList::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> t o, SVGElement*) 168 float SVGLengthList::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> t o, SVGElement*)
166 { 169 {
167 // FIXME: Distance calculation is not possible for SVGLengthList right now. We need the distance for every single value. 170 // FIXME: Distance calculation is not possible for SVGLengthList right now. We need the distance for every single value.
168 return -1; 171 return -1;
169 } 172 }
170 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698