Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGSVGElement.h
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 "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"
33
34 namespace WebCore {
35
36 class SVGAngle;
37 class SVGMatrix;
38 class SVGNumberTearOff;
39 class SVGTransform;
40 class SVGViewSpec;
41 class SVGViewElement;
42 class SMILTimeContainer;
43
44 class SVGSVGElement FINAL : public SVGGraphicsElement,
45                             public SVGFitToViewBox,
46                             public SVGZoomAndPan {
47 public:
48     static PassRefPtr<SVGSVGElement> create(Document&);
49
50     using SVGGraphicsElement::ref;
51     using SVGGraphicsElement::deref;
52
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     PassRefPtr<SVGRectTearOff> 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     FloatRect currentViewBoxRect() const;
82
83     float currentScale() const;
84     void setCurrentScale(float scale);
85
86     FloatPoint currentTranslate() { return m_translation->value(); }
87     void setCurrentTranslate(const FloatPoint&);
88     PassRefPtr<SVGPointTearOff> currentTranslateFromJavascript();
89
90     SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
91
92     void pauseAnimations();
93     void unpauseAnimations();
94     bool animationsPaused() const;
95
96     float getCurrentTime() const;
97     void setCurrentTime(float seconds);
98
99     unsigned suspendRedraw(unsigned maxWaitMilliseconds);
100     void unsuspendRedraw(unsigned suspendHandleId);
101     void unsuspendRedrawAll();
102     void forceRedraw();
103
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;
108     void deselectAll();
109
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&);
118
119     AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
120
121     void setupInitialView(const String& fragmentIdentifier, Element* anchorNode);
122
123     Element* getElementById(const AtomicString&) const;
124
125     bool widthAttributeEstablishesViewport() const;
126     bool heightAttributeEstablishesViewport() const;
127
128     SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; }
129     void setZoomAndPan(unsigned short zoomAndPan) { m_zoomAndPan = SVGZoomAndPan::parseFromNumber(zoomAndPan); }
130
131     bool hasEmptyViewBox() const { return m_viewBox->currentValue()->isValid() && m_viewBox->currentValue()->value().isEmpty(); }
132
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(); }
139
140 private:
141     explicit SVGSVGElement(Document&);
142     virtual ~SVGSVGElement();
143
144     virtual bool isSVGSVGElement() const OVERRIDE { return true; }
145
146     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
147
148     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
149     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
150
151     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
152     virtual void removedFrom(ContainerNode*) OVERRIDE;
153
154     virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
155
156     virtual bool selfHasRelativeLengths() const OVERRIDE;
157
158     void inheritViewAttributes(SVGViewElement*);
159
160     void updateCurrentTranslate();
161
162     enum CollectIntersectionOrEnclosure {
163         CollectIntersectionList,
164         CollectEnclosureList
165     };
166
167     PassRefPtr<NodeList> collectIntersectionOrEnclosureList(const FloatRect&, SVGElement*, CollectIntersectionOrEnclosure) const;
168
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
177
178     virtual AffineTransform localCoordinateSpaceTransform(SVGElement::CTMScope) const OVERRIDE;
179
180     bool m_useCurrentView;
181     SVGZoomAndPanType m_zoomAndPan;
182     RefPtr<SMILTimeContainer> m_timeContainer;
183     RefPtr<SVGPoint> m_translation;
184     RefPtr<SVGViewSpec> m_viewSpec;
185
186     friend class SVGCurrentTranslateTearOff;
187 };
188
189 inline bool isSVGSVGElement(const Node& node)
190 {
191     return node.isSVGElement() && toSVGElement(node).isSVGSVGElement();
192 }
193
194 DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(SVGSVGElement);
195
196 } // namespace WebCore
197
198 #endif