Bug 1789304 [wpt PR 35786] - interactionId for first input - add wpt for tap, a=testonly
[gecko.git] / dom / geolocation / GeolocationCoordinates.cpp
blob6054b2b79ab9f7ba554fcd0597afaca7689e4cfc
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/. */
7 #include "mozilla/dom/GeolocationCoordinates.h"
9 #include "mozilla/FloatingPoint.h"
10 #include "mozilla/dom/GeolocationPosition.h"
11 #include "mozilla/dom/GeolocationCoordinatesBinding.h"
13 namespace mozilla::dom {
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GeolocationCoordinates, mPosition)
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(GeolocationCoordinates)
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(GeolocationCoordinates)
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GeolocationCoordinates)
19 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20 NS_INTERFACE_MAP_ENTRY(nsISupports)
21 NS_INTERFACE_MAP_END
23 GeolocationCoordinates::GeolocationCoordinates(GeolocationPosition* aPosition,
24 nsIDOMGeoPositionCoords* aCoords)
25 : mPosition(aPosition), mCoords(aCoords) {}
27 GeolocationCoordinates::~GeolocationCoordinates() = default;
29 GeolocationPosition* GeolocationCoordinates::GetParentObject() const {
30 return mPosition;
33 JSObject* GeolocationCoordinates::WrapObject(
34 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
35 return GeolocationCoordinates_Binding::Wrap(aCx, this, aGivenProto);
38 #define GENERATE_COORDS_WRAPPED_GETTER(name) \
39 double GeolocationCoordinates::name() const { \
40 double rv; \
41 mCoords->Get##name(&rv); \
42 return rv; \
45 #define GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(name) \
46 Nullable<double> GeolocationCoordinates::Get##name() const { \
47 double value; \
48 mCoords->Get##name(&value); \
49 Nullable<double> rv; \
50 if (!IsNaN(value)) { \
51 rv.SetValue(value); \
52 } \
53 return rv; \
56 GENERATE_COORDS_WRAPPED_GETTER(Latitude)
57 GENERATE_COORDS_WRAPPED_GETTER(Longitude)
58 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Altitude)
59 GENERATE_COORDS_WRAPPED_GETTER(Accuracy)
60 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(AltitudeAccuracy)
61 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Heading)
62 GENERATE_COORDS_WRAPPED_GETTER_NULLABLE(Speed)
64 #undef GENERATE_COORDS_WRAPPED_GETTER
65 #undef GENERATE_COORDS_WRAPPED_GETTER_NULLABLE
67 } // namespace mozilla::dom