1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsDeviceSensors_h
8 #define nsDeviceSensors_h
10 #include "nsIDeviceSensors.h"
11 #include "nsCOMArray.h"
14 #include "mozilla/dom/DeviceMotionEvent.h"
15 #include "mozilla/TimeStamp.h"
16 #include "mozilla/HalSensor.h"
20 namespace mozilla::dom
{
23 } // namespace mozilla::dom
25 class nsDeviceSensors
: public nsIDeviceSensors
,
26 public mozilla::hal::ISensorObserver
{
27 using DeviceAccelerationInit
= mozilla::dom::DeviceAccelerationInit
;
28 using DeviceRotationRateInit
= mozilla::dom::DeviceRotationRateInit
;
32 NS_DECL_NSIDEVICESENSORS
36 void Notify(const mozilla::hal::SensorData
& aSensorData
) override
;
39 virtual ~nsDeviceSensors();
41 // sensor -> window listener
42 nsTArray
<nsTArray
<nsIDOMWindow
*>*> mWindowListeners
;
44 void FireDOMLightEvent(mozilla::dom::EventTarget
* aTarget
, double value
);
46 void MaybeFireDOMUserProximityEvent(mozilla::dom::EventTarget
* aTarget
,
47 double aValue
, double aMax
);
49 void FireDOMUserProximityEvent(mozilla::dom::EventTarget
* aTarget
,
52 void FireDOMOrientationEvent(mozilla::dom::EventTarget
* target
, double aAlpha
,
53 double aBeta
, double aGamma
, bool aIsAbsolute
);
55 void FireDOMMotionEvent(mozilla::dom::Document
* domDoc
,
56 mozilla::dom::EventTarget
* target
, uint32_t type
,
57 PRTime timestamp
, double x
, double y
, double z
);
59 inline bool IsSensorEnabled(uint32_t aType
) {
60 return mWindowListeners
[aType
]->Length() > 0;
63 bool IsSensorAllowedByPref(uint32_t aType
, nsIDOMWindow
* aWindow
);
65 mozilla::TimeStamp mLastDOMMotionEventTime
;
66 bool mIsUserProximityNear
;
67 mozilla::Maybe
<DeviceAccelerationInit
> mLastAcceleration
;
68 mozilla::Maybe
<DeviceAccelerationInit
> mLastAccelerationIncludingGravity
;
69 mozilla::Maybe
<DeviceRotationRateInit
> mLastRotationRate
;