|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "nsGeoPosition.h" |
|
7 |
|
8 #include "mozilla/dom/PositionBinding.h" |
|
9 #include "mozilla/dom/CoordinatesBinding.h" |
|
10 |
|
11 //////////////////////////////////////////////////// |
|
12 // nsGeoPositionCoords |
|
13 //////////////////////////////////////////////////// |
|
14 nsGeoPositionCoords::nsGeoPositionCoords(double aLat, double aLong, |
|
15 double aAlt, double aHError, |
|
16 double aVError, double aHeading, |
|
17 double aSpeed) |
|
18 : mLat(aLat) |
|
19 , mLong(aLong) |
|
20 , mAlt(aAlt) |
|
21 , mHError(aHError) |
|
22 , mVError(aVError) |
|
23 , mHeading(aHeading) |
|
24 , mSpeed(aSpeed) |
|
25 { |
|
26 } |
|
27 |
|
28 nsGeoPositionCoords::~nsGeoPositionCoords() |
|
29 { |
|
30 } |
|
31 |
|
32 NS_INTERFACE_MAP_BEGIN(nsGeoPositionCoords) |
|
33 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionCoords) |
|
34 NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCoords) |
|
35 NS_INTERFACE_MAP_END |
|
36 |
|
37 NS_IMPL_ADDREF(nsGeoPositionCoords) |
|
38 NS_IMPL_RELEASE(nsGeoPositionCoords) |
|
39 |
|
40 NS_IMETHODIMP |
|
41 nsGeoPositionCoords::GetLatitude(double *aLatitude) |
|
42 { |
|
43 *aLatitude = mLat; |
|
44 return NS_OK; |
|
45 } |
|
46 |
|
47 NS_IMETHODIMP |
|
48 nsGeoPositionCoords::GetLongitude(double *aLongitude) |
|
49 { |
|
50 *aLongitude = mLong; |
|
51 return NS_OK; |
|
52 } |
|
53 |
|
54 NS_IMETHODIMP |
|
55 nsGeoPositionCoords::GetAltitude(double *aAltitude) |
|
56 { |
|
57 *aAltitude = mAlt; |
|
58 return NS_OK; |
|
59 } |
|
60 |
|
61 NS_IMETHODIMP |
|
62 nsGeoPositionCoords::GetAccuracy(double *aAccuracy) |
|
63 { |
|
64 *aAccuracy = mHError; |
|
65 return NS_OK; |
|
66 } |
|
67 |
|
68 NS_IMETHODIMP |
|
69 nsGeoPositionCoords::GetAltitudeAccuracy(double *aAltitudeAccuracy) |
|
70 { |
|
71 *aAltitudeAccuracy = mVError; |
|
72 return NS_OK; |
|
73 } |
|
74 |
|
75 NS_IMETHODIMP |
|
76 nsGeoPositionCoords::GetHeading(double *aHeading) |
|
77 { |
|
78 *aHeading = mHeading; |
|
79 return NS_OK; |
|
80 } |
|
81 |
|
82 NS_IMETHODIMP |
|
83 nsGeoPositionCoords::GetSpeed(double *aSpeed) |
|
84 { |
|
85 *aSpeed = mSpeed; |
|
86 return NS_OK; |
|
87 } |
|
88 |
|
89 //////////////////////////////////////////////////// |
|
90 // nsGeoPosition |
|
91 //////////////////////////////////////////////////// |
|
92 |
|
93 nsGeoPosition::nsGeoPosition(double aLat, double aLong, |
|
94 double aAlt, double aHError, |
|
95 double aVError, double aHeading, |
|
96 double aSpeed, long long aTimestamp) : |
|
97 mTimestamp(aTimestamp) |
|
98 { |
|
99 mCoords = new nsGeoPositionCoords(aLat, aLong, |
|
100 aAlt, aHError, |
|
101 aVError, aHeading, |
|
102 aSpeed); |
|
103 } |
|
104 |
|
105 nsGeoPosition::nsGeoPosition(nsIDOMGeoPositionCoords *aCoords, |
|
106 long long aTimestamp) : |
|
107 mTimestamp(aTimestamp), |
|
108 mCoords(aCoords) |
|
109 { |
|
110 } |
|
111 |
|
112 nsGeoPosition::nsGeoPosition(nsIDOMGeoPositionCoords *aCoords, |
|
113 DOMTimeStamp aTimestamp) : |
|
114 mTimestamp(aTimestamp), |
|
115 mCoords(aCoords) |
|
116 { |
|
117 } |
|
118 |
|
119 nsGeoPosition::~nsGeoPosition() |
|
120 { |
|
121 } |
|
122 |
|
123 NS_INTERFACE_MAP_BEGIN(nsGeoPosition) |
|
124 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPosition) |
|
125 NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPosition) |
|
126 NS_INTERFACE_MAP_END |
|
127 |
|
128 NS_IMPL_ADDREF(nsGeoPosition) |
|
129 NS_IMPL_RELEASE(nsGeoPosition) |
|
130 |
|
131 NS_IMETHODIMP |
|
132 nsGeoPosition::GetTimestamp(DOMTimeStamp* aTimestamp) |
|
133 { |
|
134 *aTimestamp = mTimestamp; |
|
135 return NS_OK; |
|
136 } |
|
137 |
|
138 NS_IMETHODIMP |
|
139 nsGeoPosition::GetCoords(nsIDOMGeoPositionCoords * *aCoords) |
|
140 { |
|
141 NS_IF_ADDREF(*aCoords = mCoords); |
|
142 return NS_OK; |
|
143 } |
|
144 |
|
145 namespace mozilla { |
|
146 namespace dom { |
|
147 |
|
148 |
|
149 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(Position, mParent, mCoordinates) |
|
150 NS_IMPL_CYCLE_COLLECTING_ADDREF(Position) |
|
151 NS_IMPL_CYCLE_COLLECTING_RELEASE(Position) |
|
152 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Position) |
|
153 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
154 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
155 NS_INTERFACE_MAP_END |
|
156 |
|
157 Position::Position(nsISupports* aParent, nsIDOMGeoPosition* aGeoPosition) |
|
158 : mParent(aParent) |
|
159 , mGeoPosition(aGeoPosition) |
|
160 { |
|
161 SetIsDOMBinding(); |
|
162 } |
|
163 |
|
164 Position::~Position() |
|
165 { |
|
166 } |
|
167 |
|
168 nsISupports* |
|
169 Position::GetParentObject() const |
|
170 { |
|
171 return mParent; |
|
172 } |
|
173 |
|
174 JSObject* |
|
175 Position::WrapObject(JSContext* aCx) |
|
176 { |
|
177 return PositionBinding::Wrap(aCx, this); |
|
178 } |
|
179 |
|
180 Coordinates* |
|
181 Position::Coords() |
|
182 { |
|
183 if (!mCoordinates) { |
|
184 nsCOMPtr<nsIDOMGeoPositionCoords> coords; |
|
185 mGeoPosition->GetCoords(getter_AddRefs(coords)); |
|
186 MOZ_ASSERT(coords, "coords should not be null"); |
|
187 |
|
188 mCoordinates = new Coordinates(this, coords); |
|
189 } |
|
190 |
|
191 return mCoordinates; |
|
192 } |
|
193 |
|
194 uint64_t |
|
195 Position::Timestamp() const |
|
196 { |
|
197 uint64_t rv; |
|
198 |
|
199 mGeoPosition->GetTimestamp(&rv); |
|
200 return rv; |
|
201 } |
|
202 |
|
203 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Coordinates, mPosition) |
|
204 NS_IMPL_CYCLE_COLLECTING_ADDREF(Coordinates) |
|
205 NS_IMPL_CYCLE_COLLECTING_RELEASE(Coordinates) |
|
206 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Coordinates) |
|
207 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
208 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
209 NS_INTERFACE_MAP_END |
|
210 |
|
211 Coordinates::Coordinates(Position* aPosition, nsIDOMGeoPositionCoords* aCoords) |
|
212 : mPosition(aPosition) |
|
213 , mCoords(aCoords) |
|
214 { |
|
215 SetIsDOMBinding(); |
|
216 } |
|
217 |
|
218 Coordinates::~Coordinates() |
|
219 { |
|
220 } |
|
221 |
|
222 Position* |
|
223 Coordinates::GetParentObject() const |
|
224 { |
|
225 return mPosition; |
|
226 } |
|
227 |
|
228 JSObject* |
|
229 Coordinates::WrapObject(JSContext* aCx) |
|
230 { |
|
231 return CoordinatesBinding::Wrap(aCx, this); |
|
232 } |
|
233 |
|
234 #define GENERATE_COORDS_WRAPPED_GETTER(name) \ |
|
235 double \ |
|
236 Coordinates::name() const \ |
|
237 { \ |
|
238 double rv; \ |
|
239 mCoords->Get##name(&rv); \ |
|
240 return rv; \ |
|
241 } |
|
242 |
|
243 #define GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(name) \ |
|
244 Nullable<double> \ |
|
245 Coordinates::Get##name() const \ |
|
246 { \ |
|
247 double rv; \ |
|
248 mCoords->Get##name(&rv); \ |
|
249 return Nullable<double>(rv); \ |
|
250 } |
|
251 |
|
252 GENERATE_COORDS_WRAPPED_GETTER(Latitude) |
|
253 GENERATE_COORDS_WRAPPED_GETTER(Longitude) |
|
254 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Altitude) |
|
255 GENERATE_COORDS_WRAPPED_GETTER(Accuracy) |
|
256 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(AltitudeAccuracy) |
|
257 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Heading) |
|
258 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Speed) |
|
259 |
|
260 #undef GENERATE_COORDS_WRAPPED_GETTER |
|
261 #undef GENERATE_COORDS_WRAPPED_GETTER_NULLABLE |
|
262 |
|
263 } // namespace dom |
|
264 } // namespace mozilla |