|
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/. */ |
|
4 |
|
5 #ifndef nsDeviceSensors_h |
|
6 #define nsDeviceSensors_h |
|
7 |
|
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" |
|
18 |
|
19 class nsIDOMWindow; |
|
20 |
|
21 namespace mozilla { |
|
22 namespace dom { |
|
23 class EventTarget; |
|
24 } |
|
25 } |
|
26 |
|
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 |
|
34 |
|
35 nsDeviceSensors(); |
|
36 |
|
37 virtual ~nsDeviceSensors(); |
|
38 |
|
39 void Notify(const mozilla::hal::SensorData& aSensorData); |
|
40 |
|
41 private: |
|
42 // sensor -> window listener |
|
43 nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners; |
|
44 |
|
45 void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget, |
|
46 double value); |
|
47 |
|
48 void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget, |
|
49 double aValue, |
|
50 double aMin, |
|
51 double aMax); |
|
52 |
|
53 void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget, |
|
54 bool aNear); |
|
55 |
|
56 void FireDOMOrientationEvent(class nsIDOMDocument *domDoc, |
|
57 mozilla::dom::EventTarget* target, |
|
58 double alpha, |
|
59 double beta, |
|
60 double gamma); |
|
61 |
|
62 void FireDOMMotionEvent(class nsIDOMDocument *domDoc, |
|
63 mozilla::dom::EventTarget* target, |
|
64 uint32_t type, |
|
65 double x, |
|
66 double y, |
|
67 double z); |
|
68 |
|
69 bool mEnabled; |
|
70 |
|
71 inline bool IsSensorEnabled(uint32_t aType) { |
|
72 return mWindowListeners[aType]->Length() > 0; |
|
73 } |
|
74 |
|
75 mozilla::TimeStamp mLastDOMMotionEventTime; |
|
76 bool mIsUserProximityNear; |
|
77 mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration; |
|
78 mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity; |
|
79 mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate; |
|
80 }; |
|
81 |
|
82 #endif |