dom/system/nsDeviceSensors.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsDeviceSensors_h
     6 #define nsDeviceSensors_h
     8 #include "nsIDeviceSensors.h"
     9 #include "nsCOMArray.h"
    10 #include "nsTArray.h"
    11 #include "nsCOMPtr.h"
    12 #include "nsITimer.h"
    13 #include "nsIDOMDeviceOrientationEvent.h"
    14 #include "mozilla/dom/DeviceMotionEvent.h"
    15 #include "mozilla/TimeStamp.h"
    16 #include "mozilla/HalSensor.h"
    17 #include "nsDataHashtable.h"
    19 class nsIDOMWindow;
    21 namespace mozilla {
    22 namespace dom {
    23 class EventTarget;
    24 }
    25 }
    27 class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
    28 {
    29   typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit;
    30   typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit;
    31 public:
    32   NS_DECL_ISUPPORTS
    33   NS_DECL_NSIDEVICESENSORS
    35   nsDeviceSensors();
    37   virtual ~nsDeviceSensors();
    39   void Notify(const mozilla::hal::SensorData& aSensorData);
    41 private:
    42   // sensor -> window listener
    43   nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners;
    45   void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
    46                          double value);
    48   void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
    49                              double aValue,
    50                              double aMin,
    51                              double aMax);
    53   void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
    54                                  bool aNear);
    56   void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
    57                                mozilla::dom::EventTarget* target,
    58                                double alpha,
    59                                double beta,
    60                                double gamma);
    62   void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
    63                           mozilla::dom::EventTarget* target,
    64                           uint32_t type,
    65                           double x,
    66                           double y,
    67                           double z);
    69   bool mEnabled;
    71   inline bool IsSensorEnabled(uint32_t aType) {
    72     return mWindowListeners[aType]->Length() > 0;
    73   }
    75   mozilla::TimeStamp mLastDOMMotionEventTime;
    76   bool mIsUserProximityNear;
    77   mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
    78   mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity;
    79   mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
    80 };
    82 #endif

mercurial