Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGImageElement.h
blob591179b3a9df503c5f3f250e76c84b23e5f203c6
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);
20 namespace mozilla {
21 class SVGImageFrame;
23 namespace dom {
24 class DOMSVGAnimatedPreserveAspectRatio;
26 using SVGImageElementBase = SVGGraphicsElement;
28 class SVGImageElement final : public SVGImageElementBase,
29 public nsImageLoadingContent {
30 friend class mozilla::SVGImageFrame;
32 protected:
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(
39 nsIContent** aResult,
40 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
42 public:
43 // interfaces:
45 NS_DECL_ISUPPORTS_INHERITED
47 // EventTarget
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(UnbindContext&) override;
65 void DestroyContent() override;
67 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* name) const override;
69 // SVGSVGElement methods:
70 bool HasValidDimensions() const override;
72 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
74 void MaybeLoadSVGImage();
76 // WebIDL
77 already_AddRefed<DOMSVGAnimatedLength> X();
78 already_AddRefed<DOMSVGAnimatedLength> Y();
79 already_AddRefed<DOMSVGAnimatedLength> Width();
80 already_AddRefed<DOMSVGAnimatedLength> Height();
81 already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
82 already_AddRefed<DOMSVGAnimatedString> Href();
83 void GetCrossOrigin(nsAString& aCrossOrigin) {
84 // Null for both missing and invalid defaults is ok, since we
85 // always parse to an enum value, so we don't need an invalid
86 // default, and we _want_ the missing default to be null.
87 GetEnumAttr(nsGkAtoms::crossorigin, nullptr, aCrossOrigin);
89 void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError) {
90 SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
93 void SetDecoding(const nsAString& aDecoding, ErrorResult& aError) {
94 SetAttr(nsGkAtoms::decoding, aDecoding, aError);
96 void GetDecoding(nsAString& aValue);
98 already_AddRefed<Promise> Decode(ErrorResult& aRv);
100 static nsCSSPropertyID GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum);
102 gfx::Rect GeometryBounds(const gfx::Matrix& aToBoundsSpace);
104 protected:
105 void DidAnimateAttribute(int32_t aNameSpaceID, nsAtom* aAttribute) override;
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];
128 } // namespace dom
129 } // namespace mozilla
131 #endif // DOM_SVG_SVGIMAGEELEMENT_H_