Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_DeviceMotionEvent_h_
8 : #define mozilla_dom_DeviceMotionEvent_h_
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/dom/DeviceMotionEventBinding.h"
12 : #include "mozilla/dom/Event.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : class DeviceRotationRate final : public nsWrapperCache
18 : {
19 : public:
20 0 : NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceRotationRate)
21 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DeviceRotationRate)
22 :
23 : DeviceRotationRate(DeviceMotionEvent* aOwner,
24 : const Nullable<double>& aAlpha,
25 : const Nullable<double>& aBeta,
26 : const Nullable<double>& aGamma);
27 :
28 0 : DeviceMotionEvent* GetParentObject() const
29 : {
30 0 : return mOwner;
31 : }
32 :
33 0 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
34 : {
35 0 : return DeviceRotationRateBinding::Wrap(aCx, this, aGivenProto);
36 : }
37 :
38 0 : Nullable<double> GetAlpha() const { return mAlpha; }
39 0 : Nullable<double> GetBeta() const { return mBeta; }
40 0 : Nullable<double> GetGamma() const { return mGamma; }
41 :
42 : private:
43 : ~DeviceRotationRate();
44 :
45 : protected:
46 : RefPtr<DeviceMotionEvent> mOwner;
47 : Nullable<double> mAlpha, mBeta, mGamma;
48 : };
49 :
50 : class DeviceAcceleration final : public nsWrapperCache
51 : {
52 : public:
53 0 : NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceAcceleration)
54 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DeviceAcceleration)
55 :
56 : DeviceAcceleration(DeviceMotionEvent* aOwner,
57 : const Nullable<double>& aX,
58 : const Nullable<double>& aY,
59 : const Nullable<double>& aZ);
60 :
61 0 : DeviceMotionEvent* GetParentObject() const
62 : {
63 0 : return mOwner;
64 : }
65 :
66 0 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
67 : {
68 0 : return DeviceAccelerationBinding::Wrap(aCx, this, aGivenProto);
69 : }
70 :
71 0 : Nullable<double> GetX() const { return mX; }
72 0 : Nullable<double> GetY() const { return mY; }
73 0 : Nullable<double> GetZ() const { return mZ; }
74 :
75 : private:
76 : ~DeviceAcceleration();
77 :
78 : protected:
79 : RefPtr<DeviceMotionEvent> mOwner;
80 : Nullable<double> mX, mY, mZ;
81 : };
82 :
83 : class DeviceMotionEvent final : public Event
84 : {
85 : public:
86 :
87 0 : DeviceMotionEvent(EventTarget* aOwner,
88 : nsPresContext* aPresContext,
89 : WidgetEvent* aEvent)
90 0 : : Event(aOwner, aPresContext, aEvent)
91 : {
92 0 : }
93 :
94 : NS_DECL_ISUPPORTS_INHERITED
95 :
96 : // Forward to Event
97 0 : NS_FORWARD_TO_EVENT
98 :
99 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeviceMotionEvent, Event)
100 :
101 0 : virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
102 : {
103 0 : return DeviceMotionEventBinding::Wrap(aCx, this, aGivenProto);
104 : }
105 :
106 0 : DeviceAcceleration* GetAcceleration() const
107 : {
108 0 : return mAcceleration;
109 : }
110 :
111 0 : DeviceAcceleration* GetAccelerationIncludingGravity() const
112 : {
113 0 : return mAccelerationIncludingGravity;
114 : }
115 :
116 0 : DeviceRotationRate* GetRotationRate() const
117 : {
118 0 : return mRotationRate;
119 : }
120 :
121 0 : Nullable<double> GetInterval() const
122 : {
123 0 : return mInterval;
124 : }
125 :
126 : void InitDeviceMotionEvent(
127 : const nsAString& aType,
128 : bool aCanBubble,
129 : bool aCancelable,
130 : const DeviceAccelerationInit& aAcceleration,
131 : const DeviceAccelerationInit& aAccelerationIncludingGravity,
132 : const DeviceRotationRateInit& aRotationRate,
133 : const Nullable<double>& aInterval);
134 :
135 : void InitDeviceMotionEvent(
136 : const nsAString& aType,
137 : bool aCanBubble,
138 : bool aCancelable,
139 : const DeviceAccelerationInit& aAcceleration,
140 : const DeviceAccelerationInit& aAccelerationIncludingGravity,
141 : const DeviceRotationRateInit& aRotationRate,
142 : const Nullable<double>& aInterval,
143 : const Nullable<uint64_t>& aTimeStamp);
144 :
145 : static already_AddRefed<DeviceMotionEvent>
146 : Constructor(const GlobalObject& aGlobal,
147 : const nsAString& aType,
148 : const DeviceMotionEventInit& aEventInitDict,
149 : ErrorResult& aRv);
150 :
151 : protected:
152 0 : ~DeviceMotionEvent() {}
153 :
154 : RefPtr<DeviceAcceleration> mAcceleration;
155 : RefPtr<DeviceAcceleration> mAccelerationIncludingGravity;
156 : RefPtr<DeviceRotationRate> mRotationRate;
157 : Nullable<double> mInterval;
158 : };
159 :
160 : } // namespace dom
161 : } // namespace mozilla
162 :
163 : already_AddRefed<mozilla::dom::DeviceMotionEvent>
164 : NS_NewDOMDeviceMotionEvent(mozilla::dom::EventTarget* aOwner,
165 : nsPresContext* aPresContext,
166 : mozilla::WidgetEvent* aEvent);
167 :
168 : #endif // mozilla_dom_DeviceMotionEvent_h_
|