1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/nsDeviceSensors.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef nsDeviceSensors_h 1.9 +#define nsDeviceSensors_h 1.10 + 1.11 +#include "nsIDeviceSensors.h" 1.12 +#include "nsCOMArray.h" 1.13 +#include "nsTArray.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "nsITimer.h" 1.16 +#include "nsIDOMDeviceOrientationEvent.h" 1.17 +#include "mozilla/dom/DeviceMotionEvent.h" 1.18 +#include "mozilla/TimeStamp.h" 1.19 +#include "mozilla/HalSensor.h" 1.20 +#include "nsDataHashtable.h" 1.21 + 1.22 +class nsIDOMWindow; 1.23 + 1.24 +namespace mozilla { 1.25 +namespace dom { 1.26 +class EventTarget; 1.27 +} 1.28 +} 1.29 + 1.30 +class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver 1.31 +{ 1.32 + typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit; 1.33 + typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit; 1.34 +public: 1.35 + NS_DECL_ISUPPORTS 1.36 + NS_DECL_NSIDEVICESENSORS 1.37 + 1.38 + nsDeviceSensors(); 1.39 + 1.40 + virtual ~nsDeviceSensors(); 1.41 + 1.42 + void Notify(const mozilla::hal::SensorData& aSensorData); 1.43 + 1.44 +private: 1.45 + // sensor -> window listener 1.46 + nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners; 1.47 + 1.48 + void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget, 1.49 + double value); 1.50 + 1.51 + void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget, 1.52 + double aValue, 1.53 + double aMin, 1.54 + double aMax); 1.55 + 1.56 + void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget, 1.57 + bool aNear); 1.58 + 1.59 + void FireDOMOrientationEvent(class nsIDOMDocument *domDoc, 1.60 + mozilla::dom::EventTarget* target, 1.61 + double alpha, 1.62 + double beta, 1.63 + double gamma); 1.64 + 1.65 + void FireDOMMotionEvent(class nsIDOMDocument *domDoc, 1.66 + mozilla::dom::EventTarget* target, 1.67 + uint32_t type, 1.68 + double x, 1.69 + double y, 1.70 + double z); 1.71 + 1.72 + bool mEnabled; 1.73 + 1.74 + inline bool IsSensorEnabled(uint32_t aType) { 1.75 + return mWindowListeners[aType]->Length() > 0; 1.76 + } 1.77 + 1.78 + mozilla::TimeStamp mLastDOMMotionEventTime; 1.79 + bool mIsUserProximityNear; 1.80 + mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration; 1.81 + mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity; 1.82 + mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate; 1.83 +}; 1.84 + 1.85 +#endif