Upstream version 5.34.104.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/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"
31
32 namespace WebCore {
33
34 class SVGAngle;
35 class SVGMatrix;
36 class SVGNumberTearOff;
37 class SVGTransform;
38 class SVGViewSpec;
39 class SVGViewElement;
40 class SMILTimeContainer;
41
42 class SVGSVGElement FINAL : public SVGGraphicsElement,
43                             public SVGFitToViewBox,
44                             public SVGZoomAndPan {
45 public:
46     static PassRefPtr<SVGSVGElement> create(Document&);
47
48     using SVGGraphicsElement::ref;
49     using SVGGraphicsElement::deref;
50
51     virtual bool supportsFocus() const OVERRIDE { return hasFocusEventListeners(); }
52
53     // 'SVGSVGElement' functions
54     const AtomicString& contentScriptType() const;
55     void setContentScriptType(const AtomicString& type);
56
57     const AtomicString& contentStyleType() const;
58     void setContentStyleType(const AtomicString& type);
59
60     PassRefPtr<SVGRectTearOff> viewport() const;
61
62     float pixelUnitToMillimeterX() const;
63     float pixelUnitToMillimeterY() const;
64     float screenPixelToMillimeterX() const;
65     float screenPixelToMillimeterY() const;
66
67     bool useCurrentView() const { return m_useCurrentView; }
68     SVGViewSpec* currentView();
69
70     enum ConsiderCSSMode {
71         RespectCSSProperties,
72         IgnoreCSSProperties
73     };
74
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;
80
81     float currentScale() const;
82     void setCurrentScale(float scale);
83
84     FloatPoint currentTranslate() { return m_translation->value(); }
85     void setCurrentTranslate(const FloatPoint&);
86     PassRefPtr<SVGPointTearOff> currentTranslateFromJavascript();
87
88     SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
89
90     void pauseAnimations();
91     void unpauseAnimations();
92     bool animationsPaused() const;
93
94     float getCurrentTime() const;
95     void setCurrentTime(float seconds);
96
97     // Stubs for the deprecated 'redraw' interface.
98     unsigned suspendRedraw(unsigned) { return 1; }
99     void unsuspendRedraw(unsigned) { }
100     void unsuspendRedrawAll() { }
101     void forceRedraw() { }
102
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;
107     void deselectAll();
108
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&);
117
118     AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
119
120     void setupInitialView(const String& fragmentIdentifier, Element* anchorNode);
121
122     Element* getElementById(const AtomicString&) const;
123
124     bool widthAttributeEstablishesViewport() const;
125     bool heightAttributeEstablishesViewport() const;
126
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(); }
131
132 private:
133     explicit SVGSVGElement(Document&);
134     virtual ~SVGSVGElement();
135
136     virtual bool isSVGSVGElement() const OVERRIDE { return true; }
137
138     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
139
140     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
141     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
142
143     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
144     virtual void removedFrom(ContainerNode*) OVERRIDE;
145
146     virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
147
148     virtual bool selfHasRelativeLengths() const OVERRIDE;
149
150     void inheritViewAttributes(SVGViewElement*);
151
152     void updateCurrentTranslate();
153
154     enum CollectIntersectionOrEnclosure {
155         CollectIntersectionList,
156         CollectEnclosureList
157     };
158
159     PassRefPtr<NodeList> collectIntersectionOrEnclosureList(const FloatRect&, SVGElement*, CollectIntersectionOrEnclosure) const;
160
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
167
168     virtual AffineTransform localCoordinateSpaceTransform(SVGElement::CTMScope) const OVERRIDE;
169
170     bool m_useCurrentView;
171     RefPtr<SMILTimeContainer> m_timeContainer;
172     RefPtr<SVGPoint> m_translation;
173     RefPtr<SVGViewSpec> m_viewSpec;
174
175     friend class SVGCurrentTranslateTearOff;
176 };
177
178 inline bool isSVGSVGElement(const Node& node)
179 {
180     return node.isSVGElement() && toSVGElement(node).isSVGSVGElement();
181 }
182
183 DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(SVGSVGElement);
184
185 } // namespace WebCore
186
187 #endif