| 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 "config.h" | 20 #include "config.h" |
| 21 #include "core/svg/SVGViewSpec.h" | 21 #include "core/svg/SVGViewSpec.h" |
| 22 | 22 |
| 23 #include "SVGNames.h" | 23 #include "SVGNames.h" |
| 24 #include "bindings/v8/ExceptionMessages.h" | |
| 25 #include "bindings/v8/ExceptionState.h" | |
| 26 #include "core/dom/Document.h" | 24 #include "core/dom/Document.h" |
| 27 #include "core/svg/SVGAnimatedTransformList.h" | 25 #include "core/svg/SVGAnimatedTransformList.h" |
| 28 #include "core/svg/SVGParserUtilities.h" | 26 #include "core/svg/SVGParserUtilities.h" |
| 29 | 27 |
| 30 namespace WebCore { | 28 namespace WebCore { |
| 31 | 29 |
| 32 // Define custom non-animated property 'transform'. | 30 // Define custom non-animated property 'transform'. |
| 33 const SVGPropertyInfo* SVGViewSpec::transformPropertyInfo() | 31 const SVGPropertyInfo* SVGViewSpec::transformPropertyInfo() |
| 34 { | 32 { |
| 35 static const SVGPropertyInfo* s_propertyInfo = 0; | 33 static const SVGPropertyInfo* s_propertyInfo = 0; |
| 36 if (!s_propertyInfo) { | 34 if (!s_propertyInfo) { |
| 37 s_propertyInfo = new SVGPropertyInfo(AnimatedTransformList, | 35 s_propertyInfo = new SVGPropertyInfo(AnimatedTransformList, |
| 38 PropertyIsReadOnly, | 36 PropertyIsReadOnly, |
| 39 SVGNames::transformAttr, | 37 SVGNames::transformAttr, |
| 40 transformIdentifier(), | 38 transformIdentifier(), |
| 41 0, | 39 0, |
| 42 0); | 40 0); |
| 43 } | 41 } |
| 44 return s_propertyInfo; | 42 return s_propertyInfo; |
| 45 } | 43 } |
| 46 | 44 |
| 47 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) | 45 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) |
| 48 : m_contextElement(contextElement) | 46 : m_contextElement(contextElement) |
| 49 , m_zoomAndPan(SVGZoomAndPanMagnify) | |
| 50 // Note: We make |viewBox| and |preserveAspectRatio|'s contextElement the ta
rget element of SVGViewSpec. | 47 // Note: We make |viewBox| and |preserveAspectRatio|'s contextElement the ta
rget element of SVGViewSpec. |
| 51 // This contextElement will be only used for keeping this alive from the tea
roff. | 48 // This contextElement will be only used for keeping this alive from the tea
roff. |
| 52 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali
ve as: | 49 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali
ve as: |
| 53 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV
GViewSpec. | 50 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV
GViewSpec. |
| 54 , m_viewBox(SVGAnimatedRect::create(contextElement, SVGNames::viewBoxAttr)) | 51 , m_viewBox(SVGAnimatedRect::create(contextElement, SVGNames::viewBoxAttr)) |
| 55 , m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(contextElemen
t, SVGNames::preserveAspectRatioAttr, SVGPreserveAspectRatio::create())) | 52 , m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(contextElemen
t, SVGNames::preserveAspectRatioAttr, SVGPreserveAspectRatio::create())) |
| 56 { | 53 { |
| 57 ASSERT(m_contextElement); | 54 ASSERT(m_contextElement); |
| 58 ScriptWrappable::init(this); | 55 ScriptWrappable::init(this); |
| 59 | 56 |
| 60 m_viewBox->setReadOnly(); | 57 m_viewBox->setReadOnly(); |
| 61 m_preserveAspectRatio->setReadOnly(); | 58 m_preserveAspectRatio->setReadOnly(); |
| 62 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to
an element. | 59 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to
an element. |
| 63 } | 60 } |
| 64 | 61 |
| 65 const AtomicString& SVGViewSpec::transformIdentifier() | 62 const AtomicString& SVGViewSpec::transformIdentifier() |
| 66 { | 63 { |
| 67 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecTransformAttrib
ute", AtomicString::ConstructFromLiteral)); | 64 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecTransformAttrib
ute", AtomicString::ConstructFromLiteral)); |
| 68 return s_identifier; | 65 return s_identifier; |
| 69 } | 66 } |
| 70 | 67 |
| 71 void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionState& exceptionState) | |
| 72 { | |
| 73 // SVGViewSpec and all of its content is read-only. | |
| 74 exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessag
es::readOnly()); | |
| 75 } | |
| 76 | |
| 77 String SVGViewSpec::preserveAspectRatioString() const | 68 String SVGViewSpec::preserveAspectRatioString() const |
| 78 { | 69 { |
| 79 return m_preserveAspectRatio->baseValue()->valueAsString(); | 70 return m_preserveAspectRatio->baseValue()->valueAsString(); |
| 80 } | 71 } |
| 81 | 72 |
| 82 void SVGViewSpec::setTransformString(const String& transform) | 73 void SVGViewSpec::setTransformString(const String& transform) |
| 83 { | 74 { |
| 84 if (!m_contextElement) | 75 if (!m_contextElement) |
| 85 return; | 76 return; |
| 86 | 77 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 121 |
| 131 void SVGViewSpec::detachContextElement() | 122 void SVGViewSpec::detachContextElement() |
| 132 { | 123 { |
| 133 m_viewBox = 0; | 124 m_viewBox = 0; |
| 134 m_preserveAspectRatio = 0; | 125 m_preserveAspectRatio = 0; |
| 135 m_contextElement = 0; | 126 m_contextElement = 0; |
| 136 } | 127 } |
| 137 | 128 |
| 138 void SVGViewSpec::reset() | 129 void SVGViewSpec::reset() |
| 139 { | 130 { |
| 140 m_zoomAndPan = SVGZoomAndPanMagnify; | 131 resetZoomAndPan(); |
| 141 m_transform.clear(); | 132 m_transform.clear(); |
| 142 ASSERT(m_viewBox); | 133 ASSERT(m_viewBox); |
| 143 m_viewBox->baseValue()->setValue(FloatRect()); | 134 m_viewBox->baseValue()->setValue(FloatRect()); |
| 144 ASSERT(m_preserveAspectRatio); | 135 ASSERT(m_preserveAspectRatio); |
| 145 m_preserveAspectRatio->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE
SERVEASPECTRATIO_XMIDYMID); | 136 m_preserveAspectRatio->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE
SERVEASPECTRATIO_XMIDYMID); |
| 146 m_preserveAspectRatio->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S
VG_MEETORSLICE_MEET); | 137 m_preserveAspectRatio->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S
VG_MEETORSLICE_MEET); |
| 147 m_viewTargetString = emptyString(); | 138 m_viewTargetString = emptyString(); |
| 148 } | 139 } |
| 149 | 140 |
| 150 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; | 141 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 setViewTargetString(String(viewTargetStart, ptr - viewTargetStar
t)); | 182 setViewTargetString(String(viewTargetStart, ptr - viewTargetStar
t)); |
| 192 ptr++; | 183 ptr++; |
| 193 } else | 184 } else |
| 194 return false; | 185 return false; |
| 195 } else if (*ptr == 'z') { | 186 } else if (*ptr == 'z') { |
| 196 if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPa
nSpec))) | 187 if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPa
nSpec))) |
| 197 return false; | 188 return false; |
| 198 if (ptr >= end || *ptr != '(') | 189 if (ptr >= end || *ptr != '(') |
| 199 return false; | 190 return false; |
| 200 ptr++; | 191 ptr++; |
| 201 if (!parseZoomAndPan(ptr, end, m_zoomAndPan)) | 192 if (!parseZoomAndPan(ptr, end)) |
| 202 return false; | 193 return false; |
| 203 if (ptr >= end || *ptr != ')') | 194 if (ptr >= end || *ptr != ')') |
| 204 return false; | 195 return false; |
| 205 ptr++; | 196 ptr++; |
| 206 } else if (*ptr == 'p') { | 197 } else if (*ptr == 'p') { |
| 207 if (!skipString(ptr, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(
preserveAspectRatioSpec))) | 198 if (!skipString(ptr, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(
preserveAspectRatioSpec))) |
| 208 return false; | 199 return false; |
| 209 if (ptr >= end || *ptr != '(') | 200 if (ptr >= end || *ptr != '(') |
| 210 return false; | 201 return false; |
| 211 ptr++; | 202 ptr++; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 const LChar* ptr = spec.characters8(); | 236 const LChar* ptr = spec.characters8(); |
| 246 const LChar* end = ptr + spec.length(); | 237 const LChar* end = ptr + spec.length(); |
| 247 return parseViewSpecInternal(ptr, end); | 238 return parseViewSpecInternal(ptr, end); |
| 248 } | 239 } |
| 249 const UChar* ptr = spec.characters16(); | 240 const UChar* ptr = spec.characters16(); |
| 250 const UChar* end = ptr + spec.length(); | 241 const UChar* end = ptr + spec.length(); |
| 251 return parseViewSpecInternal(ptr, end); | 242 return parseViewSpecInternal(ptr, end); |
| 252 } | 243 } |
| 253 | 244 |
| 254 } | 245 } |
| OLD | NEW |