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 #include "mozilla/dom/DeviceMotionEvent.h"
8 #include "nsContentUtils.h"
13 /******************************************************************************
15 *****************************************************************************/
17 NS_IMPL_CYCLE_COLLECTION_INHERITED(DeviceMotionEvent
, Event
,
19 mAccelerationIncludingGravity
,
22 NS_IMPL_ADDREF_INHERITED(DeviceMotionEvent
, Event
)
23 NS_IMPL_RELEASE_INHERITED(DeviceMotionEvent
, Event
)
25 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DeviceMotionEvent
)
26 NS_INTERFACE_MAP_END_INHERITING(Event
)
29 DeviceMotionEvent::InitDeviceMotionEvent(
30 const nsAString
& aType
,
33 const DeviceAccelerationInit
& aAcceleration
,
34 const DeviceAccelerationInit
& aAccelIncludingGravity
,
35 const DeviceRotationRateInit
& aRotationRate
,
36 Nullable
<double> aInterval
,
39 aRv
= Event::InitEvent(aType
, aCanBubble
, aCancelable
);
44 mAcceleration
= new DeviceAcceleration(this, aAcceleration
.mX
,
48 mAccelerationIncludingGravity
=
49 new DeviceAcceleration(this, aAccelIncludingGravity
.mX
,
50 aAccelIncludingGravity
.mY
,
51 aAccelIncludingGravity
.mZ
);
53 mRotationRate
= new DeviceRotationRate(this, aRotationRate
.mAlpha
,
55 aRotationRate
.mGamma
);
56 mInterval
= aInterval
;
59 already_AddRefed
<DeviceMotionEvent
>
60 DeviceMotionEvent::Constructor(const GlobalObject
& aGlobal
,
61 const nsAString
& aType
,
62 const DeviceMotionEventInit
& aEventInitDict
,
65 nsCOMPtr
<EventTarget
> t
= do_QueryInterface(aGlobal
.GetAsSupports());
66 nsRefPtr
<DeviceMotionEvent
> e
= new DeviceMotionEvent(t
, nullptr, nullptr);
67 aRv
= e
->InitEvent(aType
, aEventInitDict
.mBubbles
, aEventInitDict
.mCancelable
);
71 bool trusted
= e
->Init(t
);
73 e
->mAcceleration
= new DeviceAcceleration(e
,
74 aEventInitDict
.mAcceleration
.mX
,
75 aEventInitDict
.mAcceleration
.mY
,
76 aEventInitDict
.mAcceleration
.mZ
);
78 e
->mAccelerationIncludingGravity
= new DeviceAcceleration(e
,
79 aEventInitDict
.mAccelerationIncludingGravity
.mX
,
80 aEventInitDict
.mAccelerationIncludingGravity
.mY
,
81 aEventInitDict
.mAccelerationIncludingGravity
.mZ
);
83 e
->mRotationRate
= new DeviceRotationRate(e
,
84 aEventInitDict
.mRotationRate
.mAlpha
,
85 aEventInitDict
.mRotationRate
.mBeta
,
86 aEventInitDict
.mRotationRate
.mGamma
);
88 e
->mInterval
= aEventInitDict
.mInterval
;
89 e
->SetTrusted(trusted
);
94 /******************************************************************************
96 *****************************************************************************/
98 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DeviceAcceleration
, mOwner
)
100 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DeviceAcceleration
, AddRef
)
101 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DeviceAcceleration
, Release
)
103 DeviceAcceleration::DeviceAcceleration(DeviceMotionEvent
* aOwner
,
115 DeviceAcceleration::~DeviceAcceleration()
119 /******************************************************************************
121 *****************************************************************************/
123 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DeviceRotationRate
, mOwner
)
125 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DeviceRotationRate
, AddRef
)
126 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DeviceRotationRate
, Release
)
128 DeviceRotationRate::DeviceRotationRate(DeviceMotionEvent
* aOwner
,
129 Nullable
<double> aAlpha
,
130 Nullable
<double> aBeta
,
131 Nullable
<double> aGamma
)
140 DeviceRotationRate::~DeviceRotationRate()
145 } // namespace mozilla
147 using namespace mozilla
;
148 using namespace mozilla::dom
;
151 NS_NewDOMDeviceMotionEvent(nsIDOMEvent
** aInstancePtrResult
,
153 nsPresContext
* aPresContext
,
156 NS_ENSURE_ARG_POINTER(aInstancePtrResult
);
158 DeviceMotionEvent
* it
= new DeviceMotionEvent(aOwner
, aPresContext
, aEvent
);
160 *aInstancePtrResult
= static_cast<Event
*>(it
);