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_DOMPOINT_H_
8 #define MOZILLA_DOMPOINT_H_
10 #include "js/TypeDecls.h"
11 #include "mozilla/AlreadyAddRefed.h"
12 #include "mozilla/Assertions.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "nsISupports.h"
16 #include "nsWrapperCache.h"
19 class nsIGlobalObject
;
21 struct JSStructuredCloneReader
;
22 struct JSStructuredCloneWriter
;
34 class DOMPointReadOnly
: public nsWrapperCache
{
36 explicit DOMPointReadOnly(nsISupports
* aParent
, double aX
= 0.0,
37 double aY
= 0.0, double aZ
= 0.0, double aW
= 1.0)
38 : mParent(aParent
), mX(aX
), mY(aY
), mZ(aZ
), mW(aW
) {}
40 static already_AddRefed
<DOMPointReadOnly
> FromPoint(
41 const GlobalObject
& aGlobal
, const DOMPointInit
& aParams
);
42 static already_AddRefed
<DOMPointReadOnly
> Constructor(
43 const GlobalObject
& aGlobal
, double aX
, double aY
, double aZ
, double aW
);
45 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMPointReadOnly
)
46 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMPointReadOnly
)
48 double X() const { return mX
; }
49 double Y() const { return mY
; }
50 double Z() const { return mZ
; }
51 double W() const { return mW
; }
53 already_AddRefed
<DOMPoint
> MatrixTransform(const DOMMatrixInit
& aInit
,
56 nsISupports
* GetParentObject() const { return mParent
; }
57 virtual JSObject
* WrapObject(JSContext
* aCx
,
58 JS::Handle
<JSObject
*> aGivenProto
) override
;
60 bool WriteStructuredClone(JSContext
* aCx
,
61 JSStructuredCloneWriter
* aWriter
) const;
63 static already_AddRefed
<DOMPointReadOnly
> ReadStructuredClone(
64 JSContext
* aCx
, nsIGlobalObject
* aGlobal
,
65 JSStructuredCloneReader
* aReader
);
68 virtual ~DOMPointReadOnly() = default;
70 // Shared implementation of ReadStructuredClone for DOMPoint and
72 bool ReadStructuredClone(JSStructuredCloneReader
* aReader
);
74 nsCOMPtr
<nsISupports
> mParent
;
75 double mX
, mY
, mZ
, mW
;
78 class DOMPoint final
: public DOMPointReadOnly
{
80 explicit DOMPoint(nsISupports
* aParent
, double aX
= 0.0, double aY
= 0.0,
81 double aZ
= 0.0, double aW
= 1.0)
82 : DOMPointReadOnly(aParent
, aX
, aY
, aZ
, aW
) {}
84 static already_AddRefed
<DOMPoint
> FromPoint(const GlobalObject
& aGlobal
,
85 const DOMPointInit
& aParams
);
86 static already_AddRefed
<DOMPoint
> Constructor(const GlobalObject
& aGlobal
,
87 double aX
, double aY
, double aZ
,
90 virtual JSObject
* WrapObject(JSContext
* aCx
,
91 JS::Handle
<JSObject
*> aGivenProto
) override
;
93 static already_AddRefed
<DOMPoint
> ReadStructuredClone(
94 JSContext
* aCx
, nsIGlobalObject
* aGlobal
,
95 JSStructuredCloneReader
* aReader
);
96 using DOMPointReadOnly::ReadStructuredClone
;
98 void SetX(double aX
) { mX
= aX
; }
99 void SetY(double aY
) { mY
= aY
; }
100 void SetZ(double aZ
) { mZ
= aZ
; }
101 void SetW(double aW
) { mW
= aW
; }
105 } // namespace mozilla
107 #endif /*MOZILLA_DOMPOINT_H_*/