Bug 1663089 [wpt PR 25399] - idle-detection: Implement requestPermission() method...
[gecko.git] / dom / svg / SVGElement.h
blobfd2afbde8dd6c4363bd957a4779469ab7b6aeffe
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 "nsChangeHint.h"
24 #include "nsCycleCollectionParticipant.h"
25 #include "nsError.h"
26 #include "nsISupportsImpl.h"
27 #include "nsStyledElement.h"
28 #include "gfxMatrix.h"
30 // {70db954d-e452-4be3-83aa-f54a51cf7890}
31 #define MOZILLA_SVGELEMENT_IID \
32 { \
33 0x70db954d, 0xe452, 0x4be3, { \
34 0x82, 0xaa, 0xf5, 0x4a, 0x51, 0xcf, 0x78, 0x90 \
35 } \
38 nsresult NS_NewSVGElement(mozilla::dom::Element** aResult,
39 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
41 class mozAutoDocUpdate;
43 namespace mozilla {
44 class DeclarationBlock;
46 class SVGAnimatedBoolean;
47 class SVGAnimatedEnumeration;
48 class SVGAnimatedInteger;
49 class SVGAnimatedIntegerPair;
50 class SVGAnimatedLength;
51 class SVGAnimatedLengthList;
52 class SVGAnimatedNumber;
53 class SVGAnimatedNumberList;
54 class SVGAnimatedNumberPair;
55 class SVGAnimatedOrient;
56 class SVGAnimatedPathSegList;
57 class SVGAnimatedPointList;
58 class SVGAnimatedString;
59 class SVGAnimatedPreserveAspectRatio;
60 class SVGAnimatedTransformList;
61 class SVGAnimatedViewBox;
62 class SVGNumberList;
63 class SVGStringList;
64 class SVGUserUnitList;
66 struct SVGEnumMapping;
68 namespace dom {
69 class DOMSVGStringList;
70 class SVGSVGElement;
71 class SVGViewportElement;
73 using SVGElementBase = nsStyledElement;
75 class SVGElement : public SVGElementBase // nsIContent
77 protected:
78 explicit SVGElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
79 friend nsresult(
80 ::NS_NewSVGElement(mozilla::dom::Element** aResult,
81 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
82 nsresult Init();
83 virtual ~SVGElement();
85 public:
86 virtual nsresult Clone(mozilla::dom::NodeInfo*,
87 nsINode** aResult) const MOZ_MUST_OVERRIDE override;
89 // From Element
90 nsresult CopyInnerTo(mozilla::dom::Element* aDest);
92 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_SVGELEMENT_IID)
93 // nsISupports
94 NS_INLINE_DECL_REFCOUNTING_INHERITED(SVGElement, SVGElementBase)
96 NS_DECL_ADDSIZEOFEXCLUDINGTHIS
98 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
100 void DidAnimateClass();
102 void SetNonce(const nsAString& aNonce) {
103 SetProperty(nsGkAtoms::nonce, new nsString(aNonce),
104 nsINode::DeleteProperty<nsString>);
106 void RemoveNonce() { RemoveProperty(nsGkAtoms::nonce); }
107 void GetNonce(nsAString& aNonce) const {
108 nsString* cspNonce = static_cast<nsString*>(GetProperty(nsGkAtoms::nonce));
109 if (cspNonce) {
110 aNonce = *cspNonce;
114 // nsIContent interface methods
116 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
118 virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
119 int32_t aModType) const override;
121 virtual bool IsNodeOfType(uint32_t aFlags) const override;
124 * We override the default to unschedule computation of Servo declaration
125 * blocks when adopted across documents.
127 virtual void NodeInfoChanged(Document* aOldDoc) override;
129 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
131 static const MappedAttributeEntry sFillStrokeMap[];
132 static const MappedAttributeEntry sGraphicsMap[];
133 static const MappedAttributeEntry sTextContentElementsMap[];
134 static const MappedAttributeEntry sFontSpecificationMap[];
135 static const MappedAttributeEntry sGradientStopMap[];
136 static const MappedAttributeEntry sViewportsMap[];
137 static const MappedAttributeEntry sMarkersMap[];
138 static const MappedAttributeEntry sColorMap[];
139 static const MappedAttributeEntry sFiltersMap[];
140 static const MappedAttributeEntry sFEFloodMap[];
141 static const MappedAttributeEntry sLightingEffectsMap[];
142 static const MappedAttributeEntry sMaskMap[];
144 NS_IMPL_FROMNODE(SVGElement, kNameSpaceID_SVG)
146 // Gets the element that establishes the rectangular viewport against which
147 // we should resolve percentage lengths (our "coordinate context"). Returns
148 // nullptr for outer <svg> or SVG without an <svg> parent (invalid SVG).
149 mozilla::dom::SVGViewportElement* GetCtx() const;
152 * Returns aMatrix pre-multiplied by (explicit or implicit) transforms that
153 * are introduced by attributes on this element.
155 * If aWhich is eAllTransforms, then all the transforms from the coordinate
156 * space established by this element for its children to the coordinate
157 * space established by this element's parent element for this element, are
158 * included.
160 * If aWhich is eUserSpaceToParent, then only the transforms from this
161 * element's userspace to the coordinate space established by its parent is
162 * included. This includes any transforms introduced by the 'transform'
163 * attribute, transform animations and animateMotion, but not any offsets
164 * due to e.g. 'x'/'y' attributes, or any transform due to a 'viewBox'
165 * attribute. (SVG userspace is defined to be the coordinate space in which
166 * coordinates on an element apply.)
168 * If aWhich is eChildToUserSpace, then only the transforms from the
169 * coordinate space established by this element for its childre to this
170 * elements userspace are included. This includes any offsets due to e.g.
171 * 'x'/'y' attributes, and any transform due to a 'viewBox' attribute, but
172 * does not include any transforms due to the 'transform' attribute.
174 virtual gfxMatrix PrependLocalTransformsTo(
175 const gfxMatrix& aMatrix,
176 SVGTransformTypes aWhich = eAllTransforms) const;
178 // Setter for to set the current <animateMotion> transformation
179 // Only visible for SVGGraphicElement, so it's a no-op here, and that
180 // subclass has the useful implementation.
181 virtual void SetAnimateMotionTransform(
182 const mozilla::gfx::Matrix* aMatrix) { /*no-op*/
184 virtual const mozilla::gfx::Matrix* GetAnimateMotionTransform() const {
185 return nullptr;
188 bool IsStringAnimatable(uint8_t aAttrEnum) {
189 return GetStringInfo().mStringInfo[aAttrEnum].mIsAnimatable;
191 bool NumberAttrAllowsPercentage(uint8_t aAttrEnum) {
192 return GetNumberInfo().mNumberInfo[aAttrEnum].mPercentagesAllowed;
194 virtual bool HasValidDimensions() const { return true; }
195 void SetLength(nsAtom* aName, const SVGAnimatedLength& aLength);
197 enum class ValToUse { Base, Anim };
198 static bool UpdateDeclarationBlockFromLength(DeclarationBlock& aBlock,
199 nsCSSPropertyID aPropId,
200 const SVGAnimatedLength& aLength,
201 ValToUse aValToUse);
203 nsAttrValue WillChangeLength(uint8_t aAttrEnum,
204 const mozAutoDocUpdate& aProofOfUpdate);
205 nsAttrValue WillChangeNumberPair(uint8_t aAttrEnum);
206 nsAttrValue WillChangeIntegerPair(uint8_t aAttrEnum,
207 const mozAutoDocUpdate& aProofOfUpdate);
208 nsAttrValue WillChangeOrient(const mozAutoDocUpdate& aProofOfUpdate);
209 nsAttrValue WillChangeViewBox(const mozAutoDocUpdate& aProofOfUpdate);
210 nsAttrValue WillChangePreserveAspectRatio(
211 const mozAutoDocUpdate& aProofOfUpdate);
212 nsAttrValue WillChangeNumberList(uint8_t aAttrEnum,
213 const mozAutoDocUpdate& aProofOfUpdate);
214 nsAttrValue WillChangeLengthList(uint8_t aAttrEnum,
215 const mozAutoDocUpdate& aProofOfUpdate);
216 nsAttrValue WillChangePointList(const mozAutoDocUpdate& aProofOfUpdate);
217 nsAttrValue WillChangePathSegList(const mozAutoDocUpdate& aProofOfUpdate);
218 nsAttrValue WillChangeTransformList(const mozAutoDocUpdate& aProofOfUpdate);
219 nsAttrValue WillChangeStringList(bool aIsConditionalProcessingAttribute,
220 uint8_t aAttrEnum,
221 const mozAutoDocUpdate& aProofOfUpdate);
223 void DidChangeLength(uint8_t aAttrEnum, const nsAttrValue& aEmptyOrOldValue,
224 const mozAutoDocUpdate& aProofOfUpdate);
225 void DidChangeNumber(uint8_t aAttrEnum);
226 void DidChangeNumberPair(uint8_t aAttrEnum,
227 const nsAttrValue& aEmptyOrOldValue);
228 void DidChangeInteger(uint8_t aAttrEnum);
229 void DidChangeIntegerPair(uint8_t aAttrEnum,
230 const nsAttrValue& aEmptyOrOldValue,
231 const mozAutoDocUpdate& aProofOfUpdate);
232 void DidChangeBoolean(uint8_t aAttrEnum);
233 void DidChangeEnum(uint8_t aAttrEnum);
234 void DidChangeOrient(const nsAttrValue& aEmptyOrOldValue,
235 const mozAutoDocUpdate& aProofOfUpdate);
236 void DidChangeViewBox(const nsAttrValue& aEmptyOrOldValue,
237 const mozAutoDocUpdate& aProofOfUpdate);
238 void DidChangePreserveAspectRatio(const nsAttrValue& aEmptyOrOldValue,
239 const mozAutoDocUpdate& aProofOfUpdate);
240 void DidChangeNumberList(uint8_t aAttrEnum,
241 const nsAttrValue& aEmptyOrOldValue,
242 const mozAutoDocUpdate& aProofOfUpdate);
243 void DidChangeLengthList(uint8_t aAttrEnum,
244 const nsAttrValue& aEmptyOrOldValue,
245 const mozAutoDocUpdate& aProofOfUpdate);
246 void DidChangePointList(const nsAttrValue& aEmptyOrOldValue,
247 const mozAutoDocUpdate& aProofOfUpdate);
248 void DidChangePathSegList(const nsAttrValue& aEmptyOrOldValue,
249 const mozAutoDocUpdate& aProofOfUpdate);
250 void DidChangeTransformList(const nsAttrValue& aEmptyOrOldValue,
251 const mozAutoDocUpdate& aProofOfUpdate);
252 void DidChangeString(uint8_t aAttrEnum) {}
253 void DidChangeStringList(bool aIsConditionalProcessingAttribute,
254 uint8_t aAttrEnum,
255 const nsAttrValue& aEmptyOrOldValue,
256 const mozAutoDocUpdate& aProofOfUpdate);
258 void DidAnimateLength(uint8_t aAttrEnum);
259 void DidAnimateNumber(uint8_t aAttrEnum);
260 void DidAnimateNumberPair(uint8_t aAttrEnum);
261 void DidAnimateInteger(uint8_t aAttrEnum);
262 void DidAnimateIntegerPair(uint8_t aAttrEnum);
263 void DidAnimateBoolean(uint8_t aAttrEnum);
264 void DidAnimateEnum(uint8_t aAttrEnum);
265 void DidAnimateOrient();
266 void DidAnimateViewBox();
267 void DidAnimatePreserveAspectRatio();
268 void DidAnimateNumberList(uint8_t aAttrEnum);
269 void DidAnimateLengthList(uint8_t aAttrEnum);
270 void DidAnimatePointList();
271 void DidAnimatePathSegList();
272 void DidAnimateTransformList(int32_t aModType);
273 void DidAnimateString(uint8_t aAttrEnum);
275 enum {
277 * Flag to indicate to GetAnimatedXxx() methods that the object being
278 * requested should be allocated if it hasn't already been allocated, and
279 * that the method should not return null. Only applicable to methods that
280 * need to allocate the object that they return.
282 DO_ALLOCATE = 0x1
285 SVGAnimatedLength* GetAnimatedLength(uint8_t aAttrEnum);
286 SVGAnimatedLength* GetAnimatedLength(const nsAtom* aAttrName);
287 void GetAnimatedLengthValues(float* aFirst, ...);
288 void GetAnimatedNumberValues(float* aFirst, ...);
289 void GetAnimatedIntegerValues(int32_t* aFirst, ...);
290 SVGAnimatedNumberList* GetAnimatedNumberList(uint8_t aAttrEnum);
291 SVGAnimatedNumberList* GetAnimatedNumberList(nsAtom* aAttrName);
292 void GetAnimatedLengthListValues(SVGUserUnitList* aFirst, ...);
293 SVGAnimatedLengthList* GetAnimatedLengthList(uint8_t aAttrEnum);
294 virtual SVGAnimatedPointList* GetAnimatedPointList() { return nullptr; }
295 virtual SVGAnimatedPathSegList* GetAnimPathSegList() {
296 // DOM interface 'SVGAnimatedPathData' (*inherited* by SVGPathElement)
297 // has a member called 'animatedPathSegList' member, so we have a shorter
298 // name so we don't get hidden by the GetAnimatedPathSegList declared by
299 // NS_DECL_NSIDOMSVGANIMATEDPATHDATA.
300 return nullptr;
303 * Get the SVGAnimatedTransformList for this element.
305 * Despite the fact that animated transform lists are used for a variety of
306 * attributes, no SVG element uses more than one.
308 * It's relatively uncommon for elements to have their transform attribute
309 * set, so to save memory the SVGAnimatedTransformList is not allocated
310 * until the attribute is set/animated or its DOM wrapper is created. Callers
311 * that require the SVGAnimatedTransformList to be allocated and for this
312 * method to return non-null must pass the DO_ALLOCATE flag.
314 virtual SVGAnimatedTransformList* GetAnimatedTransformList(
315 uint32_t aFlags = 0) {
316 return nullptr;
319 mozilla::UniquePtr<SMILAttr> GetAnimatedAttr(int32_t aNamespaceID,
320 nsAtom* aName) override;
321 void AnimationNeedsResample();
322 void FlushAnimations();
324 virtual void RecompileScriptEventListeners() override;
326 void GetStringBaseValue(uint8_t aAttrEnum, nsAString& aResult) const;
327 void SetStringBaseValue(uint8_t aAttrEnum, const nsAString& aValue);
329 virtual nsStaticAtom* GetPointListAttrName() const { return nullptr; }
330 virtual nsStaticAtom* GetPathDataAttrName() const { return nullptr; }
331 virtual nsStaticAtom* GetTransformListAttrName() const { return nullptr; }
332 const nsAttrValue* GetAnimatedClassName() const {
333 if (!mClassAttribute.IsAnimated()) {
334 return nullptr;
336 return mClassAnimAttr.get();
339 virtual void ClearAnyCachedPath() {}
340 virtual bool IsTransformable() { return false; }
342 // WebIDL
343 mozilla::dom::SVGSVGElement* GetOwnerSVGElement();
344 SVGElement* GetViewportElement();
345 already_AddRefed<mozilla::dom::DOMSVGAnimatedString> ClassName();
347 void UpdateContentDeclarationBlock();
348 const mozilla::DeclarationBlock* GetContentDeclarationBlock() const;
350 protected:
351 virtual JSObject* WrapNode(JSContext* cx,
352 JS::Handle<JSObject*> aGivenProto) override;
354 // We define BeforeSetAttr here and mark it final to ensure it is NOT used
355 // by SVG elements.
356 // This is because we're not currently passing the correct value for aValue to
357 // BeforeSetAttr since it would involve allocating extra SVG value types.
358 // See the comment in SVGElement::WillChangeValue.
359 nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
360 const nsAttrValueOrString* aValue, bool aNotify) final;
361 virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
362 const nsAttrValue* aValue,
363 const nsAttrValue* aOldValue,
364 nsIPrincipal* aSubjectPrincipal,
365 bool aNotify) override;
366 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
367 const nsAString& aValue,
368 nsIPrincipal* aMaybeScriptedPrincipal,
369 nsAttrValue& aResult) override;
370 static nsresult ReportAttributeParseFailure(Document* aDocument,
371 nsAtom* aAttribute,
372 const nsAString& aValue);
374 nsAttrValue WillChangeValue(nsAtom* aName,
375 const mozAutoDocUpdate& aProofOfUpdate);
376 // aNewValue is set to the old value. This value may be invalid if
377 // !StoresOwnData.
378 void DidChangeValue(nsAtom* aName, const nsAttrValue& aEmptyOrOldValue,
379 nsAttrValue& aNewValue,
380 const mozAutoDocUpdate& aProofOfUpdate);
381 void MaybeSerializeAttrBeforeRemoval(nsAtom* aName, bool aNotify);
383 static nsAtom* GetEventNameForAttr(nsAtom* aAttr);
385 struct LengthInfo {
386 nsStaticAtom* const mName;
387 const float mDefaultValue;
388 const uint8_t mDefaultUnitType;
389 const uint8_t mCtxType;
392 struct LengthAttributesInfo {
393 SVGAnimatedLength* const mLengths;
394 const LengthInfo* const mLengthInfo;
395 const uint32_t mLengthCount;
397 LengthAttributesInfo(SVGAnimatedLength* aLengths, LengthInfo* aLengthInfo,
398 uint32_t aLengthCount)
399 : mLengths(aLengths),
400 mLengthInfo(aLengthInfo),
401 mLengthCount(aLengthCount) {}
403 void Reset(uint8_t aAttrEnum);
406 struct NumberInfo {
407 nsStaticAtom* const mName;
408 const float mDefaultValue;
409 const bool mPercentagesAllowed;
412 struct NumberAttributesInfo {
413 SVGAnimatedNumber* const mNumbers;
414 const NumberInfo* const mNumberInfo;
415 const uint32_t mNumberCount;
417 NumberAttributesInfo(SVGAnimatedNumber* aNumbers, NumberInfo* aNumberInfo,
418 uint32_t aNumberCount)
419 : mNumbers(aNumbers),
420 mNumberInfo(aNumberInfo),
421 mNumberCount(aNumberCount) {}
423 void Reset(uint8_t aAttrEnum);
426 struct NumberPairInfo {
427 nsStaticAtom* const mName;
428 const float mDefaultValue1;
429 const float mDefaultValue2;
432 struct NumberPairAttributesInfo {
433 SVGAnimatedNumberPair* const mNumberPairs;
434 const NumberPairInfo* const mNumberPairInfo;
435 const uint32_t mNumberPairCount;
437 NumberPairAttributesInfo(SVGAnimatedNumberPair* aNumberPairs,
438 NumberPairInfo* aNumberPairInfo,
439 uint32_t aNumberPairCount)
440 : mNumberPairs(aNumberPairs),
441 mNumberPairInfo(aNumberPairInfo),
442 mNumberPairCount(aNumberPairCount) {}
444 void Reset(uint8_t aAttrEnum);
447 struct IntegerInfo {
448 nsStaticAtom* const mName;
449 const int32_t mDefaultValue;
452 struct IntegerAttributesInfo {
453 SVGAnimatedInteger* const mIntegers;
454 const IntegerInfo* const mIntegerInfo;
455 const uint32_t mIntegerCount;
457 IntegerAttributesInfo(SVGAnimatedInteger* aIntegers,
458 IntegerInfo* aIntegerInfo, uint32_t aIntegerCount)
459 : mIntegers(aIntegers),
460 mIntegerInfo(aIntegerInfo),
461 mIntegerCount(aIntegerCount) {}
463 void Reset(uint8_t aAttrEnum);
466 struct IntegerPairInfo {
467 nsStaticAtom* const mName;
468 const int32_t mDefaultValue1;
469 const int32_t mDefaultValue2;
472 struct IntegerPairAttributesInfo {
473 SVGAnimatedIntegerPair* const mIntegerPairs;
474 const IntegerPairInfo* const mIntegerPairInfo;
475 const uint32_t mIntegerPairCount;
477 IntegerPairAttributesInfo(SVGAnimatedIntegerPair* aIntegerPairs,
478 IntegerPairInfo* aIntegerPairInfo,
479 uint32_t aIntegerPairCount)
480 : mIntegerPairs(aIntegerPairs),
481 mIntegerPairInfo(aIntegerPairInfo),
482 mIntegerPairCount(aIntegerPairCount) {}
484 void Reset(uint8_t aAttrEnum);
487 struct BooleanInfo {
488 nsStaticAtom* const mName;
489 const bool mDefaultValue;
492 struct BooleanAttributesInfo {
493 SVGAnimatedBoolean* const mBooleans;
494 const BooleanInfo* const mBooleanInfo;
495 const uint32_t mBooleanCount;
497 BooleanAttributesInfo(SVGAnimatedBoolean* aBooleans,
498 BooleanInfo* aBooleanInfo, uint32_t aBooleanCount)
499 : mBooleans(aBooleans),
500 mBooleanInfo(aBooleanInfo),
501 mBooleanCount(aBooleanCount) {}
503 void Reset(uint8_t aAttrEnum);
506 friend class mozilla::SVGAnimatedEnumeration;
508 struct EnumInfo {
509 nsStaticAtom* const mName;
510 const SVGEnumMapping* const mMapping;
511 const uint16_t mDefaultValue;
514 struct EnumAttributesInfo {
515 SVGAnimatedEnumeration* const mEnums;
516 const EnumInfo* const mEnumInfo;
517 const uint32_t mEnumCount;
519 EnumAttributesInfo(SVGAnimatedEnumeration* aEnums, EnumInfo* aEnumInfo,
520 uint32_t aEnumCount)
521 : mEnums(aEnums), mEnumInfo(aEnumInfo), mEnumCount(aEnumCount) {}
523 void Reset(uint8_t aAttrEnum);
524 void SetUnknownValue(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_