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.

     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,
    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 }
    28 nsGeoPositionCoords::~nsGeoPositionCoords()
    29 {
    30 }
    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
    37 NS_IMPL_ADDREF(nsGeoPositionCoords)
    38 NS_IMPL_RELEASE(nsGeoPositionCoords)
    40 NS_IMETHODIMP
    41 nsGeoPositionCoords::GetLatitude(double *aLatitude)
    42 {
    43   *aLatitude = mLat;
    44   return NS_OK;
    45 }
    47 NS_IMETHODIMP
    48 nsGeoPositionCoords::GetLongitude(double *aLongitude)
    49 {
    50   *aLongitude = mLong;
    51   return NS_OK;
    52 }
    54 NS_IMETHODIMP
    55 nsGeoPositionCoords::GetAltitude(double *aAltitude)
    56 {
    57   *aAltitude = mAlt;
    58   return NS_OK;
    59 }
    61 NS_IMETHODIMP
    62 nsGeoPositionCoords::GetAccuracy(double *aAccuracy)
    63 {
    64   *aAccuracy = mHError;
    65   return NS_OK;
    66 }
    68 NS_IMETHODIMP
    69 nsGeoPositionCoords::GetAltitudeAccuracy(double *aAltitudeAccuracy)
    70 {
    71   *aAltitudeAccuracy = mVError;
    72   return NS_OK;
    73 }
    75 NS_IMETHODIMP
    76 nsGeoPositionCoords::GetHeading(double *aHeading)
    77 {
    78   *aHeading = mHeading;
    79   return NS_OK;
    80 }
    82 NS_IMETHODIMP
    83 nsGeoPositionCoords::GetSpeed(double *aSpeed)
    84 {
    85   *aSpeed = mSpeed;
    86   return NS_OK;
    87 }
    89 ////////////////////////////////////////////////////
    90 // nsGeoPosition
    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)
    98 {
    99     mCoords = new nsGeoPositionCoords(aLat, aLong,
   100                                       aAlt, aHError,
   101                                       aVError, aHeading,
   102                                       aSpeed);
   103 }
   105 nsGeoPosition::nsGeoPosition(nsIDOMGeoPositionCoords *aCoords,
   106                              long long aTimestamp) :
   107     mTimestamp(aTimestamp),
   108     mCoords(aCoords)
   109 {
   110 }
   112 nsGeoPosition::nsGeoPosition(nsIDOMGeoPositionCoords *aCoords,
   113                              DOMTimeStamp aTimestamp) :
   114   mTimestamp(aTimestamp),
   115   mCoords(aCoords)
   116 {
   117 }
   119 nsGeoPosition::~nsGeoPosition()
   120 {
   121 }
   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
   128 NS_IMPL_ADDREF(nsGeoPosition)
   129 NS_IMPL_RELEASE(nsGeoPosition)
   131 NS_IMETHODIMP
   132 nsGeoPosition::GetTimestamp(DOMTimeStamp* aTimestamp)
   133 {
   134   *aTimestamp = mTimestamp;
   135   return NS_OK;
   136 }
   138 NS_IMETHODIMP
   139 nsGeoPosition::GetCoords(nsIDOMGeoPositionCoords * *aCoords)
   140 {
   141   NS_IF_ADDREF(*aCoords = mCoords);
   142   return NS_OK;
   143 }
   145 namespace mozilla {
   146 namespace dom {
   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
   157 Position::Position(nsISupports* aParent, nsIDOMGeoPosition* aGeoPosition)
   158   : mParent(aParent)
   159   , mGeoPosition(aGeoPosition)
   160 {
   161   SetIsDOMBinding();
   162 }
   164 Position::~Position()
   165 {
   166 }
   168 nsISupports*
   169 Position::GetParentObject() const
   170 {
   171   return mParent;
   172 }
   174 JSObject*
   175 Position::WrapObject(JSContext* aCx)
   176 {
   177   return PositionBinding::Wrap(aCx, this);
   178 }
   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");
   188     mCoordinates = new Coordinates(this, coords);
   189   }
   191   return mCoordinates;
   192 }
   194 uint64_t
   195 Position::Timestamp() const
   196 {
   197   uint64_t rv;
   199   mGeoPosition->GetTimestamp(&rv);
   200   return rv;
   201 }
   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
   211 Coordinates::Coordinates(Position* aPosition, nsIDOMGeoPositionCoords* aCoords)
   212   : mPosition(aPosition)
   213   , mCoords(aCoords)
   214 {
   215   SetIsDOMBinding();
   216 }
   218 Coordinates::~Coordinates()
   219 {
   220 }
   222 Position*
   223 Coordinates::GetParentObject() const
   224 {
   225   return mPosition;
   226 }
   228 JSObject*
   229 Coordinates::WrapObject(JSContext* aCx)
   230 {
   231   return CoordinatesBinding::Wrap(aCx, this);
   232 }
   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 }
   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 }
   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)
   260 #undef GENERATE_COORDS_WRAPPED_GETTER
   261 #undef GENERATE_COORDS_WRAPPED_GETTER_NULLABLE
   263 } // namespace dom
   264 } // namespace mozilla

mercurial