Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
5 #ifndef nsDeviceSensors_h
6 #define nsDeviceSensors_h
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"
19 class nsIDOMWindow;
21 namespace mozilla {
22 namespace dom {
23 class EventTarget;
24 }
25 }
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
35 nsDeviceSensors();
37 virtual ~nsDeviceSensors();
39 void Notify(const mozilla::hal::SensorData& aSensorData);
41 private:
42 // sensor -> window listener
43 nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners;
45 void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
46 double value);
48 void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
49 double aValue,
50 double aMin,
51 double aMax);
53 void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
54 bool aNear);
56 void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
57 mozilla::dom::EventTarget* target,
58 double alpha,
59 double beta,
60 double gamma);
62 void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
63 mozilla::dom::EventTarget* target,
64 uint32_t type,
65 double x,
66 double y,
67 double z);
69 bool mEnabled;
71 inline bool IsSensorEnabled(uint32_t aType) {
72 return mWindowListeners[aType]->Length() > 0;
73 }
75 mozilla::TimeStamp mLastDOMMotionEventTime;
76 bool mIsUserProximityNear;
77 mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
78 mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity;
79 mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
80 };
82 #endif