1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Device Motion System.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2011
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Doug Turner <dougt@dougt.org>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsDOMDeviceMotionEvent.h"
39 : #include "nsContentUtils.h"
40 :
41 :
42 :
43 1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMDeviceMotionEvent)
44 :
45 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
46 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mAcceleration)
47 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mAccelerationIncludingGravity)
48 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRotationRate)
49 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
50 :
51 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
52 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAcceleration)
53 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAccelerationIncludingGravity)
54 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRotationRate)
55 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
56 :
57 0 : NS_IMPL_ADDREF_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
58 0 : NS_IMPL_RELEASE_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
59 :
60 : DOMCI_DATA(DeviceMotionEvent, nsDOMDeviceMotionEvent)
61 :
62 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMDeviceMotionEvent)
63 0 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDeviceMotionEvent)
64 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceMotionEvent)
65 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceMotionEvent)
66 0 : NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
67 :
68 : NS_IMETHODIMP
69 0 : nsDOMDeviceMotionEvent::InitDeviceMotionEvent(const nsAString & aEventTypeArg,
70 : bool aCanBubbleArg,
71 : bool aCancelableArg,
72 : nsIDOMDeviceAcceleration* aAcceleration,
73 : nsIDOMDeviceAcceleration* aAccelerationIncludingGravity,
74 : nsIDOMDeviceRotationRate* aRotationRate,
75 : double aInterval)
76 : {
77 0 : nsresult rv = nsDOMEvent::InitEvent(aEventTypeArg, aCanBubbleArg, aCancelableArg);
78 0 : NS_ENSURE_SUCCESS(rv, rv);
79 :
80 0 : mAcceleration = aAcceleration;
81 0 : mAccelerationIncludingGravity = aAccelerationIncludingGravity;
82 0 : mRotationRate = aRotationRate;
83 0 : mInterval = aInterval;
84 0 : return NS_OK;
85 : }
86 :
87 : NS_IMETHODIMP
88 0 : nsDOMDeviceMotionEvent::GetAcceleration(nsIDOMDeviceAcceleration **aAcceleration)
89 : {
90 0 : NS_ENSURE_ARG_POINTER(aAcceleration);
91 :
92 0 : NS_IF_ADDREF(*aAcceleration = mAcceleration);
93 0 : return NS_OK;
94 : }
95 :
96 : NS_IMETHODIMP
97 0 : nsDOMDeviceMotionEvent::GetAccelerationIncludingGravity(nsIDOMDeviceAcceleration **aAccelerationIncludingGravity)
98 : {
99 0 : NS_ENSURE_ARG_POINTER(aAccelerationIncludingGravity);
100 :
101 0 : NS_IF_ADDREF(*aAccelerationIncludingGravity = mAccelerationIncludingGravity);
102 0 : return NS_OK;
103 : }
104 :
105 : NS_IMETHODIMP
106 0 : nsDOMDeviceMotionEvent::GetRotationRate(nsIDOMDeviceRotationRate **aRotationRate)
107 : {
108 0 : NS_ENSURE_ARG_POINTER(aRotationRate);
109 :
110 0 : NS_IF_ADDREF(*aRotationRate = mRotationRate);
111 0 : return NS_OK;
112 : }
113 :
114 : NS_IMETHODIMP
115 0 : nsDOMDeviceMotionEvent::GetInterval(double *aInterval)
116 : {
117 0 : NS_ENSURE_ARG_POINTER(aInterval);
118 :
119 0 : *aInterval = mInterval;
120 0 : return NS_OK;
121 : }
122 :
123 :
124 : nsresult
125 0 : NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aInstancePtrResult,
126 : nsPresContext* aPresContext,
127 : nsEvent *aEvent)
128 : {
129 0 : NS_ENSURE_ARG_POINTER(aInstancePtrResult);
130 :
131 0 : nsDOMDeviceMotionEvent* it = new nsDOMDeviceMotionEvent(aPresContext, aEvent);
132 0 : return CallQueryInterface(it, aInstancePtrResult);
133 : }
134 :
135 :
136 : DOMCI_DATA(DeviceAcceleration, nsDOMDeviceAcceleration)
137 :
138 0 : NS_INTERFACE_MAP_BEGIN(nsDOMDeviceAcceleration)
139 0 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDeviceAcceleration)
140 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceAcceleration)
141 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceAcceleration)
142 0 : NS_INTERFACE_MAP_END
143 :
144 0 : NS_IMPL_ADDREF(nsDOMDeviceAcceleration)
145 0 : NS_IMPL_RELEASE(nsDOMDeviceAcceleration)
146 :
147 0 : nsDOMDeviceAcceleration::nsDOMDeviceAcceleration(double aX, double aY, double aZ)
148 0 : : mX(aX), mY(aY), mZ(aZ)
149 : {
150 0 : }
151 :
152 0 : nsDOMDeviceAcceleration::~nsDOMDeviceAcceleration()
153 : {
154 0 : }
155 :
156 : NS_IMETHODIMP
157 0 : nsDOMDeviceAcceleration::GetX(double *aX)
158 : {
159 0 : NS_ENSURE_ARG_POINTER(aX);
160 0 : *aX = mX;
161 0 : return NS_OK;
162 : }
163 :
164 : NS_IMETHODIMP
165 0 : nsDOMDeviceAcceleration::GetY(double *aY)
166 : {
167 0 : NS_ENSURE_ARG_POINTER(aY);
168 0 : *aY = mY;
169 0 : return NS_OK;
170 : }
171 :
172 : NS_IMETHODIMP
173 0 : nsDOMDeviceAcceleration::GetZ(double *aZ)
174 : {
175 0 : NS_ENSURE_ARG_POINTER(aZ);
176 0 : *aZ = mZ;
177 0 : return NS_OK;
178 : }
179 :
180 :
181 : DOMCI_DATA(DeviceRotationRate, nsDOMDeviceRotationRate)
182 :
183 0 : NS_INTERFACE_MAP_BEGIN(nsDOMDeviceRotationRate)
184 0 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDeviceRotationRate)
185 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceRotationRate)
186 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceRotationRate)
187 0 : NS_INTERFACE_MAP_END
188 :
189 0 : NS_IMPL_ADDREF(nsDOMDeviceRotationRate)
190 0 : NS_IMPL_RELEASE(nsDOMDeviceRotationRate)
191 :
192 0 : nsDOMDeviceRotationRate::nsDOMDeviceRotationRate(double aAlpha, double aBeta, double aGamma)
193 0 : : mAlpha(aAlpha), mBeta(aBeta), mGamma(aGamma)
194 : {
195 0 : }
196 :
197 0 : nsDOMDeviceRotationRate::~nsDOMDeviceRotationRate()
198 : {
199 0 : }
200 :
201 : NS_IMETHODIMP
202 0 : nsDOMDeviceRotationRate::GetAlpha(double *aAlpha)
203 : {
204 0 : NS_ENSURE_ARG_POINTER(aAlpha);
205 0 : *aAlpha = mAlpha;
206 0 : return NS_OK;
207 : }
208 :
209 : NS_IMETHODIMP
210 0 : nsDOMDeviceRotationRate::GetBeta(double *aBeta)
211 : {
212 0 : NS_ENSURE_ARG_POINTER(aBeta);
213 0 : *aBeta = mBeta;
214 0 : return NS_OK;
215 : }
216 :
217 : NS_IMETHODIMP
218 0 : nsDOMDeviceRotationRate::GetGamma(double *aGamma)
219 : {
220 0 : NS_ENSURE_ARG_POINTER(aGamma);
221 0 : *aGamma = mGamma;
222 0 : return NS_OK;
223 4392 : }
|