Line data Source code
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/. */
6 :
7 : #ifndef nsDeviceSensors_h
8 : #define nsDeviceSensors_h
9 :
10 : #include "nsIDeviceSensors.h"
11 : #include "nsCOMArray.h"
12 : #include "nsTArray.h"
13 : #include "nsCOMPtr.h"
14 : #include "nsITimer.h"
15 : #include "mozilla/dom/DeviceMotionEvent.h"
16 : #include "mozilla/TimeStamp.h"
17 : #include "mozilla/HalSensor.h"
18 : #include "nsDataHashtable.h"
19 :
20 : class nsIDOMWindow;
21 :
22 : namespace mozilla {
23 : namespace dom {
24 : class EventTarget;
25 : } // namespace dom
26 : } // namespace mozilla
27 :
28 : class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
29 : {
30 : typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit;
31 : typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit;
32 : public:
33 : NS_DECL_ISUPPORTS
34 : NS_DECL_NSIDEVICESENSORS
35 :
36 : nsDeviceSensors();
37 :
38 : void Notify(const mozilla::hal::SensorData& aSensorData) override;
39 :
40 : private:
41 : virtual ~nsDeviceSensors();
42 :
43 : // sensor -> window listener
44 : nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners;
45 :
46 : void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
47 : double value);
48 :
49 : void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
50 : double aValue,
51 : double aMin,
52 : double aMax);
53 :
54 : void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
55 : bool aNear);
56 :
57 : void FireDOMOrientationEvent(mozilla::dom::EventTarget* target,
58 : double aAlpha,
59 : double aBeta,
60 : double aGamma,
61 : bool aIsAbsolute);
62 :
63 : void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
64 : mozilla::dom::EventTarget* target,
65 : uint32_t type,
66 : PRTime timestamp,
67 : double x,
68 : double y,
69 : double z);
70 :
71 : bool mEnabled;
72 :
73 0 : inline bool IsSensorEnabled(uint32_t aType) {
74 0 : return mWindowListeners[aType]->Length() > 0;
75 : }
76 :
77 : bool AreSensorEventsDisabled(nsIDOMWindow* aWindow);
78 :
79 : mozilla::TimeStamp mLastDOMMotionEventTime;
80 : bool mIsUserProximityNear;
81 : mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
82 : mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncludingGravity;
83 : mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
84 : };
85 :
86 : #endif
|