Bug 1805294 [wpt PR 37463] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / dom / svg / SVGRect.h
blob924dc0ba9c5be8b5a0f6272f8cce4605da623761
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_SVGRECT_H_
8 #define DOM_SVG_SVGRECT_H_
10 #include "mozilla/dom/SVGElement.h"
11 #include "mozilla/gfx/Rect.h"
13 ////////////////////////////////////////////////////////////////////////
14 // SVGRect class
16 namespace mozilla::dom {
18 class SVGSVGElement;
20 class SVGRect final : public nsWrapperCache {
21 public:
22 enum class RectType : uint8_t { BaseValue, AnimValue, CreatedValue };
24 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGRect)
25 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(SVGRect)
27 /**
28 * Generic ctor for objects that are created for an attribute.
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);
36 /**
37 * Ctor for creating the objects returned by SVGSVGElement.createSVGRect(),
38 * which do not initially belong to an attribute.
40 explicit SVGRect(SVGSVGElement* aSVGElement);
42 /**
43 * Ctor for all other non-attribute usage i.e getBBox, getExtentOfChar etc.
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);
53 JSObject* WrapObject(JSContext* aCx,
54 JS::Handle<JSObject*> aGivenProto) override;
56 float X();
57 float Y();
58 float Width();
59 float Height();
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);
66 nsIContent* GetParentObject() const {
67 MOZ_ASSERT(mParent);
68 return mParent;
71 private:
72 virtual ~SVGRect();
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;
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;
85 } // namespace mozilla::dom
87 #endif // DOM_SVG_SVGRECT_H_