tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GeolocationCoordinates.cpp (2682B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "mozilla/dom/GeolocationCoordinates.h"
      8 
      9 #include "mozilla/dom/GeolocationCoordinatesBinding.h"
     10 #include "mozilla/dom/GeolocationPosition.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GeolocationCoordinates, mPosition)
     15 NS_IMPL_CYCLE_COLLECTING_ADDREF(GeolocationCoordinates)
     16 NS_IMPL_CYCLE_COLLECTING_RELEASE(GeolocationCoordinates)
     17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GeolocationCoordinates)
     18  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     19  NS_INTERFACE_MAP_ENTRY(nsISupports)
     20 NS_INTERFACE_MAP_END
     21 
     22 GeolocationCoordinates::GeolocationCoordinates(GeolocationPosition* aPosition,
     23                                               nsIDOMGeoPositionCoords* aCoords)
     24    : mPosition(aPosition), mCoords(aCoords) {}
     25 
     26 GeolocationCoordinates::~GeolocationCoordinates() = default;
     27 
     28 GeolocationPosition* GeolocationCoordinates::GetParentObject() const {
     29  return mPosition;
     30 }
     31 
     32 JSObject* GeolocationCoordinates::WrapObject(
     33    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     34  return GeolocationCoordinates_Binding::Wrap(aCx, this, aGivenProto);
     35 }
     36 
     37 #define GENERATE_COORDS_WRAPPED_GETTER(name)    \
     38  double GeolocationCoordinates::name() const { \
     39    double rv;                                  \
     40    mCoords->Get##name(&rv);                    \
     41    return rv;                                  \
     42  }
     43 
     44 #define GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(name)          \
     45  Nullable<double> GeolocationCoordinates::Get##name() const { \
     46    double value;                                              \
     47    mCoords->Get##name(&value);                                \
     48    Nullable<double> rv;                                       \
     49    if (!std::isnan(value)) {                                  \
     50      rv.SetValue(value);                                      \
     51    }                                                          \
     52    return rv;                                                 \
     53  }
     54 
     55 GENERATE_COORDS_WRAPPED_GETTER(Latitude)
     56 GENERATE_COORDS_WRAPPED_GETTER(Longitude)
     57 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Altitude)
     58 GENERATE_COORDS_WRAPPED_GETTER(Accuracy)
     59 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(AltitudeAccuracy)
     60 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Heading)
     61 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Speed)
     62 
     63 #undef GENERATE_COORDS_WRAPPED_GETTER
     64 #undef GENERATE_COORDS_WRAPPED_GETTER_NULLABLE
     65 
     66 }  // namespace mozilla::dom