/work/obj-fuzz/dist/include/mozilla/dom/SVGSVGElement.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_SVGSVGElement_h |
8 | | #define mozilla_dom_SVGSVGElement_h |
9 | | |
10 | | #include "SVGViewportElement.h" |
11 | | |
12 | | nsresult NS_NewSVGSVGElement(nsIContent **aResult, |
13 | | already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
14 | | mozilla::dom::FromParser aFromParser); |
15 | | |
16 | | class nsSMILTimeContainer; |
17 | | |
18 | | namespace mozilla { |
19 | | class AutoSVGViewHandler; |
20 | | class SVGFragmentIdentifier; |
21 | | class EventChainPreVisitor; |
22 | | class DOMSVGLength; |
23 | | class DOMSVGNumber; |
24 | | |
25 | | namespace dom { |
26 | | class SVGAngle; |
27 | | class SVGMatrix; |
28 | | class SVGIRect; |
29 | | class SVGSVGElement; |
30 | | |
31 | | // Stores svgView arguments of SVG fragment identifiers. |
32 | | class SVGView { |
33 | | public: |
34 | | SVGView(); |
35 | | |
36 | | nsSVGEnum mZoomAndPan; |
37 | | nsSVGViewBox mViewBox; |
38 | | SVGAnimatedPreserveAspectRatio mPreserveAspectRatio; |
39 | | nsAutoPtr<nsSVGAnimatedTransformList> mTransforms; |
40 | | }; |
41 | | |
42 | | class DOMSVGTranslatePoint final : public nsISVGPoint { |
43 | | public: |
44 | | DOMSVGTranslatePoint(SVGPoint* aPt, SVGSVGElement* aElement) |
45 | 0 | : nsISVGPoint(aPt, true), mElement(aElement) {} |
46 | | |
47 | | explicit DOMSVGTranslatePoint(DOMSVGTranslatePoint* aPt) |
48 | 0 | : nsISVGPoint(&aPt->mPt, true), mElement(aPt->mElement) {} |
49 | | |
50 | | NS_DECL_ISUPPORTS_INHERITED |
51 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMSVGTranslatePoint, nsISVGPoint) |
52 | | |
53 | | virtual DOMSVGPoint* Copy() override; |
54 | | |
55 | | // WebIDL |
56 | 0 | virtual float X() override { return mPt.GetX(); } |
57 | 0 | virtual float Y() override { return mPt.GetY(); } |
58 | | virtual void SetX(float aValue, ErrorResult& rv) override; |
59 | | virtual void SetY(float aValue, ErrorResult& rv) override; |
60 | | virtual already_AddRefed<nsISVGPoint> MatrixTransform(SVGMatrix& matrix) override; |
61 | | |
62 | | virtual nsISupports* GetParentObject() override; |
63 | | |
64 | | RefPtr<SVGSVGElement> mElement; |
65 | | |
66 | | private: |
67 | 0 | ~DOMSVGTranslatePoint() {} |
68 | | }; |
69 | | |
70 | | typedef SVGViewportElement SVGSVGElementBase; |
71 | | |
72 | | class SVGSVGElement final : public SVGSVGElementBase |
73 | | { |
74 | | friend class ::nsSVGOuterSVGFrame; |
75 | | friend class mozilla::SVGFragmentIdentifier; |
76 | | friend class mozilla::AutoSVGViewHandler; |
77 | | friend class mozilla::AutoPreserveAspectRatioOverride; |
78 | | friend class mozilla::dom::SVGView; |
79 | | |
80 | | protected: |
81 | | SVGSVGElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
82 | | FromParser aFromParser); |
83 | | virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override; |
84 | | |
85 | | friend nsresult (::NS_NewSVGSVGElement(nsIContent **aResult, |
86 | | already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
87 | | mozilla::dom::FromParser aFromParser)); |
88 | | |
89 | | ~SVGSVGElement(); |
90 | | |
91 | | public: |
92 | | // interfaces: |
93 | | NS_DECL_ISUPPORTS_INHERITED |
94 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGSVGElement, SVGSVGElementBase) |
95 | | |
96 | | /** |
97 | | * For use by zoom controls to allow currentScale, currentTranslate.x and |
98 | | * currentTranslate.y to be set by a single operation that dispatches a |
99 | | * single SVGZoom event (instead of one SVGZoom and two SVGScroll events). |
100 | | * |
101 | | * XXX SVGZoomEvent is no more, is this needed? |
102 | | */ |
103 | | void SetCurrentScaleTranslate(float s, float x, float y); |
104 | | |
105 | | // nsIContent interface |
106 | | void GetEventTargetParent(EventChainPreVisitor& aVisitor) override; |
107 | | virtual bool IsEventAttributeNameInternal(nsAtom* aName) override; |
108 | | |
109 | | // nsINode methods: |
110 | | virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; |
111 | | |
112 | | // WebIDL |
113 | | already_AddRefed<SVGAnimatedLength> X(); |
114 | | already_AddRefed<SVGAnimatedLength> Y(); |
115 | | already_AddRefed<SVGAnimatedLength> Width(); |
116 | | already_AddRefed<SVGAnimatedLength> Height(); |
117 | | bool UseCurrentView(); |
118 | | float CurrentScale(); |
119 | | void SetCurrentScale(float aCurrentScale); |
120 | | already_AddRefed<nsISVGPoint> CurrentTranslate(); |
121 | | void SetCurrentTranslate(float x, float y); |
122 | | uint32_t SuspendRedraw(uint32_t max_wait_milliseconds); |
123 | | void UnsuspendRedraw(uint32_t suspend_handle_id); |
124 | | void UnsuspendRedrawAll(); |
125 | | void ForceRedraw(); |
126 | | void PauseAnimations(); |
127 | | void UnpauseAnimations(); |
128 | | bool AnimationsPaused(); |
129 | | float GetCurrentTime(); |
130 | | void SetCurrentTime(float seconds); |
131 | | void DeselectAll(); |
132 | | already_AddRefed<DOMSVGNumber> CreateSVGNumber(); |
133 | | already_AddRefed<DOMSVGLength> CreateSVGLength(); |
134 | | already_AddRefed<SVGAngle> CreateSVGAngle(); |
135 | | already_AddRefed<nsISVGPoint> CreateSVGPoint(); |
136 | | already_AddRefed<SVGMatrix> CreateSVGMatrix(); |
137 | | already_AddRefed<SVGIRect> CreateSVGRect(); |
138 | | already_AddRefed<SVGTransform> CreateSVGTransform(); |
139 | | already_AddRefed<SVGTransform> CreateSVGTransformFromMatrix(SVGMatrix& matrix); |
140 | | using nsINode::GetElementById; // This does what we want |
141 | | uint16_t ZoomAndPan(); |
142 | | void SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv); |
143 | | |
144 | | // nsSVGElement overrides |
145 | | |
146 | | virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, |
147 | | nsIContent* aBindingParent) override; |
148 | | virtual void UnbindFromTree(bool aDeep, bool aNullParent) override; |
149 | | virtual nsSVGAnimatedTransformList* |
150 | | GetAnimatedTransformList(uint32_t aFlags = 0) override; |
151 | | |
152 | | // SVGSVGElement methods: |
153 | | |
154 | | // Returns true IFF our attributes are currently overridden by a <view> |
155 | | // element and that element's ID matches the passed-in string. |
156 | 0 | bool IsOverriddenBy(const nsAString &aViewID) const { |
157 | 0 | return mCurrentViewID && mCurrentViewID->Equals(aViewID); |
158 | 0 | } |
159 | | |
160 | | nsSMILTimeContainer* GetTimedDocumentRoot(); |
161 | | |
162 | | // public helpers: |
163 | | |
164 | | /** |
165 | | * Returns -1 if the width/height is a percentage, else returns the user unit |
166 | | * length clamped to fit in a int32_t. |
167 | | * XXX see bug 1112533 comment 3 - we should fix drawImage so that we can |
168 | | * change these methods to make zero the error flag for percentages. |
169 | | */ |
170 | | int32_t GetIntrinsicWidth(); |
171 | | int32_t GetIntrinsicHeight(); |
172 | | |
173 | | // This services any pending notifications for the transform on on this root |
174 | | // <svg> node needing to be recalculated. (Only applicable in |
175 | | // SVG-as-an-image documents.) |
176 | | virtual void FlushImageTransformInvalidation(); |
177 | | |
178 | | private: |
179 | | // SVGViewportElement methods: |
180 | | |
181 | | virtual SVGViewElement* GetCurrentViewElement() const; |
182 | | virtual SVGPreserveAspectRatio GetPreserveAspectRatioWithOverride() const override; |
183 | | |
184 | | // implementation helpers: |
185 | | |
186 | | /* |
187 | | * While binding to the tree we need to determine if we will be the outermost |
188 | | * <svg> element _before_ the children are bound (as they want to know what |
189 | | * timed document root to register with) and therefore _before_ our parent is |
190 | | * set (both actions are performed by Element::BindToTree) so we |
191 | | * can't use GetOwnerSVGElement() as it relies on GetParent(). This code is |
192 | | * basically a simplified version of GetOwnerSVGElement that uses the parent |
193 | | * parameters passed in instead. |
194 | | */ |
195 | | bool WillBeOutermostSVG(nsIContent* aParent, |
196 | | nsIContent* aBindingParent) const; |
197 | | |
198 | | // invalidate viewbox -> viewport xform & inform frames |
199 | | void InvalidateTransformNotifyFrame(); |
200 | | |
201 | | // Methods for <image> elements to override my "PreserveAspectRatio" value. |
202 | | // These are private so that only our friends |
203 | | // (AutoPreserveAspectRatioOverride in particular) have access. |
204 | | void SetImageOverridePreserveAspectRatio(const SVGPreserveAspectRatio& aPAR); |
205 | | void ClearImageOverridePreserveAspectRatio(); |
206 | | |
207 | | // Set/Clear properties to hold old version of preserveAspectRatio |
208 | | // when it's being overridden by an <image> element that we are inside of. |
209 | | bool SetPreserveAspectRatioProperty(const SVGPreserveAspectRatio& aPAR); |
210 | | const SVGPreserveAspectRatio* GetPreserveAspectRatioProperty() const; |
211 | | bool ClearPreserveAspectRatioProperty(); |
212 | | |
213 | | virtual SVGPoint GetCurrentTranslate() const override |
214 | 0 | { return mCurrentTranslate; } |
215 | | virtual float GetCurrentScale() const override |
216 | 0 | { return mCurrentScale; } |
217 | | |
218 | | virtual const nsSVGViewBox& GetViewBoxInternal() const override; |
219 | | virtual nsSVGAnimatedTransformList* GetTransformInternal() const override; |
220 | | |
221 | | virtual EnumAttributesInfo GetEnumInfo() override; |
222 | | |
223 | | enum { ZOOMANDPAN }; |
224 | | nsSVGEnum mEnumAttributes[1]; |
225 | | static nsSVGEnumMapping sZoomAndPanMap[]; |
226 | | static EnumInfo sEnumInfo[1]; |
227 | | |
228 | | // The time container for animations within this SVG document fragment. Set |
229 | | // for all outermost <svg> elements (not nested <svg> elements). |
230 | | nsAutoPtr<nsSMILTimeContainer> mTimedDocumentRoot; |
231 | | |
232 | | // zoom and pan |
233 | | // IMPORTANT: see the comment in RecordCurrentScaleTranslate before writing |
234 | | // code to change any of these! |
235 | | SVGPoint mCurrentTranslate; |
236 | | float mCurrentScale; |
237 | | SVGPoint mPreviousTranslate; |
238 | | float mPreviousScale; |
239 | | |
240 | | // For outermost <svg> elements created from parsing, animation is started by |
241 | | // the onload event in accordance with the SVG spec, but for <svg> elements |
242 | | // created by script or promoted from inner <svg> to outermost <svg> we need |
243 | | // to manually kick off animation when they are bound to the tree. |
244 | | bool mStartAnimationOnBindToTree; |
245 | | |
246 | | bool mImageNeedsTransformInvalidation; |
247 | | |
248 | | // mCurrentViewID and mSVGView are mutually exclusive; we can have |
249 | | // at most one non-null. |
250 | | nsAutoPtr<nsString> mCurrentViewID; |
251 | | nsAutoPtr<SVGView> mSVGView; |
252 | | }; |
253 | | |
254 | | } // namespace dom |
255 | | |
256 | | class MOZ_RAII AutoSVGTimeSetRestore |
257 | | { |
258 | | public: |
259 | | AutoSVGTimeSetRestore(dom::SVGSVGElement* aRootElem, |
260 | | float aFrameTime |
261 | | MOZ_GUARD_OBJECT_NOTIFIER_PARAM) |
262 | | : mRootElem(aRootElem) |
263 | | , mOriginalTime(mRootElem->GetCurrentTime()) |
264 | 0 | { |
265 | 0 | MOZ_GUARD_OBJECT_NOTIFIER_INIT; |
266 | 0 | mRootElem->SetCurrentTime(aFrameTime); // Does nothing if there's no change. |
267 | 0 | } |
268 | | |
269 | | ~AutoSVGTimeSetRestore() |
270 | 0 | { |
271 | 0 | mRootElem->SetCurrentTime(mOriginalTime); |
272 | 0 | } |
273 | | |
274 | | private: |
275 | | const RefPtr<dom::SVGSVGElement> mRootElem; |
276 | | const float mOriginalTime; |
277 | | MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER |
278 | | }; |
279 | | |
280 | | class MOZ_RAII AutoPreserveAspectRatioOverride |
281 | | { |
282 | | public: |
283 | | AutoPreserveAspectRatioOverride(const Maybe<SVGImageContext>& aSVGContext, |
284 | | dom::SVGSVGElement* aRootElem |
285 | | MOZ_GUARD_OBJECT_NOTIFIER_PARAM) |
286 | | : mRootElem(aRootElem) |
287 | | , mDidOverride(false) |
288 | 0 | { |
289 | 0 | MOZ_GUARD_OBJECT_NOTIFIER_INIT; |
290 | 0 | MOZ_ASSERT(mRootElem, "No SVG/Symbol node to manage?"); |
291 | 0 |
|
292 | 0 | if (aSVGContext.isSome() && |
293 | 0 | aSVGContext->GetPreserveAspectRatio().isSome()) { |
294 | 0 | // Override preserveAspectRatio in our helper document. |
295 | 0 | // XXXdholbert We should technically be overriding the helper doc's clip |
296 | 0 | // and overflow properties here, too. See bug 272288 comment 36. |
297 | 0 | mRootElem->SetImageOverridePreserveAspectRatio( |
298 | 0 | *aSVGContext->GetPreserveAspectRatio()); |
299 | 0 | mDidOverride = true; |
300 | 0 | } |
301 | 0 | } |
302 | | |
303 | | ~AutoPreserveAspectRatioOverride() |
304 | 0 | { |
305 | 0 | if (mDidOverride) { |
306 | 0 | mRootElem->ClearImageOverridePreserveAspectRatio(); |
307 | 0 | } |
308 | 0 | } |
309 | | |
310 | | private: |
311 | | const RefPtr<dom::SVGSVGElement> mRootElem; |
312 | | bool mDidOverride; |
313 | | MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER |
314 | | }; |
315 | | |
316 | | } // namespace mozilla |
317 | | |
318 | | #endif // SVGSVGElement_h |