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 #ifndef mozilla_dom_GeolocationPosition_h
8 #define mozilla_dom_GeolocationPosition_h
9 
10 #include "nsIDOMGeoPositionCoords.h"
11 #include "nsIDOMGeoPosition.h"
12 #include "nsString.h"
13 #include "nsCOMPtr.h"
14 #include "mozilla/Attributes.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsWrapperCache.h"
17 #include "mozilla/dom/Nullable.h"
18 #include "js/TypeDecls.h"
19 
20 ////////////////////////////////////////////////////
21 // nsGeoPositionCoords
22 ////////////////////////////////////////////////////
23 
24 /**
25  * Simple object that holds a single point in space.
26  */
27 class nsGeoPositionCoords final : public nsIDOMGeoPositionCoords {
28  public:
29   NS_DECL_THREADSAFE_ISUPPORTS
30   NS_DECL_NSIDOMGEOPOSITIONCOORDS
31 
32   nsGeoPositionCoords(double aLat, double aLong, double aAlt, double aHError,
33                       double aVError, double aHeading, double aSpeed);
34 
35  private:
36   ~nsGeoPositionCoords();
37   const double mLat, mLong, mAlt, mHError, mVError, mHeading, mSpeed;
38 };
39 
40 ////////////////////////////////////////////////////
41 // nsGeoPosition
42 ////////////////////////////////////////////////////
43 
44 class nsGeoPosition final : public nsIDOMGeoPosition {
45  public:
46   NS_DECL_THREADSAFE_ISUPPORTS
47   NS_DECL_NSIDOMGEOPOSITION
48 
49   nsGeoPosition(double aLat, double aLong, double aAlt, double aHError,
50                 double aVError, double aHeading, double aSpeed,
51                 DOMTimeStamp aTimestamp);
52 
53   nsGeoPosition(nsIDOMGeoPositionCoords* aCoords, DOMTimeStamp aTimestamp);
54 
55  private:
56   ~nsGeoPosition();
57   DOMTimeStamp mTimestamp;
58   RefPtr<nsIDOMGeoPositionCoords> mCoords;
59 };
60 
61 ////////////////////////////////////////////////////
62 // WebIDL wrappers for the classes above
63 ////////////////////////////////////////////////////
64 
65 namespace mozilla {
66 namespace dom {
67 
68 class GeolocationCoordinates;
69 
70 class GeolocationPosition final : public nsISupports, public nsWrapperCache {
71   ~GeolocationPosition();
72 
73  public:
74   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
75   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(GeolocationPosition)
76 
77  public:
78   GeolocationPosition(nsISupports* aParent, nsIDOMGeoPosition* aGeoPosition);
79 
80   nsISupports* GetParentObject() const;
81 
82   virtual JSObject* WrapObject(JSContext* aCx,
83                                JS::Handle<JSObject*> aGivenProto) override;
84 
85   GeolocationCoordinates* Coords();
86 
87   uint64_t Timestamp() const;
88 
GetWrappedGeoPosition()89   nsIDOMGeoPosition* GetWrappedGeoPosition() { return mGeoPosition; }
90 
91  private:
92   RefPtr<GeolocationCoordinates> mCoordinates;
93   nsCOMPtr<nsISupports> mParent;
94   nsCOMPtr<nsIDOMGeoPosition> mGeoPosition;
95 };
96 
97 }  // namespace dom
98 }  // namespace mozilla
99 
100 #endif /* mozilla_dom_GeolocationPosition_h */
101