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/. */
6 
7 #ifndef DOM_SVG_SVGFEIMAGEELEMENT_H_
8 #define DOM_SVG_SVGFEIMAGEELEMENT_H_
9 
10 #include "mozilla/dom/SVGFilters.h"
11 #include "SVGAnimatedPreserveAspectRatio.h"
12 
13 nsresult NS_NewSVGFEImageElement(
14     nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
15 
16 namespace mozilla {
17 class SVGFEImageFrame;
18 
19 namespace dom {
20 
21 using SVGFEImageElementBase = SVGFE;
22 
23 class SVGFEImageElement final : public SVGFEImageElementBase,
24                                 public nsImageLoadingContent {
25   friend class mozilla::SVGFEImageFrame;
26 
27  protected:
28   friend nsresult(::NS_NewSVGFEImageElement(
29       nsIContent** aResult,
30       already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
31   explicit SVGFEImageElement(
32       already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
33   virtual ~SVGFEImageElement();
34   virtual JSObject* WrapNode(JSContext* aCx,
35                              JS::Handle<JSObject*> aGivenProto) override;
36 
37  public:
SubregionIsUnionOfRegions()38   virtual bool SubregionIsUnionOfRegions() override { return false; }
39 
40   // interfaces:
41   NS_DECL_ISUPPORTS_INHERITED
42 
43   // EventTarget
44   virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
45 
46   virtual FilterPrimitiveDescription GetPrimitiveDescription(
47       SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
48       const nsTArray<bool>& aInputsAreTainted,
49       nsTArray<RefPtr<SourceSurface>>& aInputImages) override;
50   virtual bool AttributeAffectsRendering(int32_t aNameSpaceID,
51                                          nsAtom* aAttribute) const override;
GetResultImageName()52   virtual SVGAnimatedString& GetResultImageName() override {
53     return mStringAttributes[RESULT];
54   }
55   virtual bool OutputIsTainted(const nsTArray<bool>& aInputsAreTainted,
56                                nsIPrincipal* aReferencePrincipal) override;
57 
58   // nsIContent
59   NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
60 
61   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
62 
63   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
64                                 const nsAttrValue* aValue,
65                                 const nsAttrValue* aOldValue,
66                                 nsIPrincipal* aSubjectPrincipal,
67                                 bool aNotify) override;
68   virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
69   virtual void UnbindFromTree(bool aNullParent) override;
70   virtual EventStates IntrinsicState() const override;
71   virtual void DestroyContent() override;
72 
73   NS_DECL_IMGINOTIFICATIONOBSERVER
74 
75   // Override for nsIImageLoadingContent.
76   NS_IMETHOD_(void) FrameCreated(nsIFrame* aFrame) override;
77 
78   void MaybeLoadSVGImage();
79 
80   // WebIDL
81   already_AddRefed<DOMSVGAnimatedString> Href();
82   already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
83 
84  private:
85   nsresult LoadSVGImage(bool aForce, bool aNotify);
86   bool ShouldLoadImage() const;
87 
88  protected:
ProducesSRGB()89   virtual bool ProducesSRGB() override { return true; }
90 
91   virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
92       override;
93   virtual StringAttributesInfo GetStringInfo() override;
94 
95   // Override for nsImageLoadingContent.
AsContent()96   nsIContent* AsContent() override { return this; }
97 
98   enum { RESULT, HREF, XLINK_HREF };
99   SVGAnimatedString mStringAttributes[3];
100   static StringInfo sStringInfo[3];
101 
102   SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
103   uint16_t mImageAnimationMode;
104 };
105 
106 }  // namespace dom
107 }  // namespace mozilla
108 
109 #endif  // DOM_SVG_SVGFEIMAGEELEMENT_H_
110