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/. */
6 #include "nsGeoPosition.h"
8 #include "mozilla/dom/PositionBinding.h"
9 #include "mozilla/dom/CoordinatesBinding.h"
11 ////////////////////////////////////////////////////
12 // nsGeoPositionCoords
13 ////////////////////////////////////////////////////
14 nsGeoPositionCoords::nsGeoPositionCoords(double aLat
, double aLong
,
15 double aAlt
, double aHError
,
16 double aVError
, double aHeading
,
28 nsGeoPositionCoords::~nsGeoPositionCoords()
32 NS_INTERFACE_MAP_BEGIN(nsGeoPositionCoords
)
33 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDOMGeoPositionCoords
)
34 NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCoords
)
37 NS_IMPL_ADDREF(nsGeoPositionCoords
)
38 NS_IMPL_RELEASE(nsGeoPositionCoords
)
41 nsGeoPositionCoords::GetLatitude(double *aLatitude
)
48 nsGeoPositionCoords::GetLongitude(double *aLongitude
)
55 nsGeoPositionCoords::GetAltitude(double *aAltitude
)
62 nsGeoPositionCoords::GetAccuracy(double *aAccuracy
)
69 nsGeoPositionCoords::GetAltitudeAccuracy(double *aAltitudeAccuracy
)
71 *aAltitudeAccuracy
= mVError
;
76 nsGeoPositionCoords::GetHeading(double *aHeading
)
83 nsGeoPositionCoords::GetSpeed(double *aSpeed
)
89 ////////////////////////////////////////////////////
91 ////////////////////////////////////////////////////
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
)
99 mCoords
= new nsGeoPositionCoords(aLat
, aLong
,
105 nsGeoPosition::nsGeoPosition(nsIDOMGeoPositionCoords
*aCoords
,
106 long long aTimestamp
) :
107 mTimestamp(aTimestamp
),
112 nsGeoPosition::nsGeoPosition(nsIDOMGeoPositionCoords
*aCoords
,
113 DOMTimeStamp aTimestamp
) :
114 mTimestamp(aTimestamp
),
119 nsGeoPosition::~nsGeoPosition()
123 NS_INTERFACE_MAP_BEGIN(nsGeoPosition
)
124 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDOMGeoPosition
)
125 NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPosition
)
128 NS_IMPL_ADDREF(nsGeoPosition
)
129 NS_IMPL_RELEASE(nsGeoPosition
)
132 nsGeoPosition::GetTimestamp(DOMTimeStamp
* aTimestamp
)
134 *aTimestamp
= mTimestamp
;
139 nsGeoPosition::GetCoords(nsIDOMGeoPositionCoords
* *aCoords
)
141 NS_IF_ADDREF(*aCoords
= mCoords
);
149 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(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
)
157 Position::Position(nsISupports
* aParent
, nsIDOMGeoPosition
* aGeoPosition
)
159 , mGeoPosition(aGeoPosition
)
163 Position::~Position()
168 Position::GetParentObject() const
174 Position::WrapObject(JSContext
* aCx
)
176 return PositionBinding::Wrap(aCx
, this);
183 nsCOMPtr
<nsIDOMGeoPositionCoords
> coords
;
184 mGeoPosition
->GetCoords(getter_AddRefs(coords
));
185 MOZ_ASSERT(coords
, "coords should not be null");
187 mCoordinates
= new Coordinates(this, coords
);
194 Position::Timestamp() const
198 mGeoPosition
->GetTimestamp(&rv
);
202 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Coordinates
, mPosition
)
203 NS_IMPL_CYCLE_COLLECTING_ADDREF(Coordinates
)
204 NS_IMPL_CYCLE_COLLECTING_RELEASE(Coordinates
)
205 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Coordinates
)
206 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
207 NS_INTERFACE_MAP_ENTRY(nsISupports
)
210 Coordinates::Coordinates(Position
* aPosition
, nsIDOMGeoPositionCoords
* aCoords
)
211 : mPosition(aPosition
)
216 Coordinates::~Coordinates()
221 Coordinates::GetParentObject() const
227 Coordinates::WrapObject(JSContext
* aCx
)
229 return CoordinatesBinding::Wrap(aCx
, this);
232 #define GENERATE_COORDS_WRAPPED_GETTER(name) \
234 Coordinates::name() const \
237 mCoords->Get##name(&rv); \
241 #define GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(name) \
243 Coordinates::Get##name() const \
246 mCoords->Get##name(&rv); \
247 return Nullable<double>(rv); \
250 GENERATE_COORDS_WRAPPED_GETTER(Latitude
)
251 GENERATE_COORDS_WRAPPED_GETTER(Longitude
)
252 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Altitude
)
253 GENERATE_COORDS_WRAPPED_GETTER(Accuracy
)
254 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(AltitudeAccuracy
)
255 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Heading
)
256 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Speed
)
258 #undef GENERATE_COORDS_WRAPPED_GETTER
259 #undef GENERATE_COORDS_WRAPPED_GETTER_NULLABLE
262 } // namespace mozilla