| 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 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return m_transform->baseValue()->valueAsString(); | 125 return m_transform->baseValue()->valueAsString(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void SVGViewSpec::setZoomAndPan(unsigned short, | 128 void SVGViewSpec::setZoomAndPan(unsigned short, |
| 129 ExceptionState& exceptionState) { | 129 ExceptionState& exceptionState) { |
| 130 // SVGViewSpec and all of its content is read-only. | 130 // SVGViewSpec and all of its content is read-only. |
| 131 exceptionState.throwDOMException(NoModificationAllowedError, | 131 exceptionState.throwDOMException(NoModificationAllowedError, |
| 132 ExceptionMessages::readOnly()); | 132 ExceptionMessages::readOnly()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 namespace { |
| 136 |
| 137 enum ViewSpecFunctionType { |
| 138 Unknown, |
| 139 PreserveAspectRatio, |
| 140 Transform, |
| 141 ViewBox, |
| 142 ViewTarget, |
| 143 ZoomAndPan, |
| 144 }; |
| 145 |
| 146 template <typename CharType> |
| 147 static ViewSpecFunctionType scanViewSpecFunction(const CharType*& ptr, |
| 148 const CharType* end) { |
| 149 DCHECK_LT(ptr, end); |
| 150 switch (*ptr) { |
| 151 case 'v': |
| 152 if (skipToken(ptr, end, "viewBox")) |
| 153 return ViewBox; |
| 154 if (skipToken(ptr, end, "viewTarget")) |
| 155 return ViewTarget; |
| 156 break; |
| 157 case 'z': |
| 158 if (skipToken(ptr, end, "zoomAndPan")) |
| 159 return ZoomAndPan; |
| 160 break; |
| 161 case 'p': |
| 162 if (skipToken(ptr, end, "preserveAspectRatio")) |
| 163 return PreserveAspectRatio; |
| 164 break; |
| 165 case 't': |
| 166 if (skipToken(ptr, end, "transform")) |
| 167 return Transform; |
| 168 break; |
| 169 } |
| 170 return Unknown; |
| 171 } |
| 172 |
| 173 } // namespace |
| 174 |
| 135 template <typename CharType> | 175 template <typename CharType> |
| 136 bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr, | 176 bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr, |
| 137 const CharType* end) { | 177 const CharType* end) { |
| 138 if (!skipToken(ptr, end, "svgView")) | 178 if (!skipToken(ptr, end, "svgView")) |
| 139 return false; | 179 return false; |
| 140 | 180 |
| 141 if (ptr >= end || *ptr != '(') | 181 if (!skipExactly<CharType>(ptr, end, '(')) |
| 142 return false; | 182 return false; |
| 143 ptr++; | |
| 144 | 183 |
| 145 while (ptr < end && *ptr != ')') { | 184 while (ptr < end && *ptr != ')') { |
| 146 if (*ptr == 'v') { | 185 ViewSpecFunctionType functionType = scanViewSpecFunction(ptr, end); |
| 147 if (skipToken(ptr, end, "viewBox")) { | 186 if (functionType == Unknown) |
| 148 if (ptr >= end || *ptr != '(') | 187 return false; |
| 149 return false; | 188 |
| 150 ptr++; | 189 if (!skipExactly<CharType>(ptr, end, '(')) |
| 190 return false; |
| 191 |
| 192 switch (functionType) { |
| 193 case ViewBox: { |
| 151 float x = 0.0f; | 194 float x = 0.0f; |
| 152 float y = 0.0f; | 195 float y = 0.0f; |
| 153 float width = 0.0f; | 196 float width = 0.0f; |
| 154 float height = 0.0f; | 197 float height = 0.0f; |
| 155 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && | 198 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && |
| 156 parseNumber(ptr, end, width) && | 199 parseNumber(ptr, end, width) && |
| 157 parseNumber(ptr, end, height, DisallowWhitespace))) | 200 parseNumber(ptr, end, height, DisallowWhitespace))) |
| 158 return false; | 201 return false; |
| 159 updateViewBox(FloatRect(x, y, width, height)); | 202 updateViewBox(FloatRect(x, y, width, height)); |
| 160 if (ptr >= end || *ptr != ')') | 203 break; |
| 161 return false; | 204 } |
| 162 ptr++; | 205 case ViewTarget: { |
| 163 } else if (skipToken(ptr, end, "viewTarget")) { | 206 const CharType* viewTargetStart = ptr; |
| 164 if (ptr >= end || *ptr != '(') | 207 skipUntil<CharType>(ptr, end, ')'); |
| 165 return false; | 208 if (ptr == viewTargetStart) |
| 166 const CharType* viewTargetStart = ++ptr; | |
| 167 while (ptr < end && *ptr != ')') | |
| 168 ptr++; | |
| 169 if (ptr >= end) | |
| 170 return false; | 209 return false; |
| 171 m_viewTargetString = String(viewTargetStart, ptr - viewTargetStart); | 210 m_viewTargetString = String(viewTargetStart, ptr - viewTargetStart); |
| 172 ptr++; | 211 break; |
| 173 } else | 212 } |
| 174 return false; | 213 case ZoomAndPan: |
| 175 } else if (*ptr == 'z') { | 214 if (!parseZoomAndPan(ptr, end)) |
| 176 if (!skipToken(ptr, end, "zoomAndPan")) | 215 return false; |
| 177 return false; | 216 break; |
| 178 if (ptr >= end || *ptr != '(') | 217 case PreserveAspectRatio: |
| 179 return false; | 218 if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false)) |
| 180 ptr++; | 219 return false; |
| 181 if (!parseZoomAndPan(ptr, end)) | 220 break; |
| 182 return false; | 221 case Transform: |
| 183 if (ptr >= end || *ptr != ')') | 222 m_transform->baseValue()->parse(ptr, end); |
| 184 return false; | 223 break; |
| 185 ptr++; | 224 default: |
| 186 } else if (*ptr == 'p') { | 225 NOTREACHED(); |
| 187 if (!skipToken(ptr, end, "preserveAspectRatio")) | 226 break; |
| 188 return false; | 227 } |
| 189 if (ptr >= end || *ptr != '(') | 228 |
| 190 return false; | 229 if (!skipExactly<CharType>(ptr, end, ')')) |
| 191 ptr++; | |
| 192 if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false)) | |
| 193 return false; | |
| 194 if (ptr >= end || *ptr != ')') | |
| 195 return false; | |
| 196 ptr++; | |
| 197 } else if (*ptr == 't') { | |
| 198 if (!skipToken(ptr, end, "transform")) | |
| 199 return false; | |
| 200 if (ptr >= end || *ptr != '(') | |
| 201 return false; | |
| 202 ptr++; | |
| 203 m_transform->baseValue()->parse(ptr, end); | |
| 204 if (ptr >= end || *ptr != ')') | |
| 205 return false; | |
| 206 ptr++; | |
| 207 } else | |
| 208 return false; | 230 return false; |
| 209 | 231 |
| 210 if (ptr < end && *ptr == ';') | 232 skipExactly<CharType>(ptr, end, ';'); |
| 211 ptr++; | |
| 212 } | 233 } |
| 213 | 234 return skipExactly<CharType>(ptr, end, ')'); |
| 214 if (ptr >= end || *ptr != ')') | |
| 215 return false; | |
| 216 | |
| 217 return true; | |
| 218 } | 235 } |
| 219 | 236 |
| 220 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |