OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org> | 2 * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org> |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "core/svg/SVGViewSpec.h" | 20 #include "core/svg/SVGViewSpec.h" |
21 | 21 |
22 #include "bindings/core/v8/ExceptionMessages.h" | 22 #include "bindings/core/v8/ExceptionMessages.h" |
23 #include "bindings/core/v8/ExceptionState.h" | 23 #include "bindings/core/v8/ExceptionState.h" |
24 #include "core/SVGNames.h" | 24 #include "core/SVGNames.h" |
25 #include "core/dom/ExceptionCode.h" | 25 #include "core/dom/ExceptionCode.h" |
26 #include "core/svg/SVGAnimatedTransformList.h" | 26 #include "core/svg/SVGAnimatedTransformList.h" |
27 #include "core/svg/SVGParserUtilities.h" | 27 #include "core/svg/SVGParserUtilities.h" |
28 #include "platform/ParsingUtilities.h" | 28 #include "platform/text/ParserUtilities.h" |
29 | 29 |
30 namespace blink { | 30 namespace blink { |
31 | 31 |
32 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) | 32 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) |
33 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to
an element. | 33 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to
an element. |
34 // Note: We make tear-offs' contextElement the target element of SVGViewSpec
. | 34 // Note: We make tear-offs' contextElement the target element of SVGViewSpec
. |
35 // This contextElement will be only used for keeping this alive from the tea
roff. | 35 // This contextElement will be only used for keeping this alive from the tea
roff. |
36 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali
ve as: | 36 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali
ve as: |
37 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV
GViewSpec. | 37 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV
GViewSpec. |
38 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip) | 38 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 return m_transform->baseValue()->valueAsString(); | 126 return m_transform->baseValue()->valueAsString(); |
127 } | 127 } |
128 | 128 |
129 void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionState& exceptionState) | 129 void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionState& exceptionState) |
130 { | 130 { |
131 // SVGViewSpec and all of its content is read-only. | 131 // SVGViewSpec and all of its content is read-only. |
132 exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessag
es::readOnly()); | 132 exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessag
es::readOnly()); |
133 } | 133 } |
134 | 134 |
| 135 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; |
| 136 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'}; |
| 137 static const LChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v
', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'}; |
| 138 static const LChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm
'}; |
| 139 static const LChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', '
a', 'n'}; |
| 140 static const LChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g',
'e', 't'}; |
| 141 |
135 template<typename CharType> | 142 template<typename CharType> |
136 bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr, const CharType* end
) | 143 bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr, const CharType* end
) |
137 { | 144 { |
138 if (!skipToken(ptr, end, "svgView")) | 145 if (!skipString(ptr, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec))) |
139 return false; | 146 return false; |
140 | 147 |
141 if (ptr >= end || *ptr != '(') | 148 if (ptr >= end || *ptr != '(') |
142 return false; | 149 return false; |
143 ptr++; | 150 ptr++; |
144 | 151 |
145 while (ptr < end && *ptr != ')') { | 152 while (ptr < end && *ptr != ')') { |
146 if (*ptr == 'v') { | 153 if (*ptr == 'v') { |
147 if (skipToken(ptr, end, "viewBox")) { | 154 if (skipString(ptr, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))
) { |
148 if (ptr >= end || *ptr != '(') | 155 if (ptr >= end || *ptr != '(') |
149 return false; | 156 return false; |
150 ptr++; | 157 ptr++; |
151 float x = 0.0f; | 158 float x = 0.0f; |
152 float y = 0.0f; | 159 float y = 0.0f; |
153 float width = 0.0f; | 160 float width = 0.0f; |
154 float height = 0.0f; | 161 float height = 0.0f; |
155 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && pa
rseNumber(ptr, end, width) && parseNumber(ptr, end, height, DisallowWhitespace))
) | 162 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && pa
rseNumber(ptr, end, width) && parseNumber(ptr, end, height, DisallowWhitespace))
) |
156 return false; | 163 return false; |
157 updateViewBox(FloatRect(x, y, width, height)); | 164 updateViewBox(FloatRect(x, y, width, height)); |
158 if (ptr >= end || *ptr != ')') | 165 if (ptr >= end || *ptr != ')') |
159 return false; | 166 return false; |
160 ptr++; | 167 ptr++; |
161 } else if (skipToken(ptr, end, "viewTarget")) { | 168 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie
wTargetSpec))) { |
162 if (ptr >= end || *ptr != '(') | 169 if (ptr >= end || *ptr != '(') |
163 return false; | 170 return false; |
164 const CharType* viewTargetStart = ++ptr; | 171 const CharType* viewTargetStart = ++ptr; |
165 while (ptr < end && *ptr != ')') | 172 while (ptr < end && *ptr != ')') |
166 ptr++; | 173 ptr++; |
167 if (ptr >= end) | 174 if (ptr >= end) |
168 return false; | 175 return false; |
169 m_viewTargetString = String(viewTargetStart, ptr - viewTargetSta
rt); | 176 m_viewTargetString = String(viewTargetStart, ptr - viewTargetSta
rt); |
170 ptr++; | 177 ptr++; |
171 } else | 178 } else |
172 return false; | 179 return false; |
173 } else if (*ptr == 'z') { | 180 } else if (*ptr == 'z') { |
174 if (!skipToken(ptr, end, "zoomAndPan")) | 181 if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPa
nSpec))) |
175 return false; | 182 return false; |
176 if (ptr >= end || *ptr != '(') | 183 if (ptr >= end || *ptr != '(') |
177 return false; | 184 return false; |
178 ptr++; | 185 ptr++; |
179 if (!parseZoomAndPan(ptr, end)) | 186 if (!parseZoomAndPan(ptr, end)) |
180 return false; | 187 return false; |
181 if (ptr >= end || *ptr != ')') | 188 if (ptr >= end || *ptr != ')') |
182 return false; | 189 return false; |
183 ptr++; | 190 ptr++; |
184 } else if (*ptr == 'p') { | 191 } else if (*ptr == 'p') { |
185 if (!skipToken(ptr, end, "preserveAspectRatio")) | 192 if (!skipString(ptr, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(
preserveAspectRatioSpec))) |
186 return false; | 193 return false; |
187 if (ptr >= end || *ptr != '(') | 194 if (ptr >= end || *ptr != '(') |
188 return false; | 195 return false; |
189 ptr++; | 196 ptr++; |
190 if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false)) | 197 if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false)) |
191 return false; | 198 return false; |
192 if (ptr >= end || *ptr != ')') | 199 if (ptr >= end || *ptr != ')') |
193 return false; | 200 return false; |
194 ptr++; | 201 ptr++; |
195 } else if (*ptr == 't') { | 202 } else if (*ptr == 't') { |
196 if (!skipToken(ptr, end, "transform")) | 203 if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformS
pec))) |
197 return false; | 204 return false; |
198 if (ptr >= end || *ptr != '(') | 205 if (ptr >= end || *ptr != '(') |
199 return false; | 206 return false; |
200 ptr++; | 207 ptr++; |
201 m_transform->baseValue()->parse(ptr, end); | 208 m_transform->baseValue()->parse(ptr, end); |
202 if (ptr >= end || *ptr != ')') | 209 if (ptr >= end || *ptr != ')') |
203 return false; | 210 return false; |
204 ptr++; | 211 ptr++; |
205 } else | 212 } else |
206 return false; | 213 return false; |
207 | 214 |
208 if (ptr < end && *ptr == ';') | 215 if (ptr < end && *ptr == ';') |
209 ptr++; | 216 ptr++; |
210 } | 217 } |
211 | 218 |
212 if (ptr >= end || *ptr != ')') | 219 if (ptr >= end || *ptr != ')') |
213 return false; | 220 return false; |
214 | 221 |
215 return true; | 222 return true; |
216 } | 223 } |
217 | 224 |
218 } // namespace blink | 225 } // namespace blink |
OLD | NEW |