tor-browser

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

SVGRect.h (2616B)


      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_SVGRECT_H_
      8 #define DOM_SVG_SVGRECT_H_
      9 
     10 #include "mozilla/dom/SVGElement.h"
     11 #include "mozilla/gfx/Rect.h"
     12 
     13 ////////////////////////////////////////////////////////////////////////
     14 // SVGRect class
     15 
     16 namespace mozilla::dom {
     17 
     18 class SVGSVGElement;
     19 
     20 class SVGRect final : public nsWrapperCache {
     21 public:
     22  enum class RectType : uint8_t { BaseValue, AnimValue, CreatedValue };
     23 
     24  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGRect)
     25  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(SVGRect)
     26 
     27  /**
     28   * Generic ctor for objects that are created for an attribute.
     29   */
     30  SVGRect(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement, RectType aType)
     31      : mVal(aVal), mParent(aSVGElement), mType(aType) {
     32    MOZ_ASSERT(mParent);
     33    MOZ_ASSERT(mType == RectType::BaseValue || mType == RectType::AnimValue);
     34  }
     35 
     36  /**
     37   * Ctor for creating the objects returned by SVGSVGElement.createSVGRect(),
     38   * which do not initially belong to an attribute.
     39   */
     40  explicit SVGRect(SVGSVGElement* aSVGElement);
     41 
     42  /**
     43   * Ctor for all other non-attribute usage i.e getBBox, getExtentOfChar etc.
     44   */
     45  SVGRect(nsIContent* aParent, const gfx::Rect& aRect)
     46      : mVal(nullptr),
     47        mRect(aRect),
     48        mParent(aParent),
     49        mType(RectType::CreatedValue) {
     50    MOZ_ASSERT(mParent);
     51  }
     52 
     53  JSObject* WrapObject(JSContext* aCx,
     54                       JS::Handle<JSObject*> aGivenProto) override;
     55 
     56  float X();
     57  float Y();
     58  float Width();
     59  float Height();
     60 
     61  void SetX(float aX, mozilla::ErrorResult& aRv);
     62  void SetY(float aY, mozilla::ErrorResult& aRv);
     63  void SetWidth(float aWidth, mozilla::ErrorResult& aRv);
     64  void SetHeight(float aHeight, mozilla::ErrorResult& aRv);
     65 
     66  nsIContent* GetParentObject() const {
     67    MOZ_ASSERT(mParent);
     68    return mParent;
     69  }
     70 
     71 private:
     72  virtual ~SVGRect();
     73 
     74  // If we're actually representing a viewBox rect then our value
     75  // will come from that element's viewBox attribute's value.
     76  SVGAnimatedViewBox* mVal;  // kept alive because it belongs to content
     77  gfx::Rect mRect;
     78 
     79  // If mType is AnimValue or BaseValue this will be an element that
     80  // has a viewBox, otherwise it could be any nsIContent.
     81  RefPtr<nsIContent> mParent;
     82  const RectType mType;
     83 };
     84 
     85 }  // namespace mozilla::dom
     86 
     87 #endif  // DOM_SVG_SVGRECT_H_