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"
13 #include "mozilla/dom/DeviceMotionEvent.h"
14 #include "mozilla/TimeStamp.h"
15 #include "mozilla/HalSensor.h"
16 #include "nsDataHashtable.h"
26 class nsDeviceSensors
: public nsIDeviceSensors
, public mozilla::hal::ISensorObserver
28 typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit
;
29 typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit
;
32 NS_DECL_NSIDEVICESENSORS
36 void Notify(const mozilla::hal::SensorData
& aSensorData
);
39 virtual ~nsDeviceSensors();
41 // sensor -> window listener
42 nsTArray
<nsTArray
<nsIDOMWindow
*>* > mWindowListeners
;
44 void FireDOMLightEvent(mozilla::dom::EventTarget
* aTarget
,
47 void FireDOMProximityEvent(mozilla::dom::EventTarget
* aTarget
,
52 void FireDOMUserProximityEvent(mozilla::dom::EventTarget
* aTarget
,
55 void FireDOMOrientationEvent(mozilla::dom::EventTarget
* target
,
60 void FireDOMMotionEvent(class nsIDOMDocument
*domDoc
,
61 mozilla::dom::EventTarget
* target
,
69 inline bool IsSensorEnabled(uint32_t aType
) {
70 return mWindowListeners
[aType
]->Length() > 0;
73 mozilla::TimeStamp mLastDOMMotionEventTime
;
74 bool mIsUserProximityNear
;
75 mozilla::Maybe
<DeviceAccelerationInit
> mLastAcceleration
;
76 mozilla::Maybe
<DeviceAccelerationInit
> mLastAccelerationIncluduingGravity
;
77 mozilla::Maybe
<DeviceRotationRateInit
> mLastRotationRate
;