|
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/. */ |
|
5 |
|
6 #ifndef nsGeoPosition_h |
|
7 #define nsGeoPosition_h |
|
8 |
|
9 #include "nsAutoPtr.h" |
|
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 MOZ_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 ~nsGeoPositionCoords(); |
|
37 private: |
|
38 const double mLat, mLong, mAlt, mHError, mVError, mHeading, mSpeed; |
|
39 }; |
|
40 |
|
41 |
|
42 //////////////////////////////////////////////////// |
|
43 // nsGeoPosition |
|
44 //////////////////////////////////////////////////// |
|
45 |
|
46 class nsGeoPosition MOZ_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 nsRefPtr<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 MOZ_FINAL : public nsISupports, |
|
80 public nsWrapperCache |
|
81 { |
|
82 public: |
|
83 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
84 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Position) |
|
85 |
|
86 public: |
|
87 Position(nsISupports* aParent, nsIDOMGeoPosition* aGeoPosition); |
|
88 |
|
89 ~Position(); |
|
90 |
|
91 nsISupports* GetParentObject() const; |
|
92 |
|
93 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
94 |
|
95 Coordinates* Coords(); |
|
96 |
|
97 uint64_t Timestamp() const; |
|
98 |
|
99 nsIDOMGeoPosition* GetWrappedGeoPosition() { return mGeoPosition; } |
|
100 |
|
101 private: |
|
102 nsRefPtr<Coordinates> mCoordinates; |
|
103 nsCOMPtr<nsISupports> mParent; |
|
104 nsCOMPtr<nsIDOMGeoPosition> mGeoPosition; |
|
105 }; |
|
106 |
|
107 class Coordinates MOZ_FINAL : public nsISupports, |
|
108 public nsWrapperCache |
|
109 { |
|
110 public: |
|
111 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
112 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Coordinates) |
|
113 |
|
114 public: |
|
115 Coordinates(Position* aPosition, nsIDOMGeoPositionCoords* aCoords); |
|
116 |
|
117 ~Coordinates(); |
|
118 |
|
119 Position* GetParentObject() const; |
|
120 |
|
121 virtual JSObject* WrapObject(JSContext* aCx) MOZ_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 nsRefPtr<Position> mPosition; |
|
138 nsCOMPtr<nsIDOMGeoPositionCoords> mCoords; |
|
139 }; |
|
140 |
|
141 } // namespace dom |
|
142 } // namespace mozilla |
|
143 |
|
144 #endif /* nsGeoPosition_h */ |
|
145 |