|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef mozilla_dom_DeviceMotionEvent_h_ |
|
6 #define mozilla_dom_DeviceMotionEvent_h_ |
|
7 |
|
8 #include "mozilla/Attributes.h" |
|
9 #include "mozilla/dom/DeviceMotionEventBinding.h" |
|
10 #include "mozilla/dom/Event.h" |
|
11 |
|
12 namespace mozilla { |
|
13 namespace dom { |
|
14 |
|
15 class DeviceRotationRate MOZ_FINAL : public nsWrapperCache |
|
16 { |
|
17 public: |
|
18 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceRotationRate) |
|
19 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DeviceRotationRate) |
|
20 |
|
21 DeviceRotationRate(DeviceMotionEvent* aOwner, |
|
22 Nullable<double> aAlpha, Nullable<double> aBeta, |
|
23 Nullable<double> aGamma); |
|
24 |
|
25 DeviceMotionEvent* GetParentObject() const |
|
26 { |
|
27 return mOwner; |
|
28 } |
|
29 |
|
30 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
|
31 { |
|
32 return DeviceRotationRateBinding::Wrap(aCx, this); |
|
33 } |
|
34 |
|
35 Nullable<double> GetAlpha() const { return mAlpha; } |
|
36 Nullable<double> GetBeta() const { return mBeta; } |
|
37 Nullable<double> GetGamma() const { return mGamma; } |
|
38 |
|
39 private: |
|
40 ~DeviceRotationRate(); |
|
41 |
|
42 protected: |
|
43 nsRefPtr<DeviceMotionEvent> mOwner; |
|
44 Nullable<double> mAlpha, mBeta, mGamma; |
|
45 }; |
|
46 |
|
47 class DeviceAcceleration MOZ_FINAL : public nsWrapperCache |
|
48 { |
|
49 public: |
|
50 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DeviceAcceleration) |
|
51 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DeviceAcceleration) |
|
52 |
|
53 DeviceAcceleration(DeviceMotionEvent* aOwner, |
|
54 Nullable<double> aX, Nullable<double> aY, |
|
55 Nullable<double> aZ); |
|
56 |
|
57 DeviceMotionEvent* GetParentObject() const |
|
58 { |
|
59 return mOwner; |
|
60 } |
|
61 |
|
62 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
|
63 { |
|
64 return DeviceAccelerationBinding::Wrap(aCx, this); |
|
65 } |
|
66 |
|
67 Nullable<double> GetX() const { return mX; } |
|
68 Nullable<double> GetY() const { return mY; } |
|
69 Nullable<double> GetZ() const { return mZ; } |
|
70 |
|
71 private: |
|
72 ~DeviceAcceleration(); |
|
73 |
|
74 protected: |
|
75 nsRefPtr<DeviceMotionEvent> mOwner; |
|
76 Nullable<double> mX, mY, mZ; |
|
77 }; |
|
78 |
|
79 class DeviceMotionEvent MOZ_FINAL : public Event |
|
80 { |
|
81 public: |
|
82 |
|
83 DeviceMotionEvent(EventTarget* aOwner, |
|
84 nsPresContext* aPresContext, |
|
85 WidgetEvent* aEvent) |
|
86 : Event(aOwner, aPresContext, aEvent) |
|
87 { |
|
88 } |
|
89 |
|
90 NS_DECL_ISUPPORTS_INHERITED |
|
91 |
|
92 // Forward to Event |
|
93 NS_FORWARD_TO_EVENT |
|
94 |
|
95 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeviceMotionEvent, Event) |
|
96 |
|
97 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
|
98 { |
|
99 return DeviceMotionEventBinding::Wrap(aCx, this); |
|
100 } |
|
101 |
|
102 DeviceAcceleration* GetAcceleration() const |
|
103 { |
|
104 return mAcceleration; |
|
105 } |
|
106 |
|
107 DeviceAcceleration* GetAccelerationIncludingGravity() const |
|
108 { |
|
109 return mAccelerationIncludingGravity; |
|
110 } |
|
111 |
|
112 DeviceRotationRate* GetRotationRate() const |
|
113 { |
|
114 return mRotationRate; |
|
115 } |
|
116 |
|
117 Nullable<double> GetInterval() const |
|
118 { |
|
119 return mInterval; |
|
120 } |
|
121 |
|
122 void InitDeviceMotionEvent( |
|
123 const nsAString& aType, |
|
124 bool aCanBubble, |
|
125 bool aCancelable, |
|
126 const DeviceAccelerationInit& aAcceleration, |
|
127 const DeviceAccelerationInit& aAccelerationIncludingGravity, |
|
128 const DeviceRotationRateInit& aRotationRate, |
|
129 Nullable<double> aInterval, |
|
130 ErrorResult& aRv); |
|
131 |
|
132 static already_AddRefed<DeviceMotionEvent> |
|
133 Constructor(const GlobalObject& aGlobal, |
|
134 const nsAString& aType, |
|
135 const DeviceMotionEventInit& aEventInitDict, |
|
136 ErrorResult& aRv); |
|
137 |
|
138 protected: |
|
139 nsRefPtr<DeviceAcceleration> mAcceleration; |
|
140 nsRefPtr<DeviceAcceleration> mAccelerationIncludingGravity; |
|
141 nsRefPtr<DeviceRotationRate> mRotationRate; |
|
142 Nullable<double> mInterval; |
|
143 }; |
|
144 |
|
145 } // namespace dom |
|
146 } // namespace mozilla |
|
147 |
|
148 #endif // mozilla_dom_DeviceMotionEvent_h_ |