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 ////////////////////////////////////////////////////////////////////////
16 namespace mozilla::dom
{
20 class SVGRect final
: public nsWrapperCache
{
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
)
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
) {
33 MOZ_ASSERT(mType
== RectType::BaseValue
|| mType
== RectType::AnimValue
);
37 * Ctor for creating the objects returned by SVGSVGElement.createSVGRect(),
38 * which do not initially belong to an attribute.
40 explicit SVGRect(SVGSVGElement
* aSVGElement
);
43 * Ctor for all other non-attribute usage i.e getBBox, getExtentOfChar etc.
45 SVGRect(nsIContent
* aParent
, const gfx::Rect
& aRect
)
49 mType(RectType::CreatedValue
) {
53 JSObject
* WrapObject(JSContext
* aCx
,
54 JS::Handle
<JSObject
*> aGivenProto
) override
;
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 {
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
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
;
85 } // namespace mozilla::dom
87 #endif // DOM_SVG_SVGRECT_H_