tor-browser

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

SVGImageElement.h (4930B)


      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_SVGIMAGEELEMENT_H_
      8 #define DOM_SVG_SVGIMAGEELEMENT_H_
      9 
     10 #include "mozilla/dom/SVGAnimatedLength.h"
     11 #include "mozilla/dom/SVGAnimatedPreserveAspectRatio.h"
     12 #include "mozilla/dom/SVGAnimatedString.h"
     13 #include "mozilla/dom/SVGGeometryElement.h"
     14 #include "mozilla/gfx/2D.h"
     15 #include "nsINode.h"
     16 #include "nsImageLoadingContent.h"
     17 
     18 nsresult NS_NewSVGImageElement(
     19    nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
     20 
     21 namespace mozilla {
     22 class SVGImageFrame;
     23 
     24 namespace dom {
     25 class DOMSVGAnimatedPreserveAspectRatio;
     26 
     27 using SVGImageElementBase = SVGGraphicsElement;
     28 
     29 class SVGImageElement final : public SVGImageElementBase,
     30                              public nsImageLoadingContent {
     31  friend class mozilla::SVGImageFrame;
     32 
     33 protected:
     34  explicit SVGImageElement(
     35      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
     36  virtual ~SVGImageElement();
     37  JSObject* WrapNode(JSContext* aCx,
     38                     JS::Handle<JSObject*> aGivenProto) override;
     39  friend nsresult(::NS_NewSVGImageElement(
     40      nsIContent** aResult,
     41      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
     42 
     43 public:
     44  // interfaces:
     45 
     46  NS_DECL_ISUPPORTS_INHERITED
     47  NS_DECL_ADDSIZEOFEXCLUDINGTHIS
     48 
     49  // EventTarget
     50  void AsyncEventRunning(AsyncEventDispatcher* aEvent) override;
     51 
     52  // nsImageLoadingContent interface
     53  CORSMode GetCORSMode() override;
     54 
     55  // nsIContent interface
     56  bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
     57                      const nsAString& aValue,
     58                      nsIPrincipal* aMaybeScriptedPrincipal,
     59                      nsAttrValue& aResult) override;
     60  void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
     61                    const nsAttrValue* aValue, const nsAttrValue* aOldValue,
     62                    nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
     63 
     64  nsresult BindToTree(BindContext&, nsINode& aParent) override;
     65  void UnbindFromTree(UnbindContext&) override;
     66 
     67  void DestroyContent() override;
     68 
     69  NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* name) const override;
     70 
     71  // SVGSVGElement methods:
     72  bool HasValidDimensions() const override;
     73 
     74  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
     75 
     76  void NodeInfoChanged(Document* aOldDoc) override;
     77 
     78  // WebIDL
     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);
     90  }
     91  void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& aError) {
     92    SetOrRemoveNullableStringAttr(nsGkAtoms::crossorigin, aCrossOrigin, aError);
     93  }
     94 
     95  void GetFetchPriority(nsAString& aFetchPriority) const;
     96  void SetFetchPriority(const nsAString& aFetchPriority) {
     97    SetAttr(nsGkAtoms::fetchpriority, aFetchPriority, IgnoreErrors());
     98  }
     99 
    100  void SetDecoding(const nsAString& aDecoding, ErrorResult& aError) {
    101    SetAttr(nsGkAtoms::decoding, aDecoding, aError);
    102  }
    103  void GetDecoding(nsAString& aValue);
    104 
    105  already_AddRefed<Promise> Decode(ErrorResult& aRv);
    106 
    107  static NonCustomCSSPropertyId GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum);
    108 
    109  gfx::Rect GeometryBounds(const gfx::Matrix& aToBoundsSpace);
    110 
    111 protected:
    112  void DidAnimateAttribute(int32_t aNameSpaceID, nsAtom* aAttribute) override;
    113 
    114  void UpdateSrcURI();
    115 
    116  void LoadSelectedImage(bool aAlwaysLoad, bool aStopLazyLoading) override;
    117 
    118  LengthAttributesInfo GetLengthInfo() override;
    119  SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio() override;
    120  StringAttributesInfo GetStringInfo() override;
    121 
    122  // Override for nsImageLoadingContent.
    123  nsIContent* AsContent() override { return this; }
    124 
    125  FetchPriority GetFetchPriorityForImage() const override {
    126    return Element::GetFetchPriority();
    127  }
    128 
    129  nsCOMPtr<nsIURI> mSrcURI;
    130 
    131  enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
    132  SVGAnimatedLength mLengthAttributes[4];
    133  static LengthInfo sLengthInfo[4];
    134 
    135  SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
    136 
    137  enum { HREF, XLINK_HREF };
    138  SVGAnimatedString mStringAttributes[2];
    139  static StringInfo sStringInfo[2];
    140 };
    141 
    142 }  // namespace dom
    143 }  // namespace mozilla
    144 
    145 #endif  // DOM_SVG_SVGIMAGEELEMENT_H_