Bug 1691109 [wpt PR 27513] - Increase timeout duration for wpt/fetch/api/basic/keepal...
[gecko.git] / dom / svg / SVGElement.h
blobff145d01ab1acab799a454810d7a805826d7d220
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/. */
7 #ifndef DOM_SVG_SVGELEMENT_H_
8 #define DOM_SVG_SVGELEMENT_H_
11 SVGElement is the base class for all SVG content elements.
12 It implements all the common DOM interfaces and handles attributes.
15 #include "mozilla/Attributes.h"
16 #include "mozilla/RefPtr.h"
17 #include "mozilla/SVGAnimatedClass.h"
18 #include "mozilla/SVGContentUtils.h"
19 #include "mozilla/dom/DOMRect.h"
20 #include "mozilla/dom/Element.h"
21 #include "mozilla/gfx/MatrixFwd.h"
22 #include "mozilla/UniquePtr.h"
23 #include "nsCSSPropertyID.h"
24 #include "nsChangeHint.h"
25 #include "nsCycleCollectionParticipant.h"
26 #include "nsError.h"
27 #include "nsISupportsImpl.h"
28 #include "nsStyledElement.h"
29 #include "gfxMatrix.h"
31 // {70db954d-e452-4be3-83aa-f54a51cf7890}
32 #define MOZILLA_SVGELEMENT_IID \
33 { \
34 0x70db954d, 0xe452, 0x4be3, { \
35 0x82, 0xaa, 0xf5, 0x4a, 0x51, 0xcf, 0x78, 0x90 \
36 } \
39 nsresult NS_NewSVGElement(mozilla::dom::Element** aResult,
40 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
42 class mozAutoDocUpdate;
44 namespace mozilla {
45 class DeclarationBlock;
47 class SVGAnimatedBoolean;
48 class SVGAnimatedEnumeration;
49 class SVGAnimatedInteger;
50 class SVGAnimatedIntegerPair;
51 class SVGAnimatedLength;
52 class SVGAnimatedLengthList;
53 class SVGAnimatedNumber;
54 class SVGAnimatedNumberList;
55 class SVGAnimatedNumberPair;
56 class SVGAnimatedOrient;
57 class SVGAnimatedPathSegList;
58 class SVGAnimatedPointList;
59 class SVGAnimatedString;
60 class SVGAnimatedPreserveAspectRatio;
61 class SVGAnimatedTransformList;
62 class SVGAnimatedViewBox;
63 class SVGNumberList;
64 class SVGStringList;
65 class SVGUserUnitList;
67 struct SVGEnumMapping;
69 namespace dom {
70 class DOMSVGStringList;
71 class SVGSVGElement;
72 class SVGViewportElement;
74 using SVGElementBase = nsStyledElement;
76 class SVGElement : public SVGElementBase // nsIContent
78 protected:
79 explicit SVGElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
80 friend nsresult(
81 ::NS_NewSVGElement(mozilla::dom::Element** aResult,
82 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
83 nsresult Init();
84 virtual ~SVGElement();
86 public:
87 virtual nsresult Clone(mozilla::dom::NodeInfo*,
88 nsINode** aResult) const MOZ_MUST_OVERRIDE override;
90 // From Element
91 nsresult CopyInnerTo(mozilla::dom::Element* aDest);
93 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_SVGELEMENT_IID)
94 // nsISupports
95 NS_INLINE_DECL_REFCOUNTING_INHERITED(SVGElement, SVGElementBase)
97 NS_DECL_ADDSIZEOFEXCLUDINGTHIS
99 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
101 void DidAnimateClass();
103 void SetNonce(const nsAString& aNonce) {
104 SetProperty(nsGkAtoms::nonce, new nsString(aNonce),
105 nsINode::DeleteProperty<nsString>);
107 void RemoveNonce() { RemoveProperty(nsGkAtoms::nonce); }
108 void GetNonce(nsAString& aNonce) const {
109 nsString* cspNonce = static_cast<nsString*>(GetProperty(nsGkAtoms::nonce));
110 if (cspNonce) {
111 aNonce = *cspNonce;
115 // nsIContent interface methods
117 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
119 virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
120 int32_t aModType) const override;
122 virtual bool IsNodeOfType(uint32_t aFlags) const override;
125 * We override the default to unschedule computation of Servo declaration
126 * blocks when adopted across documents.
128 virtual void NodeInfoChanged(Document* aOldDoc) override;
130 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
132 static const MappedAttributeEntry sFillStrokeMap[];
133 static const MappedAttributeEntry sGraphicsMap[];
134 static const MappedAttributeEntry sTextContentElementsMap[];
135 static const MappedAttributeEntry sFontSpecificationMap[];
136 static const MappedAttributeEntry sGradientStopMap[];
137 static const MappedAttributeEntry sViewportsMap[];
138 static const MappedAttributeEntry sMarkersMap[];
139 static const MappedAttributeEntry sColorMap[];
140 static const MappedAttributeEntry sFiltersMap[];
141 static const MappedAttributeEntry sFEFloodMap[];
142 static const MappedAttributeEntry sLightingEffectsMap[];
143 static const MappedAttributeEntry sMaskMap[];
145 NS_IMPL_FROMNODE(SVGElement, kNameSpaceID_SVG)
147 // Gets the element that establishes the rectangular viewport against which
148 // we should resolve percentage lengths (our "coordinate context"). Returns
149 // nullptr for outer <svg> or SVG without an <svg> parent (invalid SVG).
150 mozilla::dom::SVGViewportElement* GetCtx() const;
153 * Returns aMatrix pre-multiplied by (explicit or implicit) transforms that
154 * are introduced by attributes on this element.
156 * If aWhich is eAllTransforms, then all the transforms from the coordinate
157 * space established by this element for its children to the coordinate
158 * space established by this element's parent element for this element, are
159 * included.
161 * If aWhich is eUserSpaceToParent, then only the transforms from this
162 * element's userspace to the coordinate space established by its parent is
163 * included. This includes any transforms introduced by the 'transform'
164 * attribute, transform animations and animateMotion, but not any offsets
165 * due to e.g. 'x'/'y' attributes, or any transform due to a 'viewBox'
166 * attribute. (SVG userspace is defined to be the coordinate space in which
167 * coordinates on an element apply.)
169 * If aWhich is eChildToUserSpace, then only the transforms from the
170 * coordinate space established by this element for its childre to this
171 * elements userspace are included. This includes any offsets due to e.g.
172 * 'x'/'y' attributes, and any transform due to a 'viewBox' attribute, but
173 * does not include any transforms due to the 'transform' attribute.
175 virtual gfxMatrix PrependLocalTransformsTo(
176 const gfxMatrix& aMatrix,
177 SVGTransformTypes aWhich = eAllTransforms) const;
179 // Setter for to set the current <animateMotion> transformation
180 // Only visible for SVGGraphicElement, so it's a no-op here, and that
181 // subclass has the useful implementation.
182 virtual void SetAnimateMotionTransform(
183 const mozilla::gfx::Matrix* aMatrix) { /*no-op*/
185 virtual const mozilla::gfx::Matrix* GetAnimateMotionTransform() const {
186 return nullptr;
189 bool IsStringAnimatable(uint8_t aAttrEnum) {
190 return GetStringInfo().mStringInfo[aAttrEnum].mIsAnimatable;
192 bool NumberAttrAllowsPercentage(uint8_t aAttrEnum) {
193 return GetNumberInfo().mNumberInfo[aAttrEnum].mPercentagesAllowed;
195 virtual bool HasValidDimensions() const { return true; }
196 void SetLength(nsAtom* aName, const SVGAnimatedLength& aLength);
198 enum class ValToUse { Base, Anim };
199 static bool UpdateDeclarationBlockFromLength(DeclarationBlock& aBlock,
200 nsCSSPropertyID aPropId,
201 const SVGAnimatedLength& aLength,
202 ValToUse aValToUse);
204 nsAttrValue WillChangeLength(uint8_t aAttrEnum,
205 const mozAutoDocUpdate& aProofOfUpdate);
206 nsAttrValue WillChangeNumberPair(uint8_t aAttrEnum);
207 nsAttrValue WillChangeIntegerPair(uint8_t aAttrEnum,
208 const mozAutoDocUpdate& aProofOfUpdate);
209 nsAttrValue WillChangeOrient(const mozAutoDocUpdate& aProofOfUpdate);
210 nsAttrValue WillChangeViewBox(const mozAutoDocUpdate& aProofOfUpdate);
211 nsAttrValue WillChangePreserveAspectRatio(
212 const mozAutoDocUpdate& aProofOfUpdate);
213 nsAttrValue WillChangeNumberList(uint8_t aAttrEnum,
214 const mozAutoDocUpdate& aProofOfUpdate);
215 nsAttrValue WillChangeLengthList(uint8_t aAttrEnum,
216 const mozAutoDocUpdate& aProofOfUpdate);
217 nsAttrValue WillChangePointList(const mozAutoDocUpdate& aProofOfUpdate);
218 nsAttrValue WillChangePathSegList(const mozAutoDocUpdate& aProofOfUpdate);
219 nsAttrValue WillChangeTransformList(const mozAutoDocUpdate& aProofOfUpdate);
220 nsAttrValue WillChangeStringList(bool aIsConditionalProcessingAttribute,
221 uint8_t aAttrEnum,
222 const mozAutoDocUpdate& aProofOfUpdate);
224 void DidChangeLength(uint8_t aAttrEnum, const nsAttrValue& aEmptyOrOldValue,
225 const mozAutoDocUpdate& aProofOfUpdate);
226 void DidChangeNumber(uint8_t aAttrEnum);
227 void DidChangeNumberPair(uint8_t aAttrEnum,
228 const nsAttrValue& aEmptyOrOldValue);
229 void DidChangeInteger(uint8_t aAttrEnum);
230 void DidChangeIntegerPair(uint8_t aAttrEnum,
231 const nsAttrValue& aEmptyOrOldValue,
232 const mozAutoDocUpdate& aProofOfUpdate);
233 void DidChangeBoolean(uint8_t aAttrEnum);
234 void DidChangeEnum(uint8_t aAttrEnum);
235 void DidChangeOrient(const nsAttrValue& aEmptyOrOldValue,
236 const mozAutoDocUpdate& aProofOfUpdate);
237 void DidChangeViewBox(const nsAttrValue& aEmptyOrOldValue,
238 const mozAutoDocUpdate& aProofOfUpdate);
239 void DidChangePreserveAspectRatio(const nsAttrValue& aEmptyOrOldValue,
240 const mozAutoDocUpdate& aProofOfUpdate);
241 void DidChangeNumberList(uint8_t aAttrEnum,
242 const nsAttrValue& aEmptyOrOldValue,
243 const mozAutoDocUpdate& aProofOfUpdate);
244 void DidChangeLengthList(uint8_t aAttrEnum,
245 const nsAttrValue& aEmptyOrOldValue,
246 const mozAutoDocUpdate& aProofOfUpdate);
247 void DidChangePointList(const nsAttrValue& aEmptyOrOldValue,
248 const mozAutoDocUpdate& aProofOfUpdate);
249 void DidChangePathSegList(const nsAttrValue& aEmptyOrOldValue,
250 const mozAutoDocUpdate& aProofOfUpdate);
251 void DidChangeTransformList(const nsAttrValue& aEmptyOrOldValue,
252 const mozAutoDocUpdate& aProofOfUpdate);
253 void DidChangeString(uint8_t aAttrEnum) {}
254 void DidChangeStringList(bool aIsConditionalProcessingAttribute,
255 uint8_t aAttrEnum,
256 const nsAttrValue& aEmptyOrOldValue,
257 const mozAutoDocUpdate& aProofOfUpdate);
259 void DidAnimateLength(uint8_t aAttrEnum);
260 void DidAnimateNumber(uint8_t aAttrEnum);
261 void DidAnimateNumberPair(uint8_t aAttrEnum);
262 void DidAnimateInteger(uint8_t aAttrEnum);
263 void DidAnimateIntegerPair(uint8_t aAttrEnum);
264 void DidAnimateBoolean(uint8_t aAttrEnum);
265 void DidAnimateEnum(uint8_t aAttrEnum);
266 void DidAnimateOrient();
267 void DidAnimateViewBox();
268 void DidAnimatePreserveAspectRatio();
269 void DidAnimateNumberList(uint8_t aAttrEnum);
270 void DidAnimateLengthList(uint8_t aAttrEnum);
271 void DidAnimatePointList();
272 void DidAnimatePathSegList();
273 void DidAnimateTransformList(int32_t aModType);
274 void DidAnimateString(uint8_t aAttrEnum);
276 enum {
278 * Flag to indicate to GetAnimatedXxx() methods that the object being
279 * requested should be allocated if it hasn't already been allocated, and
280 * that the method should not return null. Only applicable to methods that
281 * need to allocate the object that they return.
283 DO_ALLOCATE = 0x1
286 SVGAnimatedLength* GetAnimatedLength(uint8_t aAttrEnum);
287 SVGAnimatedLength* GetAnimatedLength(const nsAtom* aAttrName);
288 void GetAnimatedLengthValues(float* aFirst, ...);
289 void GetAnimatedNumberValues(float* aFirst, ...);
290 void GetAnimatedIntegerValues(int32_t* aFirst, ...);
291 SVGAnimatedNumberList* GetAnimatedNumberList(uint8_t aAttrEnum);
292 SVGAnimatedNumberList* GetAnimatedNumberList(nsAtom* aAttrName);
293 void GetAnimatedLengthListValues(SVGUserUnitList* aFirst, ...);
294 SVGAnimatedLengthList* GetAnimatedLengthList(uint8_t aAttrEnum);
295 virtual SVGAnimatedPointList* GetAnimatedPointList() { return nullptr; }
296 virtual SVGAnimatedPathSegList* GetAnimPathSegList() {
297 // DOM interface 'SVGAnimatedPathData' (*inherited* by SVGPathElement)
298 // has a member called 'animatedPathSegList' member, so we have a shorter
299 // name so we don't get hidden by the GetAnimatedPathSegList declared by
300 // NS_DECL_NSIDOMSVGANIMATEDPATHDATA.
301 return nullptr;
304 * Get the SVGAnimatedTransformList for this element.
306 * Despite the fact that animated transform lists are used for a variety of
307 * attributes, no SVG element uses more than one.
309 * It's relatively uncommon for elements to have their transform attribute
310 * set, so to save memory the SVGAnimatedTransformList is not allocated
311 * until the attribute is set/animated or its DOM wrapper is created. Callers
312 * that require the SVGAnimatedTransformList to be allocated and for this
313 * method to return non-null must pass the DO_ALLOCATE flag.
315 virtual SVGAnimatedTransformList* GetAnimatedTransformList(
316 uint32_t aFlags = 0) {
317 return nullptr;
320 mozilla::UniquePtr<SMILAttr> GetAnimatedAttr(int32_t aNamespaceID,
321 nsAtom* aName) override;
322 void AnimationNeedsResample();
323 void FlushAnimations();
325 virtual void RecompileScriptEventListeners() override;
327 void GetStringBaseValue(uint8_t aAttrEnum, nsAString& aResult) const;
328 void SetStringBaseValue(uint8_t aAttrEnum, const nsAString& aValue);
330 virtual nsStaticAtom* GetPointListAttrName() const { return nullptr; }
331 virtual nsStaticAtom* GetPathDataAttrName() const { return nullptr; }
332 virtual nsStaticAtom* GetTransformListAttrName() const { return nullptr; }
333 const nsAttrValue* GetAnimatedClassName() const {
334 if (!mClassAttribute.IsAnimated()) {
335 return nullptr;
337 return mClassAnimAttr.get();
340 virtual void ClearAnyCachedPath() {}
341 virtual bool IsTransformable() { return false; }
343 // WebIDL
344 mozilla::dom::SVGSVGElement* GetOwnerSVGElement();
345 SVGElement* GetViewportElement();
346 already_AddRefed<mozilla::dom::DOMSVGAnimatedString> ClassName();
348 void UpdateContentDeclarationBlock();
349 const mozilla::DeclarationBlock* GetContentDeclarationBlock() const;
351 protected:
352 virtual JSObject* WrapNode(JSContext* cx,
353 JS::Handle<JSObject*> aGivenProto) override;
355 // We define BeforeSetAttr here and mark it final to ensure it is NOT used
356 // by SVG elements.
357 // This is because we're not currently passing the correct value for aValue to
358 // BeforeSetAttr since it would involve allocating extra SVG value types.
359 // See the comment in SVGElement::WillChangeValue.
360 nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
361 const nsAttrValueOrString* aValue, bool aNotify) final;
362 virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
363 const nsAttrValue* aValue,
364 const nsAttrValue* aOldValue,
365 nsIPrincipal* aSubjectPrincipal,
366 bool aNotify) override;
367 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
368 const nsAString& aValue,
369 nsIPrincipal* aMaybeScriptedPrincipal,
370 nsAttrValue& aResult) override;
371 static nsresult ReportAttributeParseFailure(Document* aDocument,
372 nsAtom* aAttribute,
373 const nsAString& aValue);
375 nsAttrValue WillChangeValue(nsAtom* aName,
376 const mozAutoDocUpdate& aProofOfUpdate);
377 // aNewValue is set to the old value. This value may be invalid if
378 // !StoresOwnData.
379 void DidChangeValue(nsAtom* aName, const nsAttrValue& aEmptyOrOldValue,
380 nsAttrValue& aNewValue,
381 const mozAutoDocUpdate& aProofOfUpdate);
382 void MaybeSerializeAttrBeforeRemoval(nsAtom* aName, bool aNotify);
384 nsAtom* GetEventNameForAttr(nsAtom* aAttr);
386 struct LengthInfo {
387 nsStaticAtom* const mName;
388 const float mDefaultValue;
389 const uint8_t mDefaultUnitType;
390 const uint8_t mCtxType;
393 struct LengthAttributesInfo {
394 SVGAnimatedLength* const mLengths;
395 const LengthInfo* const mLengthInfo;
396 const uint32_t mLengthCount;
398 LengthAttributesInfo(SVGAnimatedLength* aLengths, LengthInfo* aLengthInfo,
399 uint32_t aLengthCount)
400 : mLengths(aLengths),
401 mLengthInfo(aLengthInfo),
402 mLengthCount(aLengthCount) {}
404 void Reset(uint8_t aAttrEnum);
407 struct NumberInfo {
408 nsStaticAtom* const mName;
409 const float mDefaultValue;
410 const bool mPercentagesAllowed;
413 struct NumberAttributesInfo {
414 SVGAnimatedNumber* const mNumbers;
415 const NumberInfo* const mNumberInfo;
416 const uint32_t mNumberCount;
418 NumberAttributesInfo(SVGAnimatedNumber* aNumbers, NumberInfo* aNumberInfo,
419 uint32_t aNumberCount)
420 : mNumbers(aNumbers),
421 mNumberInfo(aNumberInfo),
422 mNumberCount(aNumberCount) {}
424 void Reset(uint8_t aAttrEnum);
427 struct NumberPairInfo {
428 nsStaticAtom* const mName;
429 const float mDefaultValue1;
430 const float mDefaultValue2;
433 struct NumberPairAttributesInfo {
434 SVGAnimatedNumberPair* const mNumberPairs;
435 const NumberPairInfo* const mNumberPairInfo;
436 const uint32_t mNumberPairCount;
438 NumberPairAttributesInfo(SVGAnimatedNumberPair* aNumberPairs,
439 NumberPairInfo* aNumberPairInfo,
440 uint32_t aNumberPairCount)
441 : mNumberPairs(aNumberPairs),
442 mNumberPairInfo(aNumberPairInfo),
443 mNumberPairCount(aNumberPairCount) {}
445 void Reset(uint8_t aAttrEnum);
448 struct IntegerInfo {
449 nsStaticAtom* const mName;
450 const int32_t mDefaultValue;
453 struct IntegerAttributesInfo {
454 SVGAnimatedInteger* const mIntegers;
455 const IntegerInfo* const mIntegerInfo;
456 const uint32_t mIntegerCount;
458 IntegerAttributesInfo(SVGAnimatedInteger* aIntegers,
459 IntegerInfo* aIntegerInfo, uint32_t aIntegerCount)
460 : mIntegers(aIntegers),
461 mIntegerInfo(aIntegerInfo),
462 mIntegerCount(aIntegerCount) {}
464 void Reset(uint8_t aAttrEnum);
467 struct IntegerPairInfo {
468 nsStaticAtom* const mName;
469 const int32_t mDefaultValue1;
470 const int32_t mDefaultValue2;
473 struct IntegerPairAttributesInfo {
474 SVGAnimatedIntegerPair* const mIntegerPairs;
475 const IntegerPairInfo* const mIntegerPairInfo;
476 const uint32_t mIntegerPairCount;
478 IntegerPairAttributesInfo(SVGAnimatedIntegerPair* aIntegerPairs,
479 IntegerPairInfo* aIntegerPairInfo,
480 uint32_t aIntegerPairCount)
481 : mIntegerPairs(aIntegerPairs),
482 mIntegerPairInfo(aIntegerPairInfo),
483 mIntegerPairCount(aIntegerPairCount) {}
485 void Reset(uint8_t aAttrEnum);
488 struct BooleanInfo {
489 nsStaticAtom* const mName;
490 const bool mDefaultValue;
493 struct BooleanAttributesInfo {
494 SVGAnimatedBoolean* const mBooleans;
495 const BooleanInfo* const mBooleanInfo;
496 const uint32_t mBooleanCount;
498 BooleanAttributesInfo(SVGAnimatedBoolean* aBooleans,
499 BooleanInfo* aBooleanInfo, uint32_t aBooleanCount)
500 : mBooleans(aBooleans),
501 mBooleanInfo(aBooleanInfo),
502 mBooleanCount(aBooleanCount) {}
504 void Reset(uint8_t aAttrEnum);
507 friend class mozilla::SVGAnimatedEnumeration;
509 struct EnumInfo {
510 nsStaticAtom* const mName;
511 const SVGEnumMapping* const mMapping;
512 const uint16_t mDefaultValue;
515 struct EnumAttributesInfo {
516 SVGAnimatedEnumeration* const mEnums;
517 const EnumInfo* const mEnumInfo;
518 const uint32_t mEnumCount;
520 EnumAttributesInfo(SVGAnimatedEnumeration* aEnums, EnumInfo* aEnumInfo,
521 uint32_t aEnumCount)
522 : mEnums(aEnums), mEnumInfo(aEnumInfo), mEnumCount(aEnumCount) {}
524 void Reset(uint8_t aAttrEnum);
527 struct NumberListInfo {
528 nsStaticAtom* const mName;
531 struct NumberListAttributesInfo {
532 SVGAnimatedNumberList* const mNumberLists;
533 const NumberListInfo* const mNumberListInfo;
534 const uint32_t mNumberListCount;
536 NumberListAttributesInfo(SVGAnimatedNumberList* aNumberLists,
537 NumberListInfo* aNumberListInfo,
538 uint32_t aNumberListCount)
539 : mNumberLists(aNumberLists),
540 mNumberListInfo(aNumberListInfo),
541 mNumberListCount(aNumberListCount) {}
543 void Reset(uint8_t aAttrEnum);
546 struct LengthListInfo {
547 nsStaticAtom* const mName;
548 const uint8_t mAxis;
550 * Flag to indicate whether appending zeros to the end of the list would
551 * change the rendering of the SVG for the attribute in question. For x and
552 * y on the <text> element this is true, but for dx and dy on <text> this
553 * is false. This flag is fed down to SVGLengthListSMILType so it can
554 * determine if it can sensibly animate from-to lists of different lengths,
555 * which is desirable in the case of dx and dy.
557 const bool mCouldZeroPadList;
560 struct LengthListAttributesInfo {
561 SVGAnimatedLengthList* const mLengthLists;
562 const LengthListInfo* const mLengthListInfo;
563 const uint32_t mLengthListCount;
565 LengthListAttributesInfo(SVGAnimatedLengthList* aLengthLists,
566 LengthListInfo* aLengthListInfo,
567 uint32_t aLengthListCount)
568 : mLengthLists(aLengthLists),
569 mLengthListInfo(aLengthListInfo),
570 mLengthListCount(aLengthListCount) {}
572 void Reset(uint8_t aAttrEnum);
575 struct StringInfo {
576 nsStaticAtom* const mName;
577 const int32_t mNamespaceID;
578 const bool mIsAnimatable;
581 struct StringAttributesInfo {
582 SVGAnimatedString* const mStrings;
583 const StringInfo* const mStringInfo;
584 const uint32_t mStringCount;
586 StringAttributesInfo(SVGAnimatedString* aStrings, StringInfo* aStringInfo,
587 uint32_t aStringCount)
588 : mStrings(aStrings),
589 mStringInfo(aStringInfo),
590 mStringCount(aStringCount) {}
592 void Reset(uint8_t aAttrEnum);
595 friend class DOMSVGStringList;
597 struct StringListInfo {
598 nsStaticAtom* const mName;
601 struct StringListAttributesInfo {
602 SVGStringList* const mStringLists;
603 const StringListInfo* const mStringListInfo;
604 const uint32_t mStringListCount;
606 StringListAttributesInfo(SVGStringList* aStringLists,
607 StringListInfo* aStringListInfo,
608 uint32_t aStringListCount)
609 : mStringLists(aStringLists),
610 mStringListInfo(aStringListInfo),
611 mStringListCount(aStringListCount) {}
613 void Reset(uint8_t aAttrEnum);
616 virtual LengthAttributesInfo GetLengthInfo();
617 virtual NumberAttributesInfo GetNumberInfo();
618 virtual NumberPairAttributesInfo GetNumberPairInfo();
619 virtual IntegerAttributesInfo GetIntegerInfo();
620 virtual IntegerPairAttributesInfo GetIntegerPairInfo();
621 virtual BooleanAttributesInfo GetBooleanInfo();
622 virtual EnumAttributesInfo GetEnumInfo();
623 // We assume all orients, viewboxes and preserveAspectRatios are alike
624 // so we don't need to wrap the class
625 virtual SVGAnimatedOrient* GetAnimatedOrient();
626 virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio();
627 virtual SVGAnimatedViewBox* GetAnimatedViewBox();
628 virtual NumberListAttributesInfo GetNumberListInfo();
629 virtual LengthListAttributesInfo GetLengthListInfo();
630 virtual StringAttributesInfo GetStringInfo();
631 virtual StringListAttributesInfo GetStringListInfo();
633 static SVGEnumMapping sSVGUnitTypesMap[];
635 private:
636 void UnsetAttrInternal(int32_t aNameSpaceID, nsAtom* aName, bool aNotify);
638 SVGAnimatedClass mClassAttribute;
639 UniquePtr<nsAttrValue> mClassAnimAttr;
640 RefPtr<mozilla::DeclarationBlock> mContentDeclarationBlock;
643 NS_DEFINE_STATIC_IID_ACCESSOR(SVGElement, MOZILLA_SVGELEMENT_IID)
646 * A macro to implement the NS_NewSVGXXXElement() functions.
648 #define NS_IMPL_NS_NEW_SVG_ELEMENT(_elementName) \
649 nsresult NS_NewSVG##_elementName##Element( \
650 nsIContent** aResult, \
651 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) { \
652 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo); \
653 auto* nim = nodeInfo->NodeInfoManager(); \
654 RefPtr<mozilla::dom::SVG##_elementName##Element> it = \
655 new (nim) mozilla::dom::SVG##_elementName##Element(nodeInfo.forget()); \
657 nsresult rv = it->Init(); \
659 if (NS_FAILED(rv)) { \
660 return rv; \
663 it.forget(aResult); \
665 return rv; \
668 #define NS_IMPL_NS_NEW_SVG_ELEMENT_CHECK_PARSER(_elementName) \
669 nsresult NS_NewSVG##_elementName##Element( \
670 nsIContent** aResult, \
671 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
672 mozilla::dom::FromParser aFromParser) { \
673 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo); \
674 auto* nim = nodeInfo->NodeInfoManager(); \
675 RefPtr<mozilla::dom::SVG##_elementName##Element> it = \
676 new (nim) mozilla::dom::SVG##_elementName##Element(nodeInfo.forget(), \
677 aFromParser); \
679 nsresult rv = it->Init(); \
681 if (NS_FAILED(rv)) { \
682 return rv; \
685 it.forget(aResult); \
687 return rv; \
690 // No unlinking, we'd need to null out the value pointer (the object it
691 // points to is held by the element) and null-check it everywhere.
692 #define NS_SVG_VAL_IMPL_CYCLE_COLLECTION(_val, _element) \
693 NS_IMPL_CYCLE_COLLECTION_CLASS(_val) \
694 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_val) \
695 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_element) \
696 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \
697 NS_IMPL_CYCLE_COLLECTION_UNLINK_0(_val)
699 #define NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(_val, _element) \
700 NS_IMPL_CYCLE_COLLECTION_CLASS(_val) \
701 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_val) \
702 NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \
703 NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
704 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_val) \
705 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_element) \
706 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \
707 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_val) \
708 NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER \
709 NS_IMPL_CYCLE_COLLECTION_TRACE_END
711 } // namespace dom
712 } // namespace mozilla
714 #endif // DOM_SVG_SVGELEMENT_H_