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 mozilla_dom_SVGUseElement_h
8 #define mozilla_dom_SVGUseElement_h
10 #include "mozilla/dom/FromParser.h"
11 #include "mozilla/dom/IDTracker.h"
12 #include "nsStubMutationObserver.h"
13 #include "mozilla/dom/SVGGraphicsElement.h"
14 #include "nsSVGLength2.h"
15 #include "nsSVGString.h"
22 NS_NewSVGSVGElement(nsIContent
**aResult
,
23 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
24 mozilla::dom::FromParser aFromParser
);
25 nsresult
NS_NewSVGUseElement(nsIContent
**aResult
,
26 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
33 typedef SVGGraphicsElement SVGUseElementBase
;
35 class SVGUseElement final
: public SVGUseElementBase
,
36 public nsStubMutationObserver
38 friend class ::nsSVGUseFrame
;
40 friend nsresult (::NS_NewSVGUseElement(nsIContent
**aResult
,
41 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
));
42 explicit SVGUseElement(already_AddRefed
<mozilla::dom::NodeInfo
>& aNodeInfo
);
43 virtual ~SVGUseElement();
44 virtual JSObject
* WrapNode(JSContext
*cx
, JS::Handle
<JSObject
*> aGivenProto
) override
;
49 NS_DECL_ISUPPORTS_INHERITED
50 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGUseElement
, SVGUseElementBase
)
52 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
53 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
54 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
55 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
56 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
57 NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
59 // for nsSVGUseFrame's nsIAnonymousContentCreator implementation.
60 already_AddRefed
<nsIContent
> CreateAnonymousContent();
62 // nsSVGElement specializations:
63 virtual gfxMatrix
PrependLocalTransformsTo(
64 const gfxMatrix
&aMatrix
,
65 SVGTransformTypes aWhich
= eAllTransforms
) const override
;
66 virtual bool HasValidDimensions() const override
;
68 // nsIContent interface
69 virtual nsresult
Clone(mozilla::dom::NodeInfo
*aNodeInfo
, nsINode
**aResult
,
70 bool aPreallocateChildren
) const override
;
71 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* aAttribute
) const override
;
74 already_AddRefed
<SVGAnimatedString
> Href();
75 already_AddRefed
<SVGAnimatedLength
> X();
76 already_AddRefed
<SVGAnimatedLength
> Y();
77 already_AddRefed
<SVGAnimatedLength
> Width();
78 already_AddRefed
<SVGAnimatedLength
> Height();
80 nsIURI
* GetSourceDocURI();
81 URLExtraData
* GetContentURLData() const { return mContentURLData
; }
85 * Helper that provides a reference to the element with the ID that is
86 * referenced by the 'use' element's 'href' attribute, and that will update
87 * the 'use' element if the element that that ID identifies changes to a
88 * different element (or none).
90 class ElementTracker final
: public IDTracker
{
92 explicit ElementTracker(SVGUseElement
* aOwningUseElement
)
93 : mOwningUseElement(aOwningUseElement
)
96 virtual void ElementChanged(Element
* aFrom
, Element
* aTo
) override
{
97 IDTracker::ElementChanged(aFrom
, aTo
);
99 aFrom
->RemoveMutationObserver(mOwningUseElement
);
101 mOwningUseElement
->TriggerReclone();
104 SVGUseElement
* mOwningUseElement
;
107 nsSVGUseFrame
* GetFrame() const;
109 virtual LengthAttributesInfo
GetLengthInfo() override
;
110 virtual StringAttributesInfo
GetStringInfo() override
;
113 * Returns true if our width and height should be used, or false if they
114 * should be ignored. As per the spec, this depends on the type of the
115 * element that we're referencing.
117 bool OurWidthAndHeightAreUsed() const;
118 void SyncWidthOrHeight(nsAtom
*aName
);
120 void TriggerReclone();
123 enum { ATTR_X
, ATTR_Y
, ATTR_WIDTH
, ATTR_HEIGHT
};
124 nsSVGLength2 mLengthAttributes
[4];
125 static LengthInfo sLengthInfo
[4];
127 enum { HREF
, XLINK_HREF
};
128 nsSVGString mStringAttributes
[2];
129 static StringInfo sStringInfo
[2];
131 nsCOMPtr
<nsIContent
> mOriginal
; // if we've been cloned, our "real" copy
132 ElementTracker mReferencedElementTracker
;
133 RefPtr
<URLExtraData
> mContentURLData
; // URL data for its anonymous content
137 } // namespace mozilla
139 #endif // mozilla_dom_SVGUseElement_h