nsSVGElement.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef __NS_SVGELEMENT_H__
  6. #define __NS_SVGELEMENT_H__
  7. /*
  8. nsSVGElement is the base class for all SVG content elements.
  9. It implements all the common DOM interfaces and handles attributes.
  10. */
  11. #include "mozilla/Attributes.h"
  12. #include "mozilla/css/StyleRule.h"
  13. #include "nsAutoPtr.h"
  14. #include "nsChangeHint.h"
  15. #include "nsCOMPtr.h"
  16. #include "nsCycleCollectionParticipant.h"
  17. #include "nsError.h"
  18. #include "mozilla/dom/DOMRect.h"
  19. #include "mozilla/dom/ElementInlines.h"
  20. #include "nsISupportsImpl.h"
  21. #include "nsStyledElement.h"
  22. #include "nsSVGClass.h"
  23. #include "nsIDOMSVGElement.h"
  24. #include "SVGContentUtils.h"
  25. class nsSVGAngle;
  26. class nsSVGBoolean;
  27. class nsSVGEnum;
  28. class nsSVGInteger;
  29. class nsSVGIntegerPair;
  30. class nsSVGLength2;
  31. class nsSVGNumber2;
  32. class nsSVGNumberPair;
  33. class nsSVGString;
  34. class nsSVGViewBox;
  35. namespace mozilla {
  36. namespace dom {
  37. class SVGSVGElement;
  38. static const unsigned short SVG_UNIT_TYPE_UNKNOWN = 0;
  39. static const unsigned short SVG_UNIT_TYPE_USERSPACEONUSE = 1;
  40. static const unsigned short SVG_UNIT_TYPE_OBJECTBOUNDINGBOX = 2;
  41. } // namespace dom
  42. class SVGAnimatedNumberList;
  43. class SVGNumberList;
  44. class SVGAnimatedLengthList;
  45. class SVGUserUnitList;
  46. class SVGAnimatedPointList;
  47. class SVGAnimatedPathSegList;
  48. class SVGAnimatedPreserveAspectRatio;
  49. class nsSVGAnimatedTransformList;
  50. class SVGStringList;
  51. class DOMSVGStringList;
  52. namespace gfx {
  53. class Matrix;
  54. } // namespace gfx
  55. } // namespace mozilla
  56. class gfxMatrix;
  57. struct nsSVGEnumMapping;
  58. typedef nsStyledElement nsSVGElementBase;
  59. class nsSVGElement : public nsSVGElementBase // nsIContent
  60. , public nsIDOMSVGElement
  61. {
  62. protected:
  63. explicit nsSVGElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
  64. friend nsresult NS_NewSVGElement(mozilla::dom::Element **aResult,
  65. already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
  66. nsresult Init();
  67. virtual ~nsSVGElement(){}
  68. public:
  69. virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const MOZ_MUST_OVERRIDE override;
  70. typedef mozilla::SVGNumberList SVGNumberList;
  71. typedef mozilla::SVGAnimatedNumberList SVGAnimatedNumberList;
  72. typedef mozilla::SVGUserUnitList SVGUserUnitList;
  73. typedef mozilla::SVGAnimatedLengthList SVGAnimatedLengthList;
  74. typedef mozilla::SVGAnimatedPointList SVGAnimatedPointList;
  75. typedef mozilla::SVGAnimatedPathSegList SVGAnimatedPathSegList;
  76. typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
  77. typedef mozilla::nsSVGAnimatedTransformList nsSVGAnimatedTransformList;
  78. typedef mozilla::SVGStringList SVGStringList;
  79. // nsISupports
  80. NS_DECL_ISUPPORTS_INHERITED
  81. void DidAnimateClass();
  82. // nsIContent interface methods
  83. virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
  84. nsIContent* aBindingParent,
  85. bool aCompileEventHandlers) override;
  86. virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
  87. bool aNotify) override;
  88. virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
  89. int32_t aModType) const override;
  90. virtual bool IsNodeOfType(uint32_t aFlags) const override;
  91. NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) override;
  92. void WalkAnimatedContentStyleRules(nsRuleWalker* aRuleWalker);
  93. NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
  94. static const MappedAttributeEntry sFillStrokeMap[];
  95. static const MappedAttributeEntry sGraphicsMap[];
  96. static const MappedAttributeEntry sTextContentElementsMap[];
  97. static const MappedAttributeEntry sFontSpecificationMap[];
  98. static const MappedAttributeEntry sGradientStopMap[];
  99. static const MappedAttributeEntry sViewportsMap[];
  100. static const MappedAttributeEntry sMarkersMap[];
  101. static const MappedAttributeEntry sColorMap[];
  102. static const MappedAttributeEntry sFiltersMap[];
  103. static const MappedAttributeEntry sFEFloodMap[];
  104. static const MappedAttributeEntry sLightingEffectsMap[];
  105. static const MappedAttributeEntry sMaskMap[];
  106. NS_FORWARD_NSIDOMNODE_TO_NSINODE
  107. NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
  108. NS_DECL_NSIDOMSVGELEMENT
  109. // Gets the element that establishes the rectangular viewport against which
  110. // we should resolve percentage lengths (our "coordinate context"). Returns
  111. // nullptr for outer <svg> or SVG without an <svg> parent (invalid SVG).
  112. mozilla::dom::SVGSVGElement* GetCtx() const;
  113. /**
  114. * Returns aMatrix pre-multiplied by (explicit or implicit) transforms that
  115. * are introduced by attributes on this element.
  116. *
  117. * If aWhich is eAllTransforms, then all the transforms from the coordinate
  118. * space established by this element for its children to the coordinate
  119. * space established by this element's parent element for this element, are
  120. * included.
  121. *
  122. * If aWhich is eUserSpaceToParent, then only the transforms from this
  123. * element's userspace to the coordinate space established by its parent is
  124. * included. This includes any transforms introduced by the 'transform'
  125. * attribute, transform animations and animateMotion, but not any offsets
  126. * due to e.g. 'x'/'y' attributes, or any transform due to a 'viewBox'
  127. * attribute. (SVG userspace is defined to be the coordinate space in which
  128. * coordinates on an element apply.)
  129. *
  130. * If aWhich is eChildToUserSpace, then only the transforms from the
  131. * coordinate space established by this element for its childre to this
  132. * elements userspace are included. This includes any offsets due to e.g.
  133. * 'x'/'y' attributes, and any transform due to a 'viewBox' attribute, but
  134. * does not include any transforms due to the 'transform' attribute.
  135. */
  136. virtual gfxMatrix PrependLocalTransformsTo(
  137. const gfxMatrix &aMatrix, SVGTransformTypes aWhich = eAllTransforms) const;
  138. // Setter for to set the current <animateMotion> transformation
  139. // Only visible for nsSVGGraphicElement, so it's a no-op here, and that
  140. // subclass has the useful implementation.
  141. virtual void SetAnimateMotionTransform(const mozilla::gfx::Matrix* aMatrix) {/*no-op*/}
  142. virtual const mozilla::gfx::Matrix* GetAnimateMotionTransform() const { return nullptr; }
  143. bool IsStringAnimatable(uint8_t aAttrEnum) {
  144. return GetStringInfo().mStringInfo[aAttrEnum].mIsAnimatable;
  145. }
  146. bool NumberAttrAllowsPercentage(uint8_t aAttrEnum) {
  147. return GetNumberInfo().mNumberInfo[aAttrEnum].mPercentagesAllowed;
  148. }
  149. virtual bool HasValidDimensions() const {
  150. return true;
  151. }
  152. void SetLength(nsIAtom* aName, const nsSVGLength2 &aLength);
  153. nsAttrValue WillChangeLength(uint8_t aAttrEnum);
  154. nsAttrValue WillChangeNumberPair(uint8_t aAttrEnum);
  155. nsAttrValue WillChangeIntegerPair(uint8_t aAttrEnum);
  156. nsAttrValue WillChangeAngle(uint8_t aAttrEnum);
  157. nsAttrValue WillChangeViewBox();
  158. nsAttrValue WillChangePreserveAspectRatio();
  159. nsAttrValue WillChangeNumberList(uint8_t aAttrEnum);
  160. nsAttrValue WillChangeLengthList(uint8_t aAttrEnum);
  161. nsAttrValue WillChangePointList();
  162. nsAttrValue WillChangePathSegList();
  163. nsAttrValue WillChangeTransformList();
  164. nsAttrValue WillChangeStringList(bool aIsConditionalProcessingAttribute,
  165. uint8_t aAttrEnum);
  166. void DidChangeLength(uint8_t aAttrEnum, const nsAttrValue& aEmptyOrOldValue);
  167. void DidChangeNumber(uint8_t aAttrEnum);
  168. void DidChangeNumberPair(uint8_t aAttrEnum,
  169. const nsAttrValue& aEmptyOrOldValue);
  170. void DidChangeInteger(uint8_t aAttrEnum);
  171. void DidChangeIntegerPair(uint8_t aAttrEnum,
  172. const nsAttrValue& aEmptyOrOldValue);
  173. void DidChangeAngle(uint8_t aAttrEnum, const nsAttrValue& aEmptyOrOldValue);
  174. void DidChangeBoolean(uint8_t aAttrEnum);
  175. void DidChangeEnum(uint8_t aAttrEnum);
  176. void DidChangeViewBox(const nsAttrValue& aEmptyOrOldValue);
  177. void DidChangePreserveAspectRatio(const nsAttrValue& aEmptyOrOldValue);
  178. void DidChangeNumberList(uint8_t aAttrEnum,
  179. const nsAttrValue& aEmptyOrOldValue);
  180. void DidChangeLengthList(uint8_t aAttrEnum,
  181. const nsAttrValue& aEmptyOrOldValue);
  182. void DidChangePointList(const nsAttrValue& aEmptyOrOldValue);
  183. void DidChangePathSegList(const nsAttrValue& aEmptyOrOldValue);
  184. void DidChangeTransformList(const nsAttrValue& aEmptyOrOldValue);
  185. void DidChangeString(uint8_t aAttrEnum) {}
  186. void DidChangeStringList(bool aIsConditionalProcessingAttribute,
  187. uint8_t aAttrEnum,
  188. const nsAttrValue& aEmptyOrOldValue);
  189. void DidAnimateLength(uint8_t aAttrEnum);
  190. void DidAnimateNumber(uint8_t aAttrEnum);
  191. void DidAnimateNumberPair(uint8_t aAttrEnum);
  192. void DidAnimateInteger(uint8_t aAttrEnum);
  193. void DidAnimateIntegerPair(uint8_t aAttrEnum);
  194. void DidAnimateAngle(uint8_t aAttrEnum);
  195. void DidAnimateBoolean(uint8_t aAttrEnum);
  196. void DidAnimateEnum(uint8_t aAttrEnum);
  197. void DidAnimateViewBox();
  198. void DidAnimatePreserveAspectRatio();
  199. void DidAnimateNumberList(uint8_t aAttrEnum);
  200. void DidAnimateLengthList(uint8_t aAttrEnum);
  201. void DidAnimatePointList();
  202. void DidAnimatePathSegList();
  203. void DidAnimateTransformList(int32_t aModType);
  204. void DidAnimateString(uint8_t aAttrEnum);
  205. enum {
  206. /**
  207. * Flag to indicate to GetAnimatedXxx() methods that the object being
  208. * requested should be allocated if it hasn't already been allocated, and
  209. * that the method should not return null. Only applicable to methods that
  210. * need to allocate the object that they return.
  211. */
  212. DO_ALLOCATE = 0x1
  213. };
  214. nsSVGLength2* GetAnimatedLength(const nsIAtom *aAttrName);
  215. void GetAnimatedLengthValues(float *aFirst, ...);
  216. void GetAnimatedNumberValues(float *aFirst, ...);
  217. void GetAnimatedIntegerValues(int32_t *aFirst, ...);
  218. SVGAnimatedNumberList* GetAnimatedNumberList(uint8_t aAttrEnum);
  219. SVGAnimatedNumberList* GetAnimatedNumberList(nsIAtom *aAttrName);
  220. void GetAnimatedLengthListValues(SVGUserUnitList *aFirst, ...);
  221. SVGAnimatedLengthList* GetAnimatedLengthList(uint8_t aAttrEnum);
  222. virtual SVGAnimatedPointList* GetAnimatedPointList() {
  223. return nullptr;
  224. }
  225. virtual SVGAnimatedPathSegList* GetAnimPathSegList() {
  226. // DOM interface 'SVGAnimatedPathData' (*inherited* by nsSVGPathElement)
  227. // has a member called 'animatedPathSegList' member, so we have a shorter
  228. // name so we don't get hidden by the GetAnimatedPathSegList declared by
  229. // NS_DECL_NSIDOMSVGANIMATEDPATHDATA.
  230. return nullptr;
  231. }
  232. /**
  233. * Get the nsSVGAnimatedTransformList for this element.
  234. *
  235. * Despite the fact that animated transform lists are used for a variety of
  236. * attributes, no SVG element uses more than one.
  237. *
  238. * It's relatively uncommon for elements to have their transform attribute
  239. * set, so to save memory the nsSVGAnimatedTransformList is not allocated until
  240. * the attribute is set/animated or its DOM wrapper is created. Callers that
  241. * require the nsSVGAnimatedTransformList to be allocated and for this method
  242. * to return non-null must pass the DO_ALLOCATE flag.
  243. */
  244. virtual nsSVGAnimatedTransformList* GetAnimatedTransformList(
  245. uint32_t aFlags = 0) {
  246. return nullptr;
  247. }
  248. virtual nsISMILAttr* GetAnimatedAttr(int32_t aNamespaceID, nsIAtom* aName) override;
  249. void AnimationNeedsResample();
  250. void FlushAnimations();
  251. virtual void RecompileScriptEventListeners() override;
  252. void GetStringBaseValue(uint8_t aAttrEnum, nsAString& aResult) const;
  253. void SetStringBaseValue(uint8_t aAttrEnum, const nsAString& aValue);
  254. virtual nsIAtom* GetPointListAttrName() const {
  255. return nullptr;
  256. }
  257. virtual nsIAtom* GetPathDataAttrName() const {
  258. return nullptr;
  259. }
  260. virtual nsIAtom* GetTransformListAttrName() const {
  261. return nullptr;
  262. }
  263. const nsAttrValue* GetAnimatedClassName() const
  264. {
  265. if (!mClassAttribute.IsAnimated()) {
  266. return nullptr;
  267. }
  268. return mClassAnimAttr;
  269. }
  270. virtual void ClearAnyCachedPath() {}
  271. virtual nsIDOMNode* AsDOMNode() final override { return this; }
  272. virtual bool IsTransformable() { return false; }
  273. // WebIDL
  274. mozilla::dom::SVGSVGElement* GetOwnerSVGElement();
  275. nsSVGElement* GetViewportElement();
  276. already_AddRefed<mozilla::dom::SVGAnimatedString> ClassName();
  277. virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse) override;
  278. protected:
  279. virtual JSObject* WrapNode(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
  280. #ifdef DEBUG
  281. // We define BeforeSetAttr here and mark it final to ensure it is NOT used
  282. // by SVG elements.
  283. // This is because we're not currently passing the correct value for aValue to
  284. // BeforeSetAttr since it would involve allocating extra SVG value types.
  285. // See the comment in nsSVGElement::WillChangeValue.
  286. virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
  287. const nsAttrValueOrString* aValue,
  288. bool aNotify) override final
  289. {
  290. return nsSVGElementBase::BeforeSetAttr(aNamespaceID, aName, aValue, aNotify);
  291. }
  292. #endif // DEBUG
  293. virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
  294. const nsAttrValue* aValue,
  295. const nsAttrValue* aOldValue,
  296. bool aNotify) override;
  297. virtual bool ParseAttribute(int32_t aNamespaceID, nsIAtom* aAttribute,
  298. const nsAString& aValue, nsAttrValue& aResult) override;
  299. static nsresult ReportAttributeParseFailure(nsIDocument* aDocument,
  300. nsIAtom* aAttribute,
  301. const nsAString& aValue);
  302. void UpdateContentStyleRule();
  303. void UpdateAnimatedContentStyleRule();
  304. mozilla::css::StyleRule* GetAnimatedContentStyleRule();
  305. nsAttrValue WillChangeValue(nsIAtom* aName);
  306. // aNewValue is set to the old value. This value may be invalid if
  307. // !StoresOwnData.
  308. void DidChangeValue(nsIAtom* aName, const nsAttrValue& aEmptyOrOldValue,
  309. nsAttrValue& aNewValue);
  310. void MaybeSerializeAttrBeforeRemoval(nsIAtom* aName, bool aNotify);
  311. static nsIAtom* GetEventNameForAttr(nsIAtom* aAttr);
  312. struct LengthInfo {
  313. nsIAtom** mName;
  314. float mDefaultValue;
  315. uint8_t mDefaultUnitType;
  316. uint8_t mCtxType;
  317. };
  318. struct LengthAttributesInfo {
  319. nsSVGLength2* mLengths;
  320. LengthInfo* mLengthInfo;
  321. uint32_t mLengthCount;
  322. LengthAttributesInfo(nsSVGLength2 *aLengths,
  323. LengthInfo *aLengthInfo,
  324. uint32_t aLengthCount) :
  325. mLengths(aLengths), mLengthInfo(aLengthInfo), mLengthCount(aLengthCount)
  326. {}
  327. void Reset(uint8_t aAttrEnum);
  328. };
  329. struct NumberInfo {
  330. nsIAtom** mName;
  331. float mDefaultValue;
  332. bool mPercentagesAllowed;
  333. };
  334. struct NumberAttributesInfo {
  335. nsSVGNumber2* mNumbers;
  336. NumberInfo* mNumberInfo;
  337. uint32_t mNumberCount;
  338. NumberAttributesInfo(nsSVGNumber2 *aNumbers,
  339. NumberInfo *aNumberInfo,
  340. uint32_t aNumberCount) :
  341. mNumbers(aNumbers), mNumberInfo(aNumberInfo), mNumberCount(aNumberCount)
  342. {}
  343. void Reset(uint8_t aAttrEnum);
  344. };
  345. struct NumberPairInfo {
  346. nsIAtom** mName;
  347. float mDefaultValue1;
  348. float mDefaultValue2;
  349. };
  350. struct NumberPairAttributesInfo {
  351. nsSVGNumberPair* mNumberPairs;
  352. NumberPairInfo* mNumberPairInfo;
  353. uint32_t mNumberPairCount;
  354. NumberPairAttributesInfo(nsSVGNumberPair *aNumberPairs,
  355. NumberPairInfo *aNumberPairInfo,
  356. uint32_t aNumberPairCount) :
  357. mNumberPairs(aNumberPairs), mNumberPairInfo(aNumberPairInfo),
  358. mNumberPairCount(aNumberPairCount)
  359. {}
  360. void Reset(uint8_t aAttrEnum);
  361. };
  362. struct IntegerInfo {
  363. nsIAtom** mName;
  364. int32_t mDefaultValue;
  365. };
  366. struct IntegerAttributesInfo {
  367. nsSVGInteger* mIntegers;
  368. IntegerInfo* mIntegerInfo;
  369. uint32_t mIntegerCount;
  370. IntegerAttributesInfo(nsSVGInteger *aIntegers,
  371. IntegerInfo *aIntegerInfo,
  372. uint32_t aIntegerCount) :
  373. mIntegers(aIntegers), mIntegerInfo(aIntegerInfo), mIntegerCount(aIntegerCount)
  374. {}
  375. void Reset(uint8_t aAttrEnum);
  376. };
  377. struct IntegerPairInfo {
  378. nsIAtom** mName;
  379. int32_t mDefaultValue1;
  380. int32_t mDefaultValue2;
  381. };
  382. struct IntegerPairAttributesInfo {
  383. nsSVGIntegerPair* mIntegerPairs;
  384. IntegerPairInfo* mIntegerPairInfo;
  385. uint32_t mIntegerPairCount;
  386. IntegerPairAttributesInfo(nsSVGIntegerPair *aIntegerPairs,
  387. IntegerPairInfo *aIntegerPairInfo,
  388. uint32_t aIntegerPairCount) :
  389. mIntegerPairs(aIntegerPairs), mIntegerPairInfo(aIntegerPairInfo),
  390. mIntegerPairCount(aIntegerPairCount)
  391. {}
  392. void Reset(uint8_t aAttrEnum);
  393. };
  394. struct AngleInfo {
  395. nsIAtom** mName;
  396. float mDefaultValue;
  397. uint8_t mDefaultUnitType;
  398. };
  399. struct AngleAttributesInfo {
  400. nsSVGAngle* mAngles;
  401. AngleInfo* mAngleInfo;
  402. uint32_t mAngleCount;
  403. AngleAttributesInfo(nsSVGAngle *aAngles,
  404. AngleInfo *aAngleInfo,
  405. uint32_t aAngleCount) :
  406. mAngles(aAngles), mAngleInfo(aAngleInfo), mAngleCount(aAngleCount)
  407. {}
  408. void Reset(uint8_t aAttrEnum);
  409. };
  410. struct BooleanInfo {
  411. nsIAtom** mName;
  412. bool mDefaultValue;
  413. };
  414. struct BooleanAttributesInfo {
  415. nsSVGBoolean* mBooleans;
  416. BooleanInfo* mBooleanInfo;
  417. uint32_t mBooleanCount;
  418. BooleanAttributesInfo(nsSVGBoolean *aBooleans,
  419. BooleanInfo *aBooleanInfo,
  420. uint32_t aBooleanCount) :
  421. mBooleans(aBooleans), mBooleanInfo(aBooleanInfo), mBooleanCount(aBooleanCount)
  422. {}
  423. void Reset(uint8_t aAttrEnum);
  424. };
  425. friend class nsSVGEnum;
  426. struct EnumInfo {
  427. nsIAtom** mName;
  428. nsSVGEnumMapping* mMapping;
  429. uint16_t mDefaultValue;
  430. };
  431. struct EnumAttributesInfo {
  432. nsSVGEnum* mEnums;
  433. EnumInfo* mEnumInfo;
  434. uint32_t mEnumCount;
  435. EnumAttributesInfo(nsSVGEnum *aEnums,
  436. EnumInfo *aEnumInfo,
  437. uint32_t aEnumCount) :
  438. mEnums(aEnums), mEnumInfo(aEnumInfo), mEnumCount(aEnumCount)
  439. {}
  440. void Reset(uint8_t aAttrEnum);
  441. };
  442. struct NumberListInfo {
  443. nsIAtom** mName;
  444. };
  445. struct NumberListAttributesInfo {
  446. SVGAnimatedNumberList* mNumberLists;
  447. NumberListInfo* mNumberListInfo;
  448. uint32_t mNumberListCount;
  449. NumberListAttributesInfo(SVGAnimatedNumberList *aNumberLists,
  450. NumberListInfo *aNumberListInfo,
  451. uint32_t aNumberListCount)
  452. : mNumberLists(aNumberLists)
  453. , mNumberListInfo(aNumberListInfo)
  454. , mNumberListCount(aNumberListCount)
  455. {}
  456. void Reset(uint8_t aAttrEnum);
  457. };
  458. struct LengthListInfo {
  459. nsIAtom** mName;
  460. uint8_t mAxis;
  461. /**
  462. * Flag to indicate whether appending zeros to the end of the list would
  463. * change the rendering of the SVG for the attribute in question. For x and
  464. * y on the <text> element this is true, but for dx and dy on <text> this
  465. * is false. This flag is fed down to SVGLengthListSMILType so it can
  466. * determine if it can sensibly animate from-to lists of different lengths,
  467. * which is desirable in the case of dx and dy.
  468. */
  469. bool mCouldZeroPadList;
  470. };
  471. struct LengthListAttributesInfo {
  472. SVGAnimatedLengthList* mLengthLists;
  473. LengthListInfo* mLengthListInfo;
  474. uint32_t mLengthListCount;
  475. LengthListAttributesInfo(SVGAnimatedLengthList *aLengthLists,
  476. LengthListInfo *aLengthListInfo,
  477. uint32_t aLengthListCount)
  478. : mLengthLists(aLengthLists)
  479. , mLengthListInfo(aLengthListInfo)
  480. , mLengthListCount(aLengthListCount)
  481. {}
  482. void Reset(uint8_t aAttrEnum);
  483. };
  484. struct StringInfo {
  485. nsIAtom** mName;
  486. int32_t mNamespaceID;
  487. bool mIsAnimatable;
  488. };
  489. struct StringAttributesInfo {
  490. nsSVGString* mStrings;
  491. StringInfo* mStringInfo;
  492. uint32_t mStringCount;
  493. StringAttributesInfo(nsSVGString *aStrings,
  494. StringInfo *aStringInfo,
  495. uint32_t aStringCount) :
  496. mStrings(aStrings), mStringInfo(aStringInfo), mStringCount(aStringCount)
  497. {}
  498. void Reset(uint8_t aAttrEnum);
  499. };
  500. friend class mozilla::DOMSVGStringList;
  501. struct StringListInfo {
  502. nsIAtom** mName;
  503. };
  504. struct StringListAttributesInfo {
  505. SVGStringList* mStringLists;
  506. StringListInfo* mStringListInfo;
  507. uint32_t mStringListCount;
  508. StringListAttributesInfo(SVGStringList *aStringLists,
  509. StringListInfo *aStringListInfo,
  510. uint32_t aStringListCount) :
  511. mStringLists(aStringLists), mStringListInfo(aStringListInfo),
  512. mStringListCount(aStringListCount)
  513. {}
  514. void Reset(uint8_t aAttrEnum);
  515. };
  516. virtual LengthAttributesInfo GetLengthInfo();
  517. virtual NumberAttributesInfo GetNumberInfo();
  518. virtual NumberPairAttributesInfo GetNumberPairInfo();
  519. virtual IntegerAttributesInfo GetIntegerInfo();
  520. virtual IntegerPairAttributesInfo GetIntegerPairInfo();
  521. virtual AngleAttributesInfo GetAngleInfo();
  522. virtual BooleanAttributesInfo GetBooleanInfo();
  523. virtual EnumAttributesInfo GetEnumInfo();
  524. // We assume all viewboxes and preserveAspectRatios are alike
  525. // so we don't need to wrap the class
  526. virtual nsSVGViewBox *GetViewBox();
  527. virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio();
  528. virtual NumberListAttributesInfo GetNumberListInfo();
  529. virtual LengthListAttributesInfo GetLengthListInfo();
  530. virtual StringAttributesInfo GetStringInfo();
  531. virtual StringListAttributesInfo GetStringListInfo();
  532. static nsSVGEnumMapping sSVGUnitTypesMap[];
  533. private:
  534. void UnsetAttrInternal(int32_t aNameSpaceID, nsIAtom* aAttribute,
  535. bool aNotify);
  536. nsSVGClass mClassAttribute;
  537. nsAutoPtr<nsAttrValue> mClassAnimAttr;
  538. RefPtr<mozilla::css::StyleRule> mContentStyleRule;
  539. };
  540. /**
  541. * A macro to implement the NS_NewSVGXXXElement() functions.
  542. */
  543. #define NS_IMPL_NS_NEW_SVG_ELEMENT(_elementName) \
  544. nsresult \
  545. NS_NewSVG##_elementName##Element(nsIContent **aResult, \
  546. already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) \
  547. { \
  548. RefPtr<nsSVG##_elementName##Element> it = \
  549. new nsSVG##_elementName##Element(aNodeInfo); \
  550. \
  551. nsresult rv = it->Init(); \
  552. \
  553. if (NS_FAILED(rv)) { \
  554. return rv; \
  555. } \
  556. \
  557. it.forget(aResult); \
  558. \
  559. return rv; \
  560. }
  561. #define NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(_elementName) \
  562. nsresult \
  563. NS_NewSVG##_elementName##Element(nsIContent **aResult, \
  564. already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) \
  565. { \
  566. RefPtr<mozilla::dom::SVG##_elementName##Element> it = \
  567. new mozilla::dom::SVG##_elementName##Element(aNodeInfo); \
  568. \
  569. nsresult rv = it->Init(); \
  570. \
  571. if (NS_FAILED(rv)) { \
  572. return rv; \
  573. } \
  574. \
  575. it.forget(aResult); \
  576. \
  577. return rv; \
  578. }
  579. #define NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT_CHECK_PARSER(_elementName) \
  580. nsresult \
  581. NS_NewSVG##_elementName##Element(nsIContent **aResult, \
  582. already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
  583. mozilla::dom::FromParser aFromParser) \
  584. { \
  585. RefPtr<mozilla::dom::SVG##_elementName##Element> it = \
  586. new mozilla::dom::SVG##_elementName##Element(aNodeInfo, aFromParser); \
  587. \
  588. nsresult rv = it->Init(); \
  589. \
  590. if (NS_FAILED(rv)) { \
  591. return rv; \
  592. } \
  593. \
  594. it.forget(aResult); \
  595. \
  596. return rv; \
  597. }
  598. // No unlinking, we'd need to null out the value pointer (the object it
  599. // points to is held by the element) and null-check it everywhere.
  600. #define NS_SVG_VAL_IMPL_CYCLE_COLLECTION(_val, _element) \
  601. NS_IMPL_CYCLE_COLLECTION_CLASS(_val) \
  602. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_val) \
  603. NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_element) \
  604. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \
  605. NS_IMPL_CYCLE_COLLECTION_UNLINK_0(_val)
  606. #define NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(_val, _element) \
  607. NS_IMPL_CYCLE_COLLECTION_CLASS(_val) \
  608. NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_val) \
  609. NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \
  610. NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
  611. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_val) \
  612. NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_element) \
  613. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \
  614. NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_val) \
  615. NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER \
  616. NS_IMPL_CYCLE_COLLECTION_TRACE_END
  617. #endif // __NS_SVGELEMENT_H__