dom/src/geolocation/nsGeoPosition.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial