1 /* -*- Mode: C++; tab-width: 2; 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/. */
6 #ifndef mozilla_dom_SVGUseElement_h
7 #define mozilla_dom_SVGUseElement_h
9 #include "mozilla/dom/FromParser.h"
10 #include "nsReferencedElement.h"
11 #include "nsStubMutationObserver.h"
12 #include "mozilla/dom/SVGGraphicsElement.h"
13 #include "nsSVGLength2.h"
14 #include "nsSVGString.h"
21 NS_NewSVGSVGElement(nsIContent
**aResult
,
22 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
23 mozilla::dom::FromParser aFromParser
);
24 nsresult
NS_NewSVGUseElement(nsIContent
**aResult
,
25 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
30 typedef SVGGraphicsElement SVGUseElementBase
;
32 class SVGUseElement MOZ_FINAL
: public SVGUseElementBase
,
33 public nsStubMutationObserver
35 friend class ::nsSVGUseFrame
;
37 friend nsresult (::NS_NewSVGUseElement(nsIContent
**aResult
,
38 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
));
39 explicit SVGUseElement(already_AddRefed
<mozilla::dom::NodeInfo
>& aNodeInfo
);
40 virtual ~SVGUseElement();
41 virtual JSObject
* WrapNode(JSContext
*cx
) MOZ_OVERRIDE
;
46 NS_DECL_ISUPPORTS_INHERITED
47 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGUseElement
, SVGUseElementBase
)
49 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
50 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
51 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
52 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
53 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
54 NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
56 // for nsSVGUseFrame's nsIAnonymousContentCreator implementation.
57 nsIContent
* CreateAnonymousContent();
58 nsIContent
* GetAnonymousContent() const { return mClone
; }
59 void DestroyAnonymousContent();
61 // nsSVGElement specializations:
62 virtual gfxMatrix
PrependLocalTransformsTo(const gfxMatrix
&aMatrix
,
63 TransformTypes aWhich
= eAllTransforms
) const MOZ_OVERRIDE
;
64 virtual bool HasValidDimensions() const MOZ_OVERRIDE
;
66 // nsIContent interface
67 virtual nsresult
Clone(mozilla::dom::NodeInfo
*aNodeInfo
, nsINode
**aResult
) const MOZ_OVERRIDE
;
68 NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom
* aAttribute
) const MOZ_OVERRIDE
;
71 already_AddRefed
<SVGAnimatedString
> Href();
72 already_AddRefed
<SVGAnimatedLength
> X();
73 already_AddRefed
<SVGAnimatedLength
> Y();
74 already_AddRefed
<SVGAnimatedLength
> Width();
75 already_AddRefed
<SVGAnimatedLength
> Height();
78 class SourceReference
: public nsReferencedElement
{
80 explicit SourceReference(SVGUseElement
* aContainer
) : mContainer(aContainer
) {}
82 virtual void ElementChanged(Element
* aFrom
, Element
* aTo
) MOZ_OVERRIDE
{
83 nsReferencedElement::ElementChanged(aFrom
, aTo
);
85 aFrom
->RemoveMutationObserver(mContainer
);
87 mContainer
->TriggerReclone();
90 SVGUseElement
* mContainer
;
93 virtual LengthAttributesInfo
GetLengthInfo() MOZ_OVERRIDE
;
94 virtual StringAttributesInfo
GetStringInfo() MOZ_OVERRIDE
;
97 * Returns true if our width and height should be used, or false if they
98 * should be ignored. As per the spec, this depends on the type of the
99 * element that we're referencing.
101 bool OurWidthAndHeightAreUsed() const;
102 void SyncWidthOrHeight(nsIAtom
*aName
);
104 void TriggerReclone();
107 enum { ATTR_X
, ATTR_Y
, ATTR_WIDTH
, ATTR_HEIGHT
};
108 nsSVGLength2 mLengthAttributes
[4];
109 static LengthInfo sLengthInfo
[4];
112 nsSVGString mStringAttributes
[1];
113 static StringInfo sStringInfo
[1];
115 nsCOMPtr
<nsIContent
> mOriginal
; // if we've been cloned, our "real" copy
116 nsCOMPtr
<nsIContent
> mClone
; // cloned tree
117 SourceReference mSource
; // observed element
121 } // namespace mozilla
123 #endif // mozilla_dom_SVGUseElement_h