2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org>
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.
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.
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.
21 #ifndef SVGSVGElement_h
22 #define SVGSVGElement_h
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/SVGFitToViewBox.h"
29 #include "core/svg/SVGGraphicsElement.h"
30 #include "core/svg/SVGLengthTearOff.h"
31 #include "core/svg/SVGPointTearOff.h"
32 #include "core/svg/SVGZoomAndPan.h"
38 class SVGNumberTearOff;
42 class SMILTimeContainer;
44 class SVGSVGElement FINAL : public SVGGraphicsElement,
45 public SVGFitToViewBox,
46 public SVGZoomAndPan {
48 static PassRefPtr<SVGSVGElement> create(Document&);
50 using SVGGraphicsElement::ref;
51 using SVGGraphicsElement::deref;
53 virtual bool supportsFocus() const OVERRIDE { return hasFocusEventListeners(); }
55 // 'SVGSVGElement' functions
56 const AtomicString& contentScriptType() const;
57 void setContentScriptType(const AtomicString& type);
59 const AtomicString& contentStyleType() const;
60 void setContentStyleType(const AtomicString& type);
62 PassRefPtr<SVGRectTearOff> viewport() const;
64 float pixelUnitToMillimeterX() const;
65 float pixelUnitToMillimeterY() const;
66 float screenPixelToMillimeterX() const;
67 float screenPixelToMillimeterY() const;
69 bool useCurrentView() const { return m_useCurrentView; }
70 SVGViewSpec* currentView();
72 enum ConsiderCSSMode {
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 FloatRect currentViewBoxRect() const;
83 float currentScale() const;
84 void setCurrentScale(float scale);
86 FloatPoint currentTranslate() { return m_translation->value(); }
87 void setCurrentTranslate(const FloatPoint&);
88 PassRefPtr<SVGPointTearOff> currentTranslateFromJavascript();
90 SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
92 void pauseAnimations();
93 void unpauseAnimations();
94 bool animationsPaused() const;
96 float getCurrentTime() const;
97 void setCurrentTime(float seconds);
99 unsigned suspendRedraw(unsigned maxWaitMilliseconds);
100 void unsuspendRedraw(unsigned suspendHandleId);
101 void unsuspendRedrawAll();
104 PassRefPtr<NodeList> getIntersectionList(PassRefPtr<SVGRectTearOff>, SVGElement* referenceElement) const;
105 PassRefPtr<NodeList> getEnclosureList(PassRefPtr<SVGRectTearOff>, SVGElement* referenceElement) const;
106 bool checkIntersection(SVGElement*, PassRefPtr<SVGRectTearOff>) const;
107 bool checkEnclosure(SVGElement*, PassRefPtr<SVGRectTearOff>) const;
110 static PassRefPtr<SVGNumberTearOff> createSVGNumber();
111 static PassRefPtr<SVGLengthTearOff> createSVGLength();
112 static SVGAngle createSVGAngle();
113 static PassRefPtr<SVGPointTearOff> createSVGPoint();
114 static SVGMatrix createSVGMatrix();
115 static PassRefPtr<SVGRectTearOff> createSVGRect();
116 static SVGTransform createSVGTransform();
117 static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&);
119 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
121 void setupInitialView(const String& fragmentIdentifier, Element* anchorNode);
123 Element* getElementById(const AtomicString&) const;
125 bool widthAttributeEstablishesViewport() const;
126 bool heightAttributeEstablishesViewport() const;
128 SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; }
129 void setZoomAndPan(unsigned short zoomAndPan) { m_zoomAndPan = SVGZoomAndPan::parseFromNumber(zoomAndPan); }
131 bool hasEmptyViewBox() const { return m_viewBox->currentValue()->isValid() && m_viewBox->currentValue()->value().isEmpty(); }
133 SVGAnimatedLength* x() const { return m_x.get(); }
134 SVGAnimatedLength* y() const { return m_y.get(); }
135 SVGAnimatedLength* width() const { return m_width.get(); }
136 SVGAnimatedLength* height() const { return m_height.get(); }
137 SVGAnimatedRect* viewBox() const { return m_viewBox.get(); }
138 SVGAnimatedPreserveAspectRatio* preserveAspectRatio() { return m_preserveAspectRatio.get(); }
141 explicit SVGSVGElement(Document&);
142 virtual ~SVGSVGElement();
144 virtual bool isSVGSVGElement() const OVERRIDE { return true; }
146 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
148 virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
149 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
151 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
152 virtual void removedFrom(ContainerNode*) OVERRIDE;
154 virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
156 virtual bool selfHasRelativeLengths() const OVERRIDE;
158 void inheritViewAttributes(SVGViewElement*);
160 void updateCurrentTranslate();
162 enum CollectIntersectionOrEnclosure {
163 CollectIntersectionList,
167 PassRefPtr<NodeList> collectIntersectionOrEnclosureList(const FloatRect&, SVGElement*, CollectIntersectionOrEnclosure) const;
169 RefPtr<SVGAnimatedLength> m_x;
170 RefPtr<SVGAnimatedLength> m_y;
171 RefPtr<SVGAnimatedLength> m_width;
172 RefPtr<SVGAnimatedLength> m_height;
173 RefPtr<SVGAnimatedRect> m_viewBox;
174 RefPtr<SVGAnimatedPreserveAspectRatio> m_preserveAspectRatio;
175 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGSVGElement)
176 END_DECLARE_ANIMATED_PROPERTIES
178 virtual AffineTransform localCoordinateSpaceTransform(SVGElement::CTMScope) const OVERRIDE;
180 bool m_useCurrentView;
181 SVGZoomAndPanType m_zoomAndPan;
182 RefPtr<SMILTimeContainer> m_timeContainer;
183 RefPtr<SVGPoint> m_translation;
184 RefPtr<SVGViewSpec> m_viewSpec;
186 friend class SVGCurrentTranslateTearOff;
189 inline bool isSVGSVGElement(const Node& node)
191 return node.isSVGElement() && toSVGElement(node).isSVGSVGElement();
194 DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(SVGSVGElement);
196 } // namespace WebCore