Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef nsDeviceSensors_h |
michael@0 | 6 | #define nsDeviceSensors_h |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIDeviceSensors.h" |
michael@0 | 9 | #include "nsCOMArray.h" |
michael@0 | 10 | #include "nsTArray.h" |
michael@0 | 11 | #include "nsCOMPtr.h" |
michael@0 | 12 | #include "nsITimer.h" |
michael@0 | 13 | #include "nsIDOMDeviceOrientationEvent.h" |
michael@0 | 14 | #include "mozilla/dom/DeviceMotionEvent.h" |
michael@0 | 15 | #include "mozilla/TimeStamp.h" |
michael@0 | 16 | #include "mozilla/HalSensor.h" |
michael@0 | 17 | #include "nsDataHashtable.h" |
michael@0 | 18 | |
michael@0 | 19 | class nsIDOMWindow; |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | namespace dom { |
michael@0 | 23 | class EventTarget; |
michael@0 | 24 | } |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver |
michael@0 | 28 | { |
michael@0 | 29 | typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit; |
michael@0 | 30 | typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit; |
michael@0 | 31 | public: |
michael@0 | 32 | NS_DECL_ISUPPORTS |
michael@0 | 33 | NS_DECL_NSIDEVICESENSORS |
michael@0 | 34 | |
michael@0 | 35 | nsDeviceSensors(); |
michael@0 | 36 | |
michael@0 | 37 | virtual ~nsDeviceSensors(); |
michael@0 | 38 | |
michael@0 | 39 | void Notify(const mozilla::hal::SensorData& aSensorData); |
michael@0 | 40 | |
michael@0 | 41 | private: |
michael@0 | 42 | // sensor -> window listener |
michael@0 | 43 | nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners; |
michael@0 | 44 | |
michael@0 | 45 | void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget, |
michael@0 | 46 | double value); |
michael@0 | 47 | |
michael@0 | 48 | void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget, |
michael@0 | 49 | double aValue, |
michael@0 | 50 | double aMin, |
michael@0 | 51 | double aMax); |
michael@0 | 52 | |
michael@0 | 53 | void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget, |
michael@0 | 54 | bool aNear); |
michael@0 | 55 | |
michael@0 | 56 | void FireDOMOrientationEvent(class nsIDOMDocument *domDoc, |
michael@0 | 57 | mozilla::dom::EventTarget* target, |
michael@0 | 58 | double alpha, |
michael@0 | 59 | double beta, |
michael@0 | 60 | double gamma); |
michael@0 | 61 | |
michael@0 | 62 | void FireDOMMotionEvent(class nsIDOMDocument *domDoc, |
michael@0 | 63 | mozilla::dom::EventTarget* target, |
michael@0 | 64 | uint32_t type, |
michael@0 | 65 | double x, |
michael@0 | 66 | double y, |
michael@0 | 67 | double z); |
michael@0 | 68 | |
michael@0 | 69 | bool mEnabled; |
michael@0 | 70 | |
michael@0 | 71 | inline bool IsSensorEnabled(uint32_t aType) { |
michael@0 | 72 | return mWindowListeners[aType]->Length() > 0; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | mozilla::TimeStamp mLastDOMMotionEventTime; |
michael@0 | 76 | bool mIsUserProximityNear; |
michael@0 | 77 | mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration; |
michael@0 | 78 | mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity; |
michael@0 | 79 | mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | #endif |