Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / system / nsDeviceSensors.h
blobdd079088e6de205f1a71c4e8a78fa95d6ee67ea7
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"
12 #include "nsTArray.h"
13 #include "nsCOMPtr.h"
14 #include "mozilla/dom/DeviceMotionEvent.h"
15 #include "mozilla/TimeStamp.h"
16 #include "mozilla/HalSensor.h"
18 class nsIDOMWindow;
20 namespace mozilla::dom {
21 class Document;
22 class EventTarget;
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;
30 public:
31 NS_DECL_ISUPPORTS
32 NS_DECL_NSIDEVICESENSORS
34 nsDeviceSensors();
36 void Notify(const mozilla::hal::SensorData& aSensorData) override;
38 private:
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,
50 bool aNear);
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;
72 #endif