1/* 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@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 "SVGAnimatedBoolean.h" 25#include "SVGAnimatedLength.h" 26#include "SVGAnimatedPreserveAspectRatio.h" 27#include "SVGAnimatedRect.h" 28#include "SVGExternalResourcesRequired.h" 29#include "SVGFitToViewBox.h" 30#include "SVGGraphicsElement.h" 31#include "SVGZoomAndPan.h" 32 33namespace WebCore { 34 35class SVGAngle; 36class SVGMatrix; 37class SVGTransform; 38class SVGViewSpec; 39class SVGViewElement; 40class SMILTimeContainer; 41 42class SVGSVGElement final : public SVGGraphicsElement, 43 public SVGExternalResourcesRequired, 44 public SVGFitToViewBox, 45 public SVGZoomAndPan { 46public: 47 static PassRefPtr<SVGSVGElement> create(const QualifiedName&, Document&); 48 49 using SVGGraphicsElement::ref; 50 using SVGGraphicsElement::deref; 51 52 virtual bool isValid() const override { return SVGTests::isValid(); } 53 54 // 'SVGSVGElement' functions 55 const AtomicString& contentScriptType() const; 56 void setContentScriptType(const AtomicString& type); 57 58 const AtomicString& contentStyleType() const; 59 void setContentStyleType(const AtomicString& type); 60 61 FloatRect viewport() const; 62 63 float pixelUnitToMillimeterX() const; 64 float pixelUnitToMillimeterY() const; 65 float screenPixelToMillimeterX() const; 66 float screenPixelToMillimeterY() const; 67 68 bool useCurrentView() const { return m_useCurrentView; } 69 SVGViewSpec* currentView(); 70 71 // RenderSVGRoot wants to query the intrinsic size, by only examining the width/height attributes. 72 Length intrinsicWidth() const; 73 Length intrinsicHeight() const; 74 FloatSize currentViewportSize() const; 75 FloatRect currentViewBoxRect() const; 76 77 float currentScale() const; 78 void setCurrentScale(float scale); 79 80 SVGPoint& currentTranslate() { return m_translation; } 81 void setCurrentTranslate(const FloatPoint&); 82 83 // Only used from the bindings. 84 void updateCurrentTranslate(); 85 86 SMILTimeContainer* timeContainer() { return m_timeContainer.get(); } 87 88 void pauseAnimations(); 89 void unpauseAnimations(); 90 bool animationsPaused() const; 91 92 float getCurrentTime() const; 93 void setCurrentTime(float seconds); 94 95 unsigned suspendRedraw(unsigned maxWaitMilliseconds); 96 void unsuspendRedraw(unsigned suspendHandleId); 97 void unsuspendRedrawAll(); 98 void forceRedraw(); 99 100 PassRefPtr<NodeList> getIntersectionList(const FloatRect&, SVGElement* referenceElement) const; 101 PassRefPtr<NodeList> getEnclosureList(const FloatRect&, SVGElement* referenceElement) const; 102 bool checkIntersection(const SVGElement*, const FloatRect&) const; 103 bool checkEnclosure(const SVGElement*, const FloatRect&) const; 104 void deselectAll(); 105 106 static float createSVGNumber(); 107 static SVGLength createSVGLength(); 108 static SVGAngle createSVGAngle(); 109 static SVGPoint createSVGPoint(); 110 static SVGMatrix createSVGMatrix(); 111 static FloatRect createSVGRect(); 112 static SVGTransform createSVGTransform(); 113 static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&); 114 115 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const; 116 117 void setupInitialView(const String& fragmentIdentifier, Element* anchorNode); 118 119 bool hasIntrinsicWidth() const; 120 bool hasIntrinsicHeight() const; 121 122 Element* getElementById(const String&); 123 124 SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; } 125 void setZoomAndPan(unsigned short zoomAndPan) { m_zoomAndPan = SVGZoomAndPan::parseFromNumber(zoomAndPan); } 126 127 bool hasEmptyViewBox() const { return viewBoxIsValid() && viewBox().isEmpty(); } 128 129private: 130 SVGSVGElement(const QualifiedName&, Document&); 131 virtual ~SVGSVGElement(); 132 133 virtual void didMoveToNewDocument(Document* oldDocument) override; 134 135 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; 136 virtual bool isPresentationAttribute(const QualifiedName&) const override; 137 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override; 138 139 virtual bool rendererIsNeeded(const RenderStyle&) override; 140 virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override; 141 142 virtual InsertionNotificationRequest insertedInto(ContainerNode&) override; 143 virtual void removedFrom(ContainerNode&) override; 144 145 virtual void svgAttributeChanged(const QualifiedName&) override; 146 147 virtual bool selfHasRelativeLengths() const override; 148 149 void inheritViewAttributes(SVGViewElement*); 150 151 enum CollectIntersectionOrEnclosure { 152 CollectIntersectionList, 153 CollectEnclosureList 154 }; 155 156 PassRefPtr<NodeList> collectIntersectionOrEnclosureList(const FloatRect&, SVGElement*, CollectIntersectionOrEnclosure) const; 157 158 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGSVGElement) 159 DECLARE_ANIMATED_LENGTH(X, x) 160 DECLARE_ANIMATED_LENGTH(Y, y) 161 DECLARE_ANIMATED_LENGTH(Width, width) 162 DECLARE_ANIMATED_LENGTH(Height, height) 163 DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) 164 DECLARE_ANIMATED_RECT(ViewBox, viewBox) 165 DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio) 166 END_DECLARE_ANIMATED_PROPERTIES 167 168 virtual void documentWillSuspendForPageCache() override; 169 virtual void documentDidResumeFromPageCache() override; 170 171 virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const override; 172 173 bool m_useCurrentView; 174 SVGZoomAndPanType m_zoomAndPan; 175 RefPtr<SMILTimeContainer> m_timeContainer; 176 SVGPoint m_translation; 177 RefPtr<SVGViewSpec> m_viewSpec; 178}; 179 180NODE_TYPE_CASTS(SVGSVGElement) 181 182} // namespace WebCore 183 184#endif 185