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_SVGIMAGEELEMENT_H_
8 #define DOM_SVG_SVGIMAGEELEMENT_H_
10 #include "nsImageLoadingContent.h"
11 #include "mozilla/dom/SVGAnimatedLength.h"
12 #include "mozilla/dom/SVGAnimatedString.h"
13 #include "mozilla/dom/SVGGeometryElement.h"
14 #include "mozilla/dom/SVGAnimatedPreserveAspectRatio.h"
15 #include "mozilla/gfx/2D.h"
17 nsresult
NS_NewSVGImageElement(
18 nsIContent
** aResult
, already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
24 class DOMSVGAnimatedPreserveAspectRatio
;
26 using SVGImageElementBase
= SVGGraphicsElement
;
28 class SVGImageElement final
: public SVGImageElementBase
,
29 public nsImageLoadingContent
{
30 friend class mozilla::SVGImageFrame
;
33 explicit SVGImageElement(
34 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
35 virtual ~SVGImageElement();
36 JSObject
* WrapNode(JSContext
* aCx
,
37 JS::Handle
<JSObject
*> aGivenProto
) override
;
38 friend nsresult(::NS_NewSVGImageElement(
40 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
));
45 NS_DECL_ISUPPORTS_INHERITED
48 void AsyncEventRunning(AsyncEventDispatcher
* aEvent
) override
;
50 // nsImageLoadingContent interface
51 CORSMode
GetCORSMode() override
;
53 // nsIContent interface
54 bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
55 const nsAString
& aValue
,
56 nsIPrincipal
* aMaybeScriptedPrincipal
,
57 nsAttrValue
& aResult
) override
;
58 void AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
59 const nsAttrValue
* aValue
, const nsAttrValue
* aOldValue
,
60 nsIPrincipal
* aSubjectPrincipal
, bool aNotify
) override
;
62 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
63 void UnbindFromTree(bool aNullParent
) override
;
65 ElementState
IntrinsicState() const override
;
67 void DestroyContent() override
;
69 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* name
) const override
;
71 // SVGSVGElement methods:
72 bool HasValidDimensions() const override
;
74 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
76 void MaybeLoadSVGImage();
79 already_AddRefed
<DOMSVGAnimatedLength
> X();
80 already_AddRefed
<DOMSVGAnimatedLength
> Y();
81 already_AddRefed
<DOMSVGAnimatedLength
> Width();
82 already_AddRefed
<DOMSVGAnimatedLength
> Height();
83 already_AddRefed
<DOMSVGAnimatedPreserveAspectRatio
> PreserveAspectRatio();
84 already_AddRefed
<DOMSVGAnimatedString
> Href();
85 void GetCrossOrigin(nsAString
& aCrossOrigin
) {
86 // Null for both missing and invalid defaults is ok, since we
87 // always parse to an enum value, so we don't need an invalid
88 // default, and we _want_ the missing default to be null.
89 GetEnumAttr(nsGkAtoms::crossorigin
, nullptr, aCrossOrigin
);
91 void SetCrossOrigin(const nsAString
& aCrossOrigin
, ErrorResult
& aError
) {
92 SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin
, aCrossOrigin
, aError
);
95 void SetDecoding(const nsAString
& aDecoding
, ErrorResult
& aError
) {
96 SetAttr(nsGkAtoms::decoding
, aDecoding
, aError
);
98 void GetDecoding(nsAString
& aValue
);
100 already_AddRefed
<Promise
> Decode(ErrorResult
& aRv
);
102 static nsCSSPropertyID
GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum
);
104 gfx::Rect
GeometryBounds(const gfx::Matrix
& aToBoundsSpace
);
107 nsresult
LoadSVGImage(bool aForce
, bool aNotify
);
108 bool ShouldLoadImage() const;
110 LengthAttributesInfo
GetLengthInfo() override
;
111 SVGAnimatedPreserveAspectRatio
* GetAnimatedPreserveAspectRatio() override
;
112 StringAttributesInfo
GetStringInfo() override
;
114 // Override for nsImageLoadingContent.
115 nsIContent
* AsContent() override
{ return this; }
117 enum { ATTR_X
, ATTR_Y
, ATTR_WIDTH
, ATTR_HEIGHT
};
118 SVGAnimatedLength mLengthAttributes
[4];
119 static LengthInfo sLengthInfo
[4];
121 SVGAnimatedPreserveAspectRatio mPreserveAspectRatio
;
123 enum { HREF
, XLINK_HREF
};
124 SVGAnimatedString mStringAttributes
[2];
125 static StringInfo sStringInfo
[2];
129 } // namespace mozilla
131 #endif // DOM_SVG_SVGIMAGEELEMENT_H_