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/SVGFitToViewBox.h"
27 #include "core/svg/SVGGraphicsElement.h"
28 #include "core/svg/SVGLengthTearOff.h"
29 #include "core/svg/SVGPointTearOff.h"
30 #include "core/svg/SVGZoomAndPan.h"
36 class SVGNumberTearOff;
40 class SMILTimeContainer;
42 class SVGSVGElement FINAL : public SVGGraphicsElement,
43 public SVGFitToViewBox,
44 public SVGZoomAndPan {
46 static PassRefPtr<SVGSVGElement> create(Document&);
48 using SVGGraphicsElement::ref;
49 using SVGGraphicsElement::deref;
51 virtual bool supportsFocus() const OVERRIDE { return hasFocusEventListeners(); }
53 // 'SVGSVGElement' functions
54 const AtomicString& contentScriptType() const;
55 void setContentScriptType(const AtomicString& type);
57 const AtomicString& contentStyleType() const;
58 void setContentStyleType(const AtomicString& type);
60 PassRefPtr<SVGRectTearOff> viewport() const;
62 float pixelUnitToMillimeterX() const;
63 float pixelUnitToMillimeterY() const;
64 float screenPixelToMillimeterX() const;
65 float screenPixelToMillimeterY() const;
67 bool useCurrentView() const { return m_useCurrentView; }
68 SVGViewSpec* currentView();
70 enum ConsiderCSSMode {
75 // RenderSVGRoot wants to query the intrinsic size, by only examining the width/height attributes.
76 Length intrinsicWidth(ConsiderCSSMode = RespectCSSProperties) const;
77 Length intrinsicHeight(ConsiderCSSMode = RespectCSSProperties) const;
78 FloatSize currentViewportSize() const;
79 FloatRect currentViewBoxRect() const;
81 float currentScale() const;
82 void setCurrentScale(float scale);
84 FloatPoint currentTranslate() { return m_translation->value(); }
85 void setCurrentTranslate(const FloatPoint&);
86 PassRefPtr<SVGPointTearOff> currentTranslateFromJavascript();
88 SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
90 void pauseAnimations();
91 void unpauseAnimations();
92 bool animationsPaused() const;
94 float getCurrentTime() const;
95 void setCurrentTime(float seconds);
97 // Stubs for the deprecated 'redraw' interface.
98 unsigned suspendRedraw(unsigned) { return 1; }
99 void unsuspendRedraw(unsigned) { }
100 void unsuspendRedrawAll() { }
101 void forceRedraw() { }
103 PassRefPtr<NodeList> getIntersectionList(PassRefPtr<SVGRectTearOff>, SVGElement* referenceElement) const;
104 PassRefPtr<NodeList> getEnclosureList(PassRefPtr<SVGRectTearOff>, SVGElement* referenceElement) const;
105 bool checkIntersection(SVGElement*, PassRefPtr<SVGRectTearOff>) const;
106 bool checkEnclosure(SVGElement*, PassRefPtr<SVGRectTearOff>) const;
109 static PassRefPtr<SVGNumberTearOff> createSVGNumber();
110 static PassRefPtr<SVGLengthTearOff> createSVGLength();
111 static SVGAngle createSVGAngle();
112 static PassRefPtr<SVGPointTearOff> createSVGPoint();
113 static SVGMatrix createSVGMatrix();
114 static PassRefPtr<SVGRectTearOff> createSVGRect();
115 static SVGTransform createSVGTransform();
116 static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&);
118 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
120 void setupInitialView(const String& fragmentIdentifier, Element* anchorNode);
122 Element* getElementById(const AtomicString&) const;
124 bool widthAttributeEstablishesViewport() const;
125 bool heightAttributeEstablishesViewport() const;
127 SVGAnimatedLength* x() const { return m_x.get(); }
128 SVGAnimatedLength* y() const { return m_y.get(); }
129 SVGAnimatedLength* width() const { return m_width.get(); }
130 SVGAnimatedLength* height() const { return m_height.get(); }
133 explicit SVGSVGElement(Document&);
134 virtual ~SVGSVGElement();
136 virtual bool isSVGSVGElement() const OVERRIDE { return true; }
138 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
140 virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
141 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
143 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
144 virtual void removedFrom(ContainerNode*) OVERRIDE;
146 virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
148 virtual bool selfHasRelativeLengths() const OVERRIDE;
150 void inheritViewAttributes(SVGViewElement*);
152 void updateCurrentTranslate();
154 enum CollectIntersectionOrEnclosure {
155 CollectIntersectionList,
159 PassRefPtr<NodeList> collectIntersectionOrEnclosureList(const FloatRect&, SVGElement*, CollectIntersectionOrEnclosure) const;
161 RefPtr<SVGAnimatedLength> m_x;
162 RefPtr<SVGAnimatedLength> m_y;
163 RefPtr<SVGAnimatedLength> m_width;
164 RefPtr<SVGAnimatedLength> m_height;
165 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGSVGElement)
166 END_DECLARE_ANIMATED_PROPERTIES
168 virtual AffineTransform localCoordinateSpaceTransform(SVGElement::CTMScope) const OVERRIDE;
170 bool m_useCurrentView;
171 RefPtr<SMILTimeContainer> m_timeContainer;
172 RefPtr<SVGPoint> m_translation;
173 RefPtr<SVGViewSpec> m_viewSpec;
175 friend class SVGCurrentTranslateTearOff;
178 inline bool isSVGSVGElement(const Node& node)
180 return node.isSVGElement() && toSVGElement(node).isSVGSVGElement();
183 DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(SVGSVGElement);
185 } // namespace WebCore