tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SVGFEImageElement.h (5051B)


      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 "SVGAnimatedPreserveAspectRatio.h"
     11 #include "mozilla/dom/SVGFilters.h"
     12 #include "nsINode.h"
     13 
     14 nsresult NS_NewSVGFEImageElement(
     15    nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
     16 
     17 namespace mozilla {
     18 class SVGFEImageFrame;
     19 class SVGObserverUtils;
     20 
     21 namespace dom {
     22 
     23 using SVGFEImageElementBase = SVGFilterPrimitiveElement;
     24 
     25 class SVGFEImageElement final : public SVGFEImageElementBase,
     26                                public nsImageLoadingContent {
     27  friend class mozilla::SVGFEImageFrame;
     28  friend class mozilla::SVGObserverUtils;
     29 
     30 protected:
     31  friend nsresult(::NS_NewSVGFEImageElement(
     32      nsIContent** aResult,
     33      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
     34  explicit SVGFEImageElement(
     35      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
     36  virtual ~SVGFEImageElement();
     37  JSObject* WrapNode(JSContext* aCx,
     38                     JS::Handle<JSObject*> aGivenProto) override;
     39 
     40 public:
     41  bool SubregionIsUnionOfRegions() override { return false; }
     42 
     43  // interfaces:
     44  NS_DECL_ISUPPORTS_INHERITED
     45  NS_DECL_ADDSIZEOFEXCLUDINGTHIS
     46 
     47  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGFEImageElement,
     48                                           SVGFEImageElementBase)
     49 
     50  // EventTarget
     51  void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
     52 
     53  FilterPrimitiveDescription GetPrimitiveDescription(
     54      SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
     55      const nsTArray<bool>& aInputsAreTainted,
     56      nsTArray<RefPtr<SourceSurface>>& aInputImages) override;
     57  bool AttributeAffectsRendering(int32_t aNameSpaceID,
     58                                 nsAtom* aAttribute) const override;
     59  SVGAnimatedString& GetResultImageName() override {
     60    return mStringAttributes[RESULT];
     61  }
     62 
     63  // nsImageLoadingContent
     64  CORSMode GetCORSMode() override;
     65 
     66  bool OutputIsTainted(const nsTArray<bool>& aInputsAreTainted,
     67                       nsIPrincipal* aReferencePrincipal) override;
     68 
     69  // nsIContent
     70  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
     71 
     72  bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
     73                      const nsAString& aValue,
     74                      nsIPrincipal* aMaybeScriptedPrincipal,
     75                      nsAttrValue& aResult) override;
     76  void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
     77                    const nsAttrValue* aValue, const nsAttrValue* aOldValue,
     78                    nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
     79  nsresult BindToTree(BindContext&, nsINode& aParent) override;
     80  void UnbindFromTree(UnbindContext&) override;
     81  void DestroyContent() override;
     82 
     83  NS_DECL_IMGINOTIFICATIONOBSERVER
     84 
     85  // Override for nsIImageLoadingContent.
     86  NS_IMETHOD_(void) FrameCreated(nsIFrame* aFrame) override;
     87 
     88  void NodeInfoChanged(Document* aOldDoc) override;
     89 
     90  // WebIDL
     91  already_AddRefed<DOMSVGAnimatedString> Href();
     92  already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
     93  void GetCrossOrigin(nsAString& aCrossOrigin) {
     94    // Null for both missing and invalid defaults is ok, since we
     95    // always parse to an enum value, so we don't need an invalid
     96    // default, and we _want_ the missing default to be null.
     97    GetEnumAttr(nsGkAtoms::crossorigin, nullptr, aCrossOrigin);
     98  }
     99  void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError) {
    100    SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
    101  }
    102 
    103  void GetFetchPriority(nsAString& aFetchPriority) const;
    104  void SetFetchPriority(const nsAString& aFetchPriority) {
    105    SetAttr(nsGkAtoms::fetchpriority, aFetchPriority, IgnoreErrors());
    106  }
    107 
    108  void NotifyImageContentChanged();
    109 
    110 private:
    111  void DidAnimateAttribute(int32_t aNameSpaceID, nsAtom* aAttribute) override;
    112 
    113  void UpdateSrcURI();
    114 
    115  void LoadSelectedImage(bool aAlwaysLoad, bool aStopLazyLoading) override;
    116 
    117 protected:
    118  bool ProducesSRGB() override { return true; }
    119 
    120  SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio() override;
    121  StringAttributesInfo GetStringInfo() override;
    122 
    123  // Override for nsImageLoadingContent.
    124  nsIContent* AsContent() override { return this; }
    125 
    126  FetchPriority GetFetchPriorityForImage() const override {
    127    return Element::GetFetchPriority();
    128  }
    129 
    130  void HrefAsString(nsAString& aHref);
    131 
    132  nsCOMPtr<nsIURI> mSrcURI;
    133  RefPtr<nsISupports> mImageContentObserver;
    134 
    135  enum { RESULT, HREF, XLINK_HREF };
    136  SVGAnimatedString mStringAttributes[3];
    137  static StringInfo sStringInfo[3];
    138 
    139  SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
    140  uint16_t mImageAnimationMode = 0;
    141 };
    142 
    143 }  // namespace dom
    144 }  // namespace mozilla
    145 
    146 #endif  // DOM_SVG_SVGFEIMAGEELEMENT_H_