/src/mozilla-central/dom/system/nsDeviceSensors.h
Line | Count | Source (jump to first uncovered line) |
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 | | class nsIDocument; |
22 | | |
23 | | namespace mozilla { |
24 | | namespace dom { |
25 | | class EventTarget; |
26 | | } // namespace dom |
27 | | } // namespace mozilla |
28 | | |
29 | | class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver |
30 | | { |
31 | | typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit; |
32 | | typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit; |
33 | | public: |
34 | | NS_DECL_ISUPPORTS |
35 | | NS_DECL_NSIDEVICESENSORS |
36 | | |
37 | | nsDeviceSensors(); |
38 | | |
39 | | void Notify(const mozilla::hal::SensorData& aSensorData) override; |
40 | | |
41 | | private: |
42 | | virtual ~nsDeviceSensors(); |
43 | | |
44 | | // sensor -> window listener |
45 | | nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners; |
46 | | |
47 | | void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget, |
48 | | double value); |
49 | | |
50 | | void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget, |
51 | | double aValue, |
52 | | double aMin, |
53 | | double aMax); |
54 | | |
55 | | void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget, |
56 | | bool aNear); |
57 | | |
58 | | void FireDOMOrientationEvent(mozilla::dom::EventTarget* target, |
59 | | double aAlpha, |
60 | | double aBeta, |
61 | | double aGamma, |
62 | | bool aIsAbsolute); |
63 | | |
64 | | void FireDOMMotionEvent(nsIDocument* domDoc, |
65 | | mozilla::dom::EventTarget* target, |
66 | | uint32_t type, |
67 | | PRTime timestamp, |
68 | | double x, |
69 | | double y, |
70 | | double z); |
71 | | |
72 | 0 | inline bool IsSensorEnabled(uint32_t aType) { |
73 | 0 | return mWindowListeners[aType]->Length() > 0; |
74 | 0 | } |
75 | | |
76 | | bool IsSensorAllowedByPref(uint32_t aType, nsIDOMWindow* aWindow); |
77 | | |
78 | | mozilla::TimeStamp mLastDOMMotionEventTime; |
79 | | bool mIsUserProximityNear; |
80 | | mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration; |
81 | | mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncludingGravity; |
82 | | mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate; |
83 | | }; |
84 | | |
85 | | #endif |