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 MOZILLA_DOMQUAD_H_
8 #define MOZILLA_DOMQUAD_H_
12 #include "js/TypeDecls.h"
13 #include "mozilla/AlreadyAddRefed.h"
14 #include "mozilla/Assertions.h"
15 #include "mozilla/RefPtr.h"
17 #include "nsCycleCollectionParticipant.h"
18 #include "nsISupports.h"
19 #include "nsWrapperCache.h"
22 class nsIGlobalObject
;
24 struct JSStructuredCloneReader
;
25 struct JSStructuredCloneWriter
;
30 class DOMRectReadOnly
;
37 class DOMQuad final
: public nsWrapperCache
{
41 DOMQuad(nsISupports
* aParent
, CSSPoint aPoints
[4]);
42 explicit DOMQuad(nsISupports
* aParent
);
44 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMQuad
)
45 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMQuad
)
47 nsISupports
* GetParentObject() const { return mParent
; }
48 virtual JSObject
* WrapObject(JSContext
* aCx
,
49 JS::Handle
<JSObject
*> aGivenProto
) override
;
51 static already_AddRefed
<DOMQuad
> FromRect(const GlobalObject
& aGlobal
,
52 const DOMRectInit
& aInit
);
54 static already_AddRefed
<DOMQuad
> FromQuad(const GlobalObject
& aGlobal
,
55 const DOMQuadInit
& aInit
);
57 static already_AddRefed
<DOMQuad
> Constructor(const GlobalObject
& aGlobal
,
58 const DOMPointInit
& aP1
,
59 const DOMPointInit
& aP2
,
60 const DOMPointInit
& aP3
,
61 const DOMPointInit
& aP4
);
62 static already_AddRefed
<DOMQuad
> Constructor(const GlobalObject
& aGlobal
,
63 const DOMRectReadOnly
& aRect
);
65 already_AddRefed
<DOMRectReadOnly
> GetBounds() const;
66 DOMPoint
* P1() const { return mPoints
[0]; }
67 DOMPoint
* P2() const { return mPoints
[1]; }
68 DOMPoint
* P3() const { return mPoints
[2]; }
69 DOMPoint
* P4() const { return mPoints
[3]; }
71 DOMPoint
* Point(uint32_t aIndex
) const { return mPoints
[aIndex
]; }
73 bool WriteStructuredClone(JSContext
* aCx
,
74 JSStructuredCloneWriter
* aWriter
) const;
76 static already_AddRefed
<DOMQuad
> ReadStructuredClone(
77 JSContext
* aCx
, nsIGlobalObject
* aGlobal
,
78 JSStructuredCloneReader
* aReader
);
81 void GetHorizontalMinMax(double* aX1
, double* aX2
) const;
82 void GetVerticalMinMax(double* aY1
, double* aY2
) const;
84 nsCOMPtr
<nsISupports
> mParent
;
85 RefPtr
<DOMPoint
> mPoints
[4];
89 } // namespace mozilla
91 #endif /*MOZILLA_DOMRECT_H_*/