dom/src/geolocation/nsGeoPosition.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #ifndef nsGeoPosition_h
     7 #define nsGeoPosition_h
     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"
    19 ////////////////////////////////////////////////////
    20 // nsGeoPositionCoords
    21 ////////////////////////////////////////////////////
    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
    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 };
    42 ////////////////////////////////////////////////////
    43 // nsGeoPosition
    44 ////////////////////////////////////////////////////
    46 class nsGeoPosition MOZ_FINAL : public nsIDOMGeoPosition
    47 {
    48 public:
    49   NS_DECL_THREADSAFE_ISUPPORTS
    50   NS_DECL_NSIDOMGEOPOSITION
    52   nsGeoPosition(double aLat, double aLong,
    53                 double aAlt, double aHError,
    54                 double aVError, double aHeading,
    55                 double aSpeed, long long aTimestamp);
    58   nsGeoPosition(nsIDOMGeoPositionCoords *aCoords,
    59                 long long aTimestamp);
    61   nsGeoPosition(nsIDOMGeoPositionCoords *aCoords,
    62                 DOMTimeStamp aTimestamp);
    64 private:
    65   ~nsGeoPosition();
    66   long long mTimestamp;
    67   nsRefPtr<nsIDOMGeoPositionCoords> mCoords;
    68 };
    70 ////////////////////////////////////////////////////
    71 // WebIDL wrappers for the classes above
    72 ////////////////////////////////////////////////////
    74 namespace mozilla {
    75 namespace dom {
    77 class Coordinates;
    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)
    86 public:
    87   Position(nsISupports* aParent, nsIDOMGeoPosition* aGeoPosition);
    89   ~Position();
    91   nsISupports* GetParentObject() const;
    93   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    95   Coordinates* Coords();
    97   uint64_t Timestamp() const;
    99   nsIDOMGeoPosition* GetWrappedGeoPosition() { return mGeoPosition; }
   101 private:
   102   nsRefPtr<Coordinates> mCoordinates;
   103   nsCOMPtr<nsISupports> mParent;
   104   nsCOMPtr<nsIDOMGeoPosition> mGeoPosition;
   105 };
   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)
   114 public:
   115   Coordinates(Position* aPosition, nsIDOMGeoPositionCoords* aCoords);
   117   ~Coordinates();
   119   Position* GetParentObject() const;
   121   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   123   double Latitude() const;
   125   double Longitude() const;
   127   Nullable<double> GetAltitude() const;
   129   double Accuracy() const;
   131   Nullable<double> GetAltitudeAccuracy() const;
   133   Nullable<double> GetHeading() const;
   135   Nullable<double> GetSpeed() const;
   136 private:
   137   nsRefPtr<Position> mPosition;
   138   nsCOMPtr<nsIDOMGeoPositionCoords> mCoords;
   139 };
   141 } // namespace dom
   142 } // namespace mozilla
   144 #endif /* nsGeoPosition_h */

mercurial