1 /* 2 * Copyright (C) 2007 Rob Buis <buis (at) kde.org> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 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 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef SVGViewSpec_h 21 #define SVGViewSpec_h 22 23 #include "bindings/v8/ScriptWrappable.h" 24 #include "core/svg/SVGAnimatedPreserveAspectRatio.h" 25 #include "core/svg/SVGAnimatedRect.h" 26 #include "core/svg/SVGFitToViewBox.h" 27 #include "core/svg/SVGTransformList.h" 28 #include "core/svg/SVGZoomAndPan.h" 29 30 namespace WebCore { 31 32 class ExceptionState; 33 class SVGElement; 34 class SVGTransformListPropertyTearOff; 35 36 class SVGViewSpec : public RefCounted<SVGViewSpec>, public ScriptWrappable, public SVGZoomAndPan, public SVGFitToViewBox { 37 public: 38 virtual ~SVGViewSpec() { } 39 40 using RefCounted<SVGViewSpec>::ref; 41 using RefCounted<SVGViewSpec>::deref; 42 43 static PassRefPtr<SVGViewSpec> create(SVGElement* contextElement) 44 { 45 return adoptRef(new SVGViewSpec(contextElement)); 46 } 47 48 bool parseViewSpec(const String&); 49 void reset(); 50 51 SVGElement* viewTarget() const; 52 String viewBoxString() const; 53 54 String preserveAspectRatioString() const; 55 56 void setTransformString(const String&); 57 String transformString() const; 58 59 void setViewTargetString(const String& string) { m_viewTargetString = string; } 60 String viewTargetString() const { return m_viewTargetString; } 61 62 SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; } 63 void setZoomAndPan(unsigned short zoomAndPan) { setZoomAndPanBaseValue(zoomAndPan); } 64 void setZoomAndPan(unsigned short, ExceptionState&); 65 void setZoomAndPanBaseValue(unsigned short zoomAndPan) { m_zoomAndPan = SVGZoomAndPan::parseFromNumber(zoomAndPan); } 66 67 SVGElement* contextElement() const { return m_contextElement; } 68 void resetContextElement() { m_contextElement = 0; } 69 70 // Custom non-animated 'transform' property. 71 SVGTransformListPropertyTearOff* transform(); 72 SVGTransformList transformBaseValue() const { return m_transform; } 73 74 // Custom animated 'viewBox' property. 75 PassRefPtr<SVGAnimatedRect> viewBox(); 76 FloatRect& viewBoxCurrentValue() { return m_viewBox; } 77 FloatRect viewBoxBaseValue() const { return m_viewBox; } 78 void setViewBoxBaseValue(const FloatRect& viewBox) { m_viewBox = viewBox; } 79 80 // Custom animated 'preserveAspectRatio' property. 81 PassRefPtr<SVGAnimatedPreserveAspectRatio> preserveAspectRatio(); 82 SVGPreserveAspectRatio& preserveAspectRatioCurrentValue() { return m_preserveAspectRatio; } 83 SVGPreserveAspectRatio preserveAspectRatioBaseValue() const { return m_preserveAspectRatio; } 84 void setPreserveAspectRatioBaseValue(const SVGPreserveAspectRatio& preserveAspectRatio) { m_preserveAspectRatio = preserveAspectRatio; } 85 86 private: 87 explicit SVGViewSpec(SVGElement*); 88 89 static const SVGPropertyInfo* transformPropertyInfo(); 90 static const SVGPropertyInfo* viewBoxPropertyInfo(); 91 static const SVGPropertyInfo* preserveAspectRatioPropertyInfo(); 92 93 static const AtomicString& transformIdentifier(); 94 static const AtomicString& viewBoxIdentifier(); 95 static const AtomicString& preserveAspectRatioIdentifier(); 96 97 static PassRefPtr<SVGAnimatedProperty> lookupOrCreateTransformWrapper(SVGViewSpec* contextElement); 98 static PassRefPtr<SVGAnimatedProperty> lookupOrCreateViewBoxWrapper(SVGViewSpec* contextElement); 99 static PassRefPtr<SVGAnimatedProperty> lookupOrCreatePreserveAspectRatioWrapper(SVGViewSpec* contextElement); 100 101 template<typename CharType> 102 bool parseViewSpecInternal(const CharType* ptr, const CharType* end); 103 104 SVGElement* m_contextElement; 105 SVGZoomAndPanType m_zoomAndPan; 106 107 SVGTransformList m_transform; 108 FloatRect m_viewBox; 109 SVGPreserveAspectRatio m_preserveAspectRatio; 110 String m_viewTargetString; 111 }; 112 113 } // namespace WebCore 114 115 #endif 116