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

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

Issue 1588993005: Extended error reporting for SVG attribute parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PLATFORM_EXPORT Created 4 years, 11 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, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 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) 2010 Dirk Schulze <krit@webkit.org> 4 * Copyright (C) 2010 Dirk Schulze <krit@webkit.org>
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 { 45 {
46 RefPtrWillBeRawPtr<SVGPreserveAspectRatio> preserveAspectRatio = create(); 46 RefPtrWillBeRawPtr<SVGPreserveAspectRatio> preserveAspectRatio = create();
47 47
48 preserveAspectRatio->m_align = m_align; 48 preserveAspectRatio->m_align = m_align;
49 preserveAspectRatio->m_meetOrSlice = m_meetOrSlice; 49 preserveAspectRatio->m_meetOrSlice = m_meetOrSlice;
50 50
51 return preserveAspectRatio.release(); 51 return preserveAspectRatio.release();
52 } 52 }
53 53
54 template<typename CharType> 54 template<typename CharType>
55 bool SVGPreserveAspectRatio::parseInternal(const CharType*& ptr, const CharType* end, bool validate) 55 SVGParsingError SVGPreserveAspectRatio::parseInternal(const CharType*& ptr, cons t CharType* end, bool validate)
56 { 56 {
57 SVGPreserveAspectRatioType align = SVG_PRESERVEASPECTRATIO_XMIDYMID; 57 SVGPreserveAspectRatioType align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
58 SVGMeetOrSliceType meetOrSlice = SVG_MEETORSLICE_MEET; 58 SVGMeetOrSliceType meetOrSlice = SVG_MEETORSLICE_MEET;
59 59
60 setAlign(align); 60 setAlign(align);
61 setMeetOrSlice(meetOrSlice); 61 setMeetOrSlice(meetOrSlice);
62 62
63 const CharType* start = ptr;
63 if (!skipOptionalSVGSpaces(ptr, end)) 64 if (!skipOptionalSVGSpaces(ptr, end))
64 return false; 65 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start) ;
65 66
66 if (*ptr == 'n') { 67 if (*ptr == 'n') {
67 if (!skipString(ptr, end, "none")) 68 if (!skipString(ptr, end, "none"))
68 return false; 69 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - st art);
69 align = SVG_PRESERVEASPECTRATIO_NONE; 70 align = SVG_PRESERVEASPECTRATIO_NONE;
70 skipOptionalSVGSpaces(ptr, end); 71 skipOptionalSVGSpaces(ptr, end);
71 } else if (*ptr == 'x') { 72 } else if (*ptr == 'x') {
72 if ((end - ptr) < 8) 73 if ((end - ptr) < 8)
73 return false; 74 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - st art);
74 if (ptr[1] != 'M' || ptr[4] != 'Y' || ptr[5] != 'M') 75 if (ptr[1] != 'M' || ptr[4] != 'Y' || ptr[5] != 'M')
75 return false; 76 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - st art);
76 if (ptr[2] == 'i') { 77 if (ptr[2] == 'i') {
77 if (ptr[3] == 'n') { 78 if (ptr[3] == 'n') {
78 if (ptr[6] == 'i') { 79 if (ptr[6] == 'i') {
79 if (ptr[7] == 'n') 80 if (ptr[7] == 'n')
80 align = SVG_PRESERVEASPECTRATIO_XMINYMIN; 81 align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
81 else if (ptr[7] == 'd') 82 else if (ptr[7] == 'd')
82 align = SVG_PRESERVEASPECTRATIO_XMINYMID; 83 align = SVG_PRESERVEASPECTRATIO_XMINYMID;
83 else 84 else
84 return false; 85 return SVGParsingError(SVGParseStatus::ExpectedEnumerati on, ptr - start);
85 } else if (ptr[6] == 'a' && ptr[7] == 'x') { 86 } else if (ptr[6] == 'a' && ptr[7] == 'x') {
86 align = SVG_PRESERVEASPECTRATIO_XMINYMAX; 87 align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
87 } else { 88 } else {
88 return false; 89 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start);
89 } 90 }
90 } else if (ptr[3] == 'd') { 91 } else if (ptr[3] == 'd') {
91 if (ptr[6] == 'i') { 92 if (ptr[6] == 'i') {
92 if (ptr[7] == 'n') 93 if (ptr[7] == 'n')
93 align = SVG_PRESERVEASPECTRATIO_XMIDYMIN; 94 align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
94 else if (ptr[7] == 'd') 95 else if (ptr[7] == 'd')
95 align = SVG_PRESERVEASPECTRATIO_XMIDYMID; 96 align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
96 else 97 else
97 return false; 98 return SVGParsingError(SVGParseStatus::ExpectedEnumerati on, ptr - start);
98 } else if (ptr[6] == 'a' && ptr[7] == 'x') { 99 } else if (ptr[6] == 'a' && ptr[7] == 'x') {
99 align = SVG_PRESERVEASPECTRATIO_XMIDYMAX; 100 align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
100 } else { 101 } else {
101 return false; 102 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start);
102 } 103 }
103 } else { 104 } else {
104 return false; 105 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start);
105 } 106 }
106 } else if (ptr[2] == 'a' && ptr[3] == 'x') { 107 } else if (ptr[2] == 'a' && ptr[3] == 'x') {
107 if (ptr[6] == 'i') { 108 if (ptr[6] == 'i') {
108 if (ptr[7] == 'n') 109 if (ptr[7] == 'n')
109 align = SVG_PRESERVEASPECTRATIO_XMAXYMIN; 110 align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
110 else if (ptr[7] == 'd') 111 else if (ptr[7] == 'd')
111 align = SVG_PRESERVEASPECTRATIO_XMAXYMID; 112 align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
112 else 113 else
113 return false; 114 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start);
114 } else if (ptr[6] == 'a' && ptr[7] == 'x') { 115 } else if (ptr[6] == 'a' && ptr[7] == 'x') {
115 align = SVG_PRESERVEASPECTRATIO_XMAXYMAX; 116 align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
116 } else { 117 } else {
117 return false; 118 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start);
118 } 119 }
119 } else { 120 } else {
120 return false; 121 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - st art);
121 } 122 }
122 ptr += 8; 123 ptr += 8;
123 skipOptionalSVGSpaces(ptr, end); 124 skipOptionalSVGSpaces(ptr, end);
124 } else { 125 } else {
125 return false; 126 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start) ;
126 } 127 }
127 128
128 if (ptr < end) { 129 if (ptr < end) {
129 if (*ptr == 'm') { 130 if (*ptr == 'm') {
130 if (!skipString(ptr, end, "meet")) 131 if (!skipString(ptr, end, "meet"))
131 return false; 132 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start);
132 skipOptionalSVGSpaces(ptr, end); 133 skipOptionalSVGSpaces(ptr, end);
133 } else if (*ptr == 's') { 134 } else if (*ptr == 's') {
134 if (!skipString(ptr, end, "slice")) 135 if (!skipString(ptr, end, "slice"))
135 return false; 136 return SVGParsingError(SVGParseStatus::ExpectedEnumeration, ptr - start);
136 skipOptionalSVGSpaces(ptr, end); 137 skipOptionalSVGSpaces(ptr, end);
137 if (align != SVG_PRESERVEASPECTRATIO_NONE) 138 if (align != SVG_PRESERVEASPECTRATIO_NONE)
138 meetOrSlice = SVG_MEETORSLICE_SLICE; 139 meetOrSlice = SVG_MEETORSLICE_SLICE;
139 } 140 }
140 } 141 }
141 142
142 if (end != ptr && validate) 143 if (end != ptr && validate)
143 return false; 144 return SVGParsingError(SVGParseStatus::TrailingGarbage, ptr - start);
144 145
145 setAlign(align); 146 setAlign(align);
146 setMeetOrSlice(meetOrSlice); 147 setMeetOrSlice(meetOrSlice);
147 148
148 return true; 149 return SVGParseStatus::NoError;
149 } 150 }
150 151
151 SVGParsingError SVGPreserveAspectRatio::setValueAsString(const String& string) 152 SVGParsingError SVGPreserveAspectRatio::setValueAsString(const String& string)
152 { 153 {
153 setDefault(); 154 setDefault();
154 155
155 if (string.isEmpty()) 156 if (string.isEmpty())
156 return NoError; 157 return SVGParseStatus::NoError;
157 158
158 bool valid = false;
159 if (string.is8Bit()) { 159 if (string.is8Bit()) {
160 const LChar* ptr = string.characters8(); 160 const LChar* ptr = string.characters8();
161 const LChar* end = ptr + string.length(); 161 const LChar* end = ptr + string.length();
162 valid = parseInternal(ptr, end, true); 162 return parseInternal(ptr, end, true);
163 } else {
164 const UChar* ptr = string.characters16();
165 const UChar* end = ptr + string.length();
166 valid = parseInternal(ptr, end, true);
167 } 163 }
168 return valid ? NoError : ParsingAttributeFailedError; 164 const UChar* ptr = string.characters16();
165 const UChar* end = ptr + string.length();
166 return parseInternal(ptr, end, true);
169 } 167 }
170 168
171 bool SVGPreserveAspectRatio::parse(const LChar*& ptr, const LChar* end, bool val idate) 169 bool SVGPreserveAspectRatio::parse(const LChar*& ptr, const LChar* end, bool val idate)
172 { 170 {
173 return parseInternal(ptr, end, validate); 171 return parseInternal(ptr, end, validate) == SVGParseStatus::NoError;
174 } 172 }
175 173
176 bool SVGPreserveAspectRatio::parse(const UChar*& ptr, const UChar* end, bool val idate) 174 bool SVGPreserveAspectRatio::parse(const UChar*& ptr, const UChar* end, bool val idate)
177 { 175 {
178 return parseInternal(ptr, end, validate); 176 return parseInternal(ptr, end, validate) == SVGParseStatus::NoError;
179 } 177 }
180 178
181 void SVGPreserveAspectRatio::transformRect(FloatRect& destRect, FloatRect& srcRe ct) 179 void SVGPreserveAspectRatio::transformRect(FloatRect& destRect, FloatRect& srcRe ct)
182 { 180 {
183 if (m_align == SVG_PRESERVEASPECTRATIO_NONE) 181 if (m_align == SVG_PRESERVEASPECTRATIO_NONE)
184 return; 182 return;
185 183
186 FloatSize imageSize = srcRect.size(); 184 FloatSize imageSize = srcRect.size();
187 float origDestWidth = destRect.width(); 185 float origDestWidth = destRect.width();
188 float origDestHeight = destRect.height(); 186 float origDestHeight = destRect.height();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 m_meetOrSlice = preserveAspectRatioToUse->m_meetOrSlice; 397 m_meetOrSlice = preserveAspectRatioToUse->m_meetOrSlice;
400 } 398 }
401 399
402 float SVGPreserveAspectRatio::calculateDistance(PassRefPtrWillBeRawPtr<SVGProper tyBase> toValue, SVGElement* contextElement) 400 float SVGPreserveAspectRatio::calculateDistance(PassRefPtrWillBeRawPtr<SVGProper tyBase> toValue, SVGElement* contextElement)
403 { 401 {
404 // No paced animations for SVGPreserveAspectRatio. 402 // No paced animations for SVGPreserveAspectRatio.
405 return -1; 403 return -1;
406 } 404 }
407 405
408 } 406 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGPreserveAspectRatio.h ('k') | third_party/WebKit/Source/core/svg/SVGRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698