2012-05-21 11:12:37 +00: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 14:42:37 +00:00
|
|
|
|
2012-03-25 00:29:57 +00:00
|
|
|
#ifndef nsDeviceSensors_h
|
|
|
|
#define nsDeviceSensors_h
|
2009-08-21 14:42:37 +00:00
|
|
|
|
2012-03-25 00:29:57 +00:00
|
|
|
#include "nsIDeviceSensors.h"
|
2009-08-21 14:42:37 +00:00
|
|
|
#include "nsCOMArray.h"
|
2011-10-28 07:35:45 +00:00
|
|
|
#include "nsTArray.h"
|
2009-08-21 14:42:37 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsITimer.h"
|
2014-02-27 10:51:12 +00:00
|
|
|
#include "mozilla/dom/DeviceMotionEvent.h"
|
2012-03-09 18:40:43 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-03-21 06:36:17 +00:00
|
|
|
#include "mozilla/HalSensor.h"
|
2012-03-25 00:29:49 +00:00
|
|
|
#include "nsDataHashtable.h"
|
2009-08-21 14:42:37 +00:00
|
|
|
|
|
|
|
class nsIDOMWindow;
|
|
|
|
|
2013-04-19 22:18:33 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-25 00:29:57 +00:00
|
|
|
class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
|
2009-08-21 14:42:37 +00:00
|
|
|
{
|
2014-01-01 22:52:47 +00:00
|
|
|
typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit;
|
|
|
|
typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit;
|
2009-08-21 14:42:37 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-03-25 00:29:57 +00:00
|
|
|
NS_DECL_NSIDEVICESENSORS
|
2009-08-21 14:42:37 +00:00
|
|
|
|
2012-03-25 00:29:57 +00:00
|
|
|
nsDeviceSensors();
|
2009-08-21 14:42:37 +00:00
|
|
|
|
2012-03-21 06:36:17 +00:00
|
|
|
void Notify(const mozilla::hal::SensorData& aSensorData);
|
|
|
|
|
2009-08-21 14:42:37 +00:00
|
|
|
private:
|
2014-06-23 19:56:07 +00:00
|
|
|
virtual ~nsDeviceSensors();
|
|
|
|
|
2012-03-25 00:29:49 +00:00
|
|
|
// sensor -> window listener
|
|
|
|
nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners;
|
2012-05-02 16:43:45 +00:00
|
|
|
|
2013-03-09 11:34:29 +00:00
|
|
|
void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-02 16:43:45 +00:00
|
|
|
double value);
|
|
|
|
|
2013-03-09 11:34:29 +00:00
|
|
|
void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-02 16:43:45 +00:00
|
|
|
double aValue,
|
|
|
|
double aMin,
|
|
|
|
double aMax);
|
|
|
|
|
2013-03-09 11:34:29 +00:00
|
|
|
void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-16 20:27:54 +00:00
|
|
|
bool aNear);
|
|
|
|
|
2014-06-30 23:02:03 +00:00
|
|
|
void FireDOMOrientationEvent(mozilla::dom::EventTarget* target,
|
2011-06-20 05:36:17 +00:00
|
|
|
double alpha,
|
|
|
|
double beta,
|
|
|
|
double gamma);
|
|
|
|
|
2013-04-19 22:18:33 +00:00
|
|
|
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
|
|
|
mozilla::dom::EventTarget* target,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t type,
|
2011-06-20 05:36:17 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double z);
|
2012-03-13 22:29:29 +00:00
|
|
|
|
2012-03-09 18:40:43 +00:00
|
|
|
bool mEnabled;
|
2012-03-25 00:29:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
inline bool IsSensorEnabled(uint32_t aType) {
|
2012-03-25 00:29:49 +00:00
|
|
|
return mWindowListeners[aType]->Length() > 0;
|
|
|
|
}
|
|
|
|
|
2012-03-09 18:40:43 +00:00
|
|
|
mozilla::TimeStamp mLastDOMMotionEventTime;
|
2012-05-16 20:27:54 +00:00
|
|
|
bool mIsUserProximityNear;
|
2014-01-01 22:52:47 +00:00
|
|
|
mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
|
|
|
|
mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity;
|
|
|
|
mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
|
2009-08-21 14:42:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|