Line data Source code
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 nsGeoPosition_h
8 : #define nsGeoPosition_h
9 :
10 : #include "nsIDOMGeoPositionCoords.h"
11 : #include "nsIDOMGeoPosition.h"
12 : #include "nsString.h"
13 : #include "mozilla/Attributes.h"
14 : #include "nsCycleCollectionParticipant.h"
15 : #include "nsWrapperCache.h"
16 : #include "mozilla/dom/Nullable.h"
17 : #include "js/TypeDecls.h"
18 :
19 : ////////////////////////////////////////////////////
20 : // nsGeoPositionCoords
21 : ////////////////////////////////////////////////////
22 :
23 : /**
24 : * Simple object that holds a single point in space.
25 : */
26 : class nsGeoPositionCoords final : public nsIDOMGeoPositionCoords
27 : {
28 : public:
29 : NS_DECL_THREADSAFE_ISUPPORTS
30 : NS_DECL_NSIDOMGEOPOSITIONCOORDS
31 :
32 : nsGeoPositionCoords(double aLat, double aLong,
33 : double aAlt, double aHError,
34 : double aVError, double aHeading,
35 : double aSpeed);
36 : private:
37 : ~nsGeoPositionCoords();
38 : const double mLat, mLong, mAlt, mHError, mVError, mHeading, mSpeed;
39 : };
40 :
41 :
42 : ////////////////////////////////////////////////////
43 : // nsGeoPosition
44 : ////////////////////////////////////////////////////
45 :
46 : class nsGeoPosition final : public nsIDOMGeoPosition
47 : {
48 : public:
49 : NS_DECL_THREADSAFE_ISUPPORTS
50 : NS_DECL_NSIDOMGEOPOSITION
51 :
52 : nsGeoPosition(double aLat, double aLong,
53 : double aAlt, double aHError,
54 : double aVError, double aHeading,
55 : double aSpeed, long long aTimestamp);
56 :
57 :
58 : nsGeoPosition(nsIDOMGeoPositionCoords *aCoords,
59 : long long aTimestamp);
60 :
61 : nsGeoPosition(nsIDOMGeoPositionCoords *aCoords,
62 : DOMTimeStamp aTimestamp);
63 :
64 : private:
65 : ~nsGeoPosition();
66 : long long mTimestamp;
67 : RefPtr<nsIDOMGeoPositionCoords> mCoords;
68 : };
69 :
70 : ////////////////////////////////////////////////////
71 : // WebIDL wrappers for the classes above
72 : ////////////////////////////////////////////////////
73 :
74 : namespace mozilla {
75 : namespace dom {
76 :
77 : class Coordinates;
78 :
79 : class Position final : public nsISupports,
80 : public nsWrapperCache
81 : {
82 : ~Position();
83 :
84 : public:
85 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
86 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Position)
87 :
88 : public:
89 : Position(nsISupports* aParent, nsIDOMGeoPosition* aGeoPosition);
90 :
91 : nsISupports* GetParentObject() const;
92 :
93 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
94 :
95 : Coordinates* Coords();
96 :
97 : uint64_t Timestamp() const;
98 :
99 : nsIDOMGeoPosition* GetWrappedGeoPosition() { return mGeoPosition; }
100 :
101 : private:
102 : RefPtr<Coordinates> mCoordinates;
103 : nsCOMPtr<nsISupports> mParent;
104 : nsCOMPtr<nsIDOMGeoPosition> mGeoPosition;
105 : };
106 :
107 : class Coordinates final : public nsISupports,
108 : public nsWrapperCache
109 : {
110 : ~Coordinates();
111 :
112 : public:
113 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
114 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Coordinates)
115 :
116 : public:
117 : Coordinates(Position* aPosition, nsIDOMGeoPositionCoords* aCoords);
118 :
119 : Position* GetParentObject() const;
120 :
121 : virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
122 :
123 : double Latitude() const;
124 :
125 : double Longitude() const;
126 :
127 : Nullable<double> GetAltitude() const;
128 :
129 : double Accuracy() const;
130 :
131 : Nullable<double> GetAltitudeAccuracy() const;
132 :
133 : Nullable<double> GetHeading() const;
134 :
135 : Nullable<double> GetSpeed() const;
136 : private:
137 : RefPtr<Position> mPosition;
138 : nsCOMPtr<nsIDOMGeoPositionCoords> mCoords;
139 : };
140 :
141 : } // namespace dom
142 : } // namespace mozilla
143 :
144 : #endif /* nsGeoPosition_h */
145 :
|