2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-08-21 07:42:37 -07:00
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
#ifndef nsDeviceSensors_h
|
|
|
|
#define nsDeviceSensors_h
|
2009-08-21 07:42:37 -07:00
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
#include "nsIDeviceSensors.h"
|
2009-08-21 07:42:37 -07:00
|
|
|
#include "nsCOMArray.h"
|
2011-10-28 00:35:45 -07:00
|
|
|
#include "nsTArray.h"
|
2009-08-21 07:42:37 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsITimer.h"
|
2012-03-09 10:40:43 -08:00
|
|
|
#include "nsIDOMDeviceOrientationEvent.h"
|
2014-02-27 02:51:12 -08:00
|
|
|
#include "mozilla/dom/DeviceMotionEvent.h"
|
2012-03-09 10:40:43 -08:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-03-20 23:36:17 -07:00
|
|
|
#include "mozilla/HalSensor.h"
|
2012-03-24 17:29:49 -07:00
|
|
|
#include "nsDataHashtable.h"
|
2009-08-21 07:42:37 -07:00
|
|
|
|
|
|
|
class nsIDOMWindow;
|
|
|
|
|
2013-04-19 15:18:33 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
|
2009-08-21 07:42:37 -07:00
|
|
|
{
|
2014-01-01 14:52:47 -08:00
|
|
|
typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit;
|
|
|
|
typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit;
|
2009-08-21 07:42:37 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-03-24 17:29:57 -07:00
|
|
|
NS_DECL_NSIDEVICESENSORS
|
2009-08-21 07:42:37 -07:00
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
nsDeviceSensors();
|
2009-08-21 07:42:37 -07:00
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
virtual ~nsDeviceSensors();
|
2009-08-26 16:57:08 -07:00
|
|
|
|
2012-03-20 23:36:17 -07:00
|
|
|
void Notify(const mozilla::hal::SensorData& aSensorData);
|
|
|
|
|
2009-08-21 07:42:37 -07:00
|
|
|
private:
|
2012-03-24 17:29:49 -07:00
|
|
|
// sensor -> window listener
|
|
|
|
nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners;
|
2012-05-02 09:43:45 -07:00
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-02 09:43:45 -07:00
|
|
|
double value);
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-02 09:43:45 -07:00
|
|
|
double aValue,
|
|
|
|
double aMin,
|
|
|
|
double aMax);
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-16 13:27:54 -07:00
|
|
|
bool aNear);
|
|
|
|
|
2013-04-19 15:18:33 -07:00
|
|
|
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
|
|
|
|
mozilla::dom::EventTarget* target,
|
2011-06-19 22:36:17 -07:00
|
|
|
double alpha,
|
|
|
|
double beta,
|
|
|
|
double gamma);
|
|
|
|
|
2013-04-19 15:18:33 -07:00
|
|
|
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
|
|
|
mozilla::dom::EventTarget* target,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t type,
|
2011-06-19 22:36:17 -07:00
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double z);
|
2012-03-13 15:29:29 -07:00
|
|
|
|
2012-03-09 10:40:43 -08:00
|
|
|
bool mEnabled;
|
2012-03-24 17:29:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
inline bool IsSensorEnabled(uint32_t aType) {
|
2012-03-24 17:29:49 -07:00
|
|
|
return mWindowListeners[aType]->Length() > 0;
|
|
|
|
}
|
|
|
|
|
2012-03-09 10:40:43 -08:00
|
|
|
mozilla::TimeStamp mLastDOMMotionEventTime;
|
2012-05-16 13:27:54 -07:00
|
|
|
bool mIsUserProximityNear;
|
2014-01-01 14:52:47 -08:00
|
|
|
mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
|
|
|
|
mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity;
|
|
|
|
mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
|
2009-08-21 07:42:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|