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_dom_DeviceMotionEvent_h_
8 #define mozilla_dom_DeviceMotionEvent_h_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/DeviceMotionEventBinding.h"
12 #include "mozilla/dom/Event.h"
14 namespace mozilla::dom
{
16 class DeviceRotationRate final
: public nsWrapperCache
{
18 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceRotationRate
)
19 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DeviceRotationRate
)
21 DeviceRotationRate(DeviceMotionEvent
* aOwner
, const Nullable
<double>& aAlpha
,
22 const Nullable
<double>& aBeta
,
23 const Nullable
<double>& aGamma
);
25 DeviceMotionEvent
* GetParentObject() const { return mOwner
; }
27 virtual JSObject
* WrapObject(JSContext
* aCx
,
28 JS::Handle
<JSObject
*> aGivenProto
) override
{
29 return DeviceRotationRate_Binding::Wrap(aCx
, this, aGivenProto
);
32 Nullable
<double> GetAlpha() const { return mAlpha
; }
33 Nullable
<double> GetBeta() const { return mBeta
; }
34 Nullable
<double> GetGamma() const { return mGamma
; }
37 ~DeviceRotationRate();
40 RefPtr
<DeviceMotionEvent
> mOwner
;
41 Nullable
<double> mAlpha
, mBeta
, mGamma
;
44 class DeviceAcceleration final
: public nsWrapperCache
{
46 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceAcceleration
)
47 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DeviceAcceleration
)
49 DeviceAcceleration(DeviceMotionEvent
* aOwner
, const Nullable
<double>& aX
,
50 const Nullable
<double>& aY
, const Nullable
<double>& aZ
);
52 DeviceMotionEvent
* GetParentObject() const { return mOwner
; }
54 virtual JSObject
* WrapObject(JSContext
* aCx
,
55 JS::Handle
<JSObject
*> aGivenProto
) override
{
56 return DeviceAcceleration_Binding::Wrap(aCx
, this, aGivenProto
);
59 Nullable
<double> GetX() const { return mX
; }
60 Nullable
<double> GetY() const { return mY
; }
61 Nullable
<double> GetZ() const { return mZ
; }
64 ~DeviceAcceleration();
67 RefPtr
<DeviceMotionEvent
> mOwner
;
68 Nullable
<double> mX
, mY
, mZ
;
71 class DeviceMotionEvent final
: public Event
{
73 DeviceMotionEvent(EventTarget
* aOwner
, nsPresContext
* aPresContext
,
75 : Event(aOwner
, aPresContext
, aEvent
) {}
77 NS_DECL_ISUPPORTS_INHERITED
79 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeviceMotionEvent
, Event
)
81 virtual JSObject
* WrapObjectInternal(
82 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
{
83 return DeviceMotionEvent_Binding::Wrap(aCx
, this, aGivenProto
);
86 DeviceAcceleration
* GetAcceleration() const { return mAcceleration
; }
88 DeviceAcceleration
* GetAccelerationIncludingGravity() const {
89 return mAccelerationIncludingGravity
;
92 DeviceRotationRate
* GetRotationRate() const { return mRotationRate
; }
94 Nullable
<double> GetInterval() const { return mInterval
; }
96 void InitDeviceMotionEvent(
97 const nsAString
& aType
, bool aCanBubble
, bool aCancelable
,
98 const DeviceAccelerationInit
& aAcceleration
,
99 const DeviceAccelerationInit
& aAccelerationIncludingGravity
,
100 const DeviceRotationRateInit
& aRotationRate
,
101 const Nullable
<double>& aInterval
);
103 void InitDeviceMotionEvent(
104 const nsAString
& aType
, bool aCanBubble
, bool aCancelable
,
105 const DeviceAccelerationInit
& aAcceleration
,
106 const DeviceAccelerationInit
& aAccelerationIncludingGravity
,
107 const DeviceRotationRateInit
& aRotationRate
,
108 const Nullable
<double>& aInterval
, const Nullable
<uint64_t>& aTimeStamp
);
110 static already_AddRefed
<DeviceMotionEvent
> Constructor(
111 const GlobalObject
& aGlobal
, const nsAString
& aType
,
112 const DeviceMotionEventInit
& aEventInitDict
);
115 ~DeviceMotionEvent() = default;
117 RefPtr
<DeviceAcceleration
> mAcceleration
;
118 RefPtr
<DeviceAcceleration
> mAccelerationIncludingGravity
;
119 RefPtr
<DeviceRotationRate
> mRotationRate
;
120 Nullable
<double> mInterval
;
123 } // namespace mozilla::dom
125 already_AddRefed
<mozilla::dom::DeviceMotionEvent
> NS_NewDOMDeviceMotionEvent(
126 mozilla::dom::EventTarget
* aOwner
, nsPresContext
* aPresContext
,
127 mozilla::WidgetEvent
* aEvent
);
129 #endif // mozilla_dom_DeviceMotionEvent_h_