Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsGeoPosition_h |
michael@0 | 7 | #define nsGeoPosition_h |
michael@0 | 8 | |
michael@0 | 9 | #include "nsAutoPtr.h" |
michael@0 | 10 | #include "nsIDOMGeoPositionCoords.h" |
michael@0 | 11 | #include "nsIDOMGeoPosition.h" |
michael@0 | 12 | #include "nsString.h" |
michael@0 | 13 | #include "mozilla/Attributes.h" |
michael@0 | 14 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 15 | #include "nsWrapperCache.h" |
michael@0 | 16 | #include "mozilla/dom/Nullable.h" |
michael@0 | 17 | #include "js/TypeDecls.h" |
michael@0 | 18 | |
michael@0 | 19 | //////////////////////////////////////////////////// |
michael@0 | 20 | // nsGeoPositionCoords |
michael@0 | 21 | //////////////////////////////////////////////////// |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Simple object that holds a single point in space. |
michael@0 | 25 | */ |
michael@0 | 26 | class nsGeoPositionCoords MOZ_FINAL : public nsIDOMGeoPositionCoords |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 30 | NS_DECL_NSIDOMGEOPOSITIONCOORDS |
michael@0 | 31 | |
michael@0 | 32 | nsGeoPositionCoords(double aLat, double aLong, |
michael@0 | 33 | double aAlt, double aHError, |
michael@0 | 34 | double aVError, double aHeading, |
michael@0 | 35 | double aSpeed); |
michael@0 | 36 | ~nsGeoPositionCoords(); |
michael@0 | 37 | private: |
michael@0 | 38 | const double mLat, mLong, mAlt, mHError, mVError, mHeading, mSpeed; |
michael@0 | 39 | }; |
michael@0 | 40 | |
michael@0 | 41 | |
michael@0 | 42 | //////////////////////////////////////////////////// |
michael@0 | 43 | // nsGeoPosition |
michael@0 | 44 | //////////////////////////////////////////////////// |
michael@0 | 45 | |
michael@0 | 46 | class nsGeoPosition MOZ_FINAL : public nsIDOMGeoPosition |
michael@0 | 47 | { |
michael@0 | 48 | public: |
michael@0 | 49 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 50 | NS_DECL_NSIDOMGEOPOSITION |
michael@0 | 51 | |
michael@0 | 52 | nsGeoPosition(double aLat, double aLong, |
michael@0 | 53 | double aAlt, double aHError, |
michael@0 | 54 | double aVError, double aHeading, |
michael@0 | 55 | double aSpeed, long long aTimestamp); |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | nsGeoPosition(nsIDOMGeoPositionCoords *aCoords, |
michael@0 | 59 | long long aTimestamp); |
michael@0 | 60 | |
michael@0 | 61 | nsGeoPosition(nsIDOMGeoPositionCoords *aCoords, |
michael@0 | 62 | DOMTimeStamp aTimestamp); |
michael@0 | 63 | |
michael@0 | 64 | private: |
michael@0 | 65 | ~nsGeoPosition(); |
michael@0 | 66 | long long mTimestamp; |
michael@0 | 67 | nsRefPtr<nsIDOMGeoPositionCoords> mCoords; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | //////////////////////////////////////////////////// |
michael@0 | 71 | // WebIDL wrappers for the classes above |
michael@0 | 72 | //////////////////////////////////////////////////// |
michael@0 | 73 | |
michael@0 | 74 | namespace mozilla { |
michael@0 | 75 | namespace dom { |
michael@0 | 76 | |
michael@0 | 77 | class Coordinates; |
michael@0 | 78 | |
michael@0 | 79 | class Position MOZ_FINAL : public nsISupports, |
michael@0 | 80 | public nsWrapperCache |
michael@0 | 81 | { |
michael@0 | 82 | public: |
michael@0 | 83 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 84 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Position) |
michael@0 | 85 | |
michael@0 | 86 | public: |
michael@0 | 87 | Position(nsISupports* aParent, nsIDOMGeoPosition* aGeoPosition); |
michael@0 | 88 | |
michael@0 | 89 | ~Position(); |
michael@0 | 90 | |
michael@0 | 91 | nsISupports* GetParentObject() const; |
michael@0 | 92 | |
michael@0 | 93 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 94 | |
michael@0 | 95 | Coordinates* Coords(); |
michael@0 | 96 | |
michael@0 | 97 | uint64_t Timestamp() const; |
michael@0 | 98 | |
michael@0 | 99 | nsIDOMGeoPosition* GetWrappedGeoPosition() { return mGeoPosition; } |
michael@0 | 100 | |
michael@0 | 101 | private: |
michael@0 | 102 | nsRefPtr<Coordinates> mCoordinates; |
michael@0 | 103 | nsCOMPtr<nsISupports> mParent; |
michael@0 | 104 | nsCOMPtr<nsIDOMGeoPosition> mGeoPosition; |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | class Coordinates MOZ_FINAL : public nsISupports, |
michael@0 | 108 | public nsWrapperCache |
michael@0 | 109 | { |
michael@0 | 110 | public: |
michael@0 | 111 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 112 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Coordinates) |
michael@0 | 113 | |
michael@0 | 114 | public: |
michael@0 | 115 | Coordinates(Position* aPosition, nsIDOMGeoPositionCoords* aCoords); |
michael@0 | 116 | |
michael@0 | 117 | ~Coordinates(); |
michael@0 | 118 | |
michael@0 | 119 | Position* GetParentObject() const; |
michael@0 | 120 | |
michael@0 | 121 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 122 | |
michael@0 | 123 | double Latitude() const; |
michael@0 | 124 | |
michael@0 | 125 | double Longitude() const; |
michael@0 | 126 | |
michael@0 | 127 | Nullable<double> GetAltitude() const; |
michael@0 | 128 | |
michael@0 | 129 | double Accuracy() const; |
michael@0 | 130 | |
michael@0 | 131 | Nullable<double> GetAltitudeAccuracy() const; |
michael@0 | 132 | |
michael@0 | 133 | Nullable<double> GetHeading() const; |
michael@0 | 134 | |
michael@0 | 135 | Nullable<double> GetSpeed() const; |
michael@0 | 136 | private: |
michael@0 | 137 | nsRefPtr<Position> mPosition; |
michael@0 | 138 | nsCOMPtr<nsIDOMGeoPositionCoords> mCoords; |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | } // namespace dom |
michael@0 | 142 | } // namespace mozilla |
michael@0 | 143 | |
michael@0 | 144 | #endif /* nsGeoPosition_h */ |
michael@0 | 145 |