michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDeviceSensors_h michael@0: #define nsDeviceSensors_h michael@0: michael@0: #include "nsIDeviceSensors.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsTArray.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsITimer.h" michael@0: #include "nsIDOMDeviceOrientationEvent.h" michael@0: #include "mozilla/dom/DeviceMotionEvent.h" michael@0: #include "mozilla/TimeStamp.h" michael@0: #include "mozilla/HalSensor.h" michael@0: #include "nsDataHashtable.h" michael@0: michael@0: class nsIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class EventTarget; michael@0: } michael@0: } michael@0: michael@0: class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver michael@0: { michael@0: typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit; michael@0: typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit; michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIDEVICESENSORS michael@0: michael@0: nsDeviceSensors(); michael@0: michael@0: virtual ~nsDeviceSensors(); michael@0: michael@0: void Notify(const mozilla::hal::SensorData& aSensorData); michael@0: michael@0: private: michael@0: // sensor -> window listener michael@0: nsTArray* > mWindowListeners; michael@0: michael@0: void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget, michael@0: double value); michael@0: michael@0: void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget, michael@0: double aValue, michael@0: double aMin, michael@0: double aMax); michael@0: michael@0: void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget, michael@0: bool aNear); michael@0: michael@0: void FireDOMOrientationEvent(class nsIDOMDocument *domDoc, michael@0: mozilla::dom::EventTarget* target, michael@0: double alpha, michael@0: double beta, michael@0: double gamma); michael@0: michael@0: void FireDOMMotionEvent(class nsIDOMDocument *domDoc, michael@0: mozilla::dom::EventTarget* target, michael@0: uint32_t type, michael@0: double x, michael@0: double y, michael@0: double z); michael@0: michael@0: bool mEnabled; michael@0: michael@0: inline bool IsSensorEnabled(uint32_t aType) { michael@0: return mWindowListeners[aType]->Length() > 0; michael@0: } michael@0: michael@0: mozilla::TimeStamp mLastDOMMotionEventTime; michael@0: bool mIsUserProximityNear; michael@0: mozilla::Maybe mLastAcceleration; michael@0: mozilla::Maybe mLastAccelerationIncluduingGravity; michael@0: mozilla::Maybe mLastRotationRate; michael@0: }; michael@0: michael@0: #endif