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 | * Copyright (C) 2015-2019 Apple Inc. All rights reserved. |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include "FloatPoint.h" |
25 | #include "SVGExternalResourcesRequired.h" |
26 | #include "SVGFitToViewBox.h" |
27 | #include "SVGGraphicsElement.h" |
28 | #include "SVGZoomAndPan.h" |
29 | |
30 | namespace WebCore { |
31 | |
32 | class SMILTimeContainer; |
33 | class SVGAngle; |
34 | class SVGLength; |
35 | class SVGMatrix; |
36 | class SVGNumber; |
37 | class SVGRect; |
38 | class SVGTransform; |
39 | class SVGViewSpec; |
40 | |
41 | class SVGSVGElement final : public SVGGraphicsElement, public SVGExternalResourcesRequired, public SVGFitToViewBox, public SVGZoomAndPan { |
42 | WTF_MAKE_ISO_ALLOCATED(SVGSVGElement); |
43 | public: // DOM |
44 | const AtomicString& contentScriptType() const; |
45 | void setContentScriptType(const AtomicString&); |
46 | |
47 | const AtomicString& contentStyleType() const; |
48 | void setContentStyleType(const AtomicString&); |
49 | |
50 | Ref<SVGRect> viewport() const; |
51 | |
52 | float pixelUnitToMillimeterX() const; |
53 | float pixelUnitToMillimeterY() const; |
54 | float screenPixelToMillimeterX() const; |
55 | float screenPixelToMillimeterY() const; |
56 | |
57 | bool useCurrentView() const { return m_useCurrentView; } |
58 | SVGViewSpec& currentView(); |
59 | |
60 | float currentScale() const; |
61 | void setCurrentScale(float); |
62 | |
63 | SVGPoint& currentTranslate() { return m_currentTranslate; } |
64 | FloatPoint currentTranslateValue() const { return m_currentTranslate->value(); } |
65 | |
66 | unsigned suspendRedraw(unsigned maxWaitMilliseconds); |
67 | void unsuspendRedraw(unsigned suspendHandleId); |
68 | void unsuspendRedrawAll(); |
69 | void forceRedraw(); |
70 | |
71 | void pauseAnimations(); |
72 | void unpauseAnimations(); |
73 | bool animationsPaused() const; |
74 | bool hasActiveAnimation() const; |
75 | |
76 | float getCurrentTime() const; |
77 | void setCurrentTime(float); |
78 | |
79 | Ref<NodeList> getIntersectionList(SVGRect&, SVGElement* referenceElement); |
80 | Ref<NodeList> getEnclosureList(SVGRect&, SVGElement* referenceElement); |
81 | static bool checkIntersection(RefPtr<SVGElement>&&, SVGRect&); |
82 | static bool checkEnclosure(RefPtr<SVGElement>&&, SVGRect&); |
83 | void deselectAll(); |
84 | |
85 | static Ref<SVGNumber> createSVGNumber(); |
86 | static Ref<SVGLength> createSVGLength(); |
87 | static Ref<SVGAngle> createSVGAngle(); |
88 | static Ref<SVGPoint> createSVGPoint(); |
89 | static Ref<SVGMatrix> createSVGMatrix(); |
90 | static Ref<SVGRect> createSVGRect(); |
91 | static Ref<SVGTransform> createSVGTransform(); |
92 | static Ref<SVGTransform> createSVGTransformFromMatrix(SVGMatrix&); |
93 | |
94 | Element* getElementById(const AtomicString&); |
95 | |
96 | public: |
97 | static Ref<SVGSVGElement> create(const QualifiedName&, Document&); |
98 | static Ref<SVGSVGElement> create(Document&); |
99 | bool scrollToFragment(const String& fragmentIdentifier); |
100 | void resetScrollAnchor(); |
101 | |
102 | using SVGGraphicsElement::ref; |
103 | using SVGGraphicsElement::deref; |
104 | |
105 | SMILTimeContainer& timeContainer() { return m_timeContainer.get(); } |
106 | |
107 | void setCurrentTranslate(const FloatPoint&); // Used to pan. |
108 | void updateCurrentTranslate(); |
109 | |
110 | bool hasIntrinsicWidth() const; |
111 | bool hasIntrinsicHeight() const; |
112 | Length intrinsicWidth() const; |
113 | Length intrinsicHeight() const; |
114 | |
115 | FloatSize currentViewportSize() const; |
116 | FloatRect currentViewBoxRect() const; |
117 | |
118 | AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const; |
119 | |
120 | const SVGLengthValue& x() const { return m_x->currentValue(); } |
121 | const SVGLengthValue& y() const { return m_y->currentValue(); } |
122 | const SVGLengthValue& width() const { return m_width->currentValue(); } |
123 | const SVGLengthValue& height() const { return m_height->currentValue(); } |
124 | |
125 | SVGAnimatedLength& xAnimated() { return m_x; } |
126 | SVGAnimatedLength& yAnimated() { return m_y; } |
127 | SVGAnimatedLength& widthAnimated() { return m_width; } |
128 | SVGAnimatedLength& heightAnimated() { return m_height; } |
129 | |
130 | private: |
131 | SVGSVGElement(const QualifiedName&, Document&); |
132 | virtual ~SVGSVGElement(); |
133 | |
134 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGSVGElement, SVGGraphicsElement, SVGExternalResourcesRequired, SVGFitToViewBox>; |
135 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
136 | |
137 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
138 | void svgAttributeChanged(const QualifiedName&) override; |
139 | bool selfHasRelativeLengths() const override; |
140 | bool isValid() const override; |
141 | |
142 | bool rendererIsNeeded(const RenderStyle&) override; |
143 | RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override; |
144 | InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) override; |
145 | void removedFromAncestor(RemovalType, ContainerNode&) override; |
146 | void prepareForDocumentSuspension() override; |
147 | void resumeFromDocumentSuspension() override; |
148 | void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override; |
149 | |
150 | AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const override; |
151 | RefPtr<Frame> frameForCurrentScale() const; |
152 | void inheritViewAttributes(const SVGViewElement&); |
153 | Ref<NodeList> collectIntersectionOrEnclosureList(SVGRect&, SVGElement*, bool (*checkFunction)(SVGElement&, SVGRect&)); |
154 | |
155 | SVGViewElement* findViewAnchor(const String& fragmentIdentifier) const; |
156 | SVGSVGElement* findRootAnchor(const SVGViewElement*) const; |
157 | SVGSVGElement* findRootAnchor(const String&) const; |
158 | |
159 | bool m_useCurrentView { false }; |
160 | Ref<SMILTimeContainer> m_timeContainer; |
161 | RefPtr<SVGViewSpec> m_viewSpec; |
162 | String m_currentViewFragmentIdentifier; |
163 | |
164 | Ref<SVGPoint> m_currentTranslate { SVGPoint::create() }; |
165 | |
166 | PropertyRegistry m_propertyRegistry { *this }; |
167 | Ref<SVGAnimatedLength> m_x { SVGAnimatedLength::create(this, LengthModeWidth) }; |
168 | Ref<SVGAnimatedLength> m_y { SVGAnimatedLength::create(this, LengthModeHeight) }; |
169 | Ref<SVGAnimatedLength> m_width { SVGAnimatedLength::create(this, LengthModeWidth, "100%"_s ) }; |
170 | Ref<SVGAnimatedLength> m_height { SVGAnimatedLength::create(this, LengthModeHeight, "100%"_s ) }; |
171 | }; |
172 | |
173 | } // namespace WebCore |
174 | |