1 /* 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis (at) kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef SVGSVGElement_h 22 #define SVGSVGElement_h 23 24 #include "core/svg/SVGAnimatedBoolean.h" 25 #include "core/svg/SVGAnimatedLength.h" 26 #include "core/svg/SVGAnimatedPreserveAspectRatio.h" 27 #include "core/svg/SVGAnimatedRect.h" 28 #include "core/svg/SVGExternalResourcesRequired.h" 29 #include "core/svg/SVGFitToViewBox.h" 30 #include "core/svg/SVGGraphicsElement.h" 31 #include "core/svg/SVGZoomAndPan.h" 32 33 namespace WebCore { 34 35 class SVGAngle; 36 class SVGMatrix; 37 class SVGTransform; 38 class SVGViewSpec; 39 class SVGViewElement; 40 class SMILTimeContainer; 41 42 class SVGSVGElement FINAL : public SVGGraphicsElement, 43 public SVGExternalResourcesRequired, 44 public SVGFitToViewBox, 45 public SVGZoomAndPan { 46 public: 47 static PassRefPtr<SVGSVGElement> create(const QualifiedName&, Document*); 48 49 using SVGGraphicsElement::ref; 50 using SVGGraphicsElement::deref; 51 52 virtual bool isValid() const { return SVGTests::isValid(); } 53 virtual bool supportsFocus() const OVERRIDE { return hasFocusEventListeners(); } 54 55 // 'SVGSVGElement' functions 56 const AtomicString& contentScriptType() const; 57 void setContentScriptType(const AtomicString& type); 58 59 const AtomicString& contentStyleType() const; 60 void setContentStyleType(const AtomicString& type); 61 62 SVGRect viewport() const; 63 64 float pixelUnitToMillimeterX() const; 65 float pixelUnitToMillimeterY() const; 66 float screenPixelToMillimeterX() const; 67 float screenPixelToMillimeterY() const; 68 69 bool useCurrentView() const { return m_useCurrentView; } 70 SVGViewSpec* currentView(); 71 72 enum ConsiderCSSMode { 73 RespectCSSProperties, 74 IgnoreCSSProperties 75 }; 76 77 // RenderSVGRoot wants to query the intrinsic size, by only examining the width/height attributes. 78 Length intrinsicWidth(ConsiderCSSMode = RespectCSSProperties) const; 79 Length intrinsicHeight(ConsiderCSSMode = RespectCSSProperties) const; 80 FloatSize currentViewportSize() const; 81 SVGRect currentViewBoxRect() const; 82 83 float currentScale() const; 84 void setCurrentScale(float scale); 85 86 SVGPoint& currentTranslate() { return m_translation; } 87 void setCurrentTranslate(const FloatPoint&); 88 89 // Only used from the bindings. 90 void updateCurrentTranslate(); 91 92 SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); } 93 94 void pauseAnimations(); 95 void unpauseAnimations(); 96 bool animationsPaused() const; 97 98 float getCurrentTime() const; 99 void setCurrentTime(float seconds); 100 101 unsigned suspendRedraw(unsigned maxWaitMilliseconds); 102 void unsuspendRedraw(unsigned suspendHandleId); 103 void unsuspendRedrawAll(); 104 void forceRedraw(); 105 106 PassRefPtr<NodeList> getIntersectionList(const SVGRect&, SVGElement* referenceElement) const; 107 PassRefPtr<NodeList> getEnclosureList(const SVGRect&, SVGElement* referenceElement) const; 108 bool checkIntersection(SVGElement*, const SVGRect&) const; 109 bool checkEnclosure(SVGElement*, const SVGRect&) const; 110 void deselectAll(); 111 112 static float createSVGNumber(); 113 static SVGLength createSVGLength(); 114 static SVGAngle createSVGAngle(); 115 static SVGPoint createSVGPoint(); 116 static SVGMatrix createSVGMatrix(); 117 static SVGRect createSVGRect(); 118 static SVGTransform createSVGTransform(); 119 static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&); 120 121 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const; 122 123 void setupInitialView(const String& fragmentIdentifier, Element* anchorNode); 124 125 Element* getElementById(const AtomicString&) const; 126 127 bool widthAttributeEstablishesViewport() const; 128 bool heightAttributeEstablishesViewport() const; 129 130 SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; } 131 void setZoomAndPan(unsigned short zoomAndPan) { m_zoomAndPan = SVGZoomAndPan::parseFromNumber(zoomAndPan); } 132 133 bool hasEmptyViewBox() const { return viewBoxIsValid() && viewBoxCurrentValue().isEmpty(); } 134 135 private: 136 SVGSVGElement(const QualifiedName&, Document*); 137 virtual ~SVGSVGElement(); 138 139 virtual bool isSVGSVGElement() const OVERRIDE { return true; } 140 141 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 142 143 virtual bool rendererIsNeeded(const NodeRenderingContext&) OVERRIDE; 144 virtual RenderObject* createRenderer(RenderStyle*); 145 146 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; 147 virtual void removedFrom(ContainerNode*) OVERRIDE; 148 149 virtual void svgAttributeChanged(const QualifiedName&); 150 151 virtual bool selfHasRelativeLengths() const; 152 153 void inheritViewAttributes(SVGViewElement*); 154 155 enum CollectIntersectionOrEnclosure { 156 CollectIntersectionList, 157 CollectEnclosureList 158 }; 159 160 PassRefPtr<NodeList> collectIntersectionOrEnclosureList(const SVGRect&, SVGElement*, CollectIntersectionOrEnclosure) const; 161 162 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGSVGElement) 163 DECLARE_ANIMATED_LENGTH(X, x) 164 DECLARE_ANIMATED_LENGTH(Y, y) 165 DECLARE_ANIMATED_LENGTH(Width, width) 166 DECLARE_ANIMATED_LENGTH(Height, height) 167 DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) 168 DECLARE_ANIMATED_RECT(ViewBox, viewBox) 169 DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) 170 END_DECLARE_ANIMATED_PROPERTIES 171 172 virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const; 173 174 bool m_useCurrentView; 175 SVGZoomAndPanType m_zoomAndPan; 176 RefPtr<SMILTimeContainer> m_timeContainer; 177 SVGPoint m_translation; 178 RefPtr<SVGViewSpec> m_viewSpec; 179 }; 180 181 inline SVGSVGElement* toSVGSVGElement(Node* node) 182 { 183 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isSVGElement()); 184 ASSERT_WITH_SECURITY_IMPLICATION(!node || toSVGElement(node)->isSVGSVGElement()); 185 return static_cast<SVGSVGElement*>(node); 186 } 187 188 } // namespace WebCore 189 190 #endif 191