2012-05-21 15:12:37 +04: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 18:42:37 +04:00
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
#ifndef nsDeviceSensors_h
|
|
|
|
#define nsDeviceSensors_h
|
2009-08-21 18:42:37 +04:00
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
#include "nsIDeviceSensors.h"
|
2011-06-20 09:36:17 +04:00
|
|
|
#include "nsIDOMDeviceMotionEvent.h"
|
2009-08-21 18:42:37 +04:00
|
|
|
#include "nsCOMArray.h"
|
2011-10-28 11:35:45 +04:00
|
|
|
#include "nsTArray.h"
|
2009-08-21 18:42:37 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsITimer.h"
|
2012-05-02 20:43:45 +04:00
|
|
|
#include "nsIDOMDeviceLightEvent.h"
|
2012-03-09 22:40:43 +04:00
|
|
|
#include "nsIDOMDeviceOrientationEvent.h"
|
2012-05-02 20:43:45 +04:00
|
|
|
#include "nsIDOMDeviceProximityEvent.h"
|
2012-05-17 00:27:54 +04:00
|
|
|
#include "nsIDOMUserProximityEvent.h"
|
2012-03-09 22:40:43 +04:00
|
|
|
#include "nsIDOMDeviceMotionEvent.h"
|
|
|
|
#include "nsDOMDeviceMotionEvent.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-03-21 10:36:17 +04:00
|
|
|
#include "mozilla/HalSensor.h"
|
2012-03-25 04:29:49 +04:00
|
|
|
#include "nsDataHashtable.h"
|
2009-08-21 18:42:37 +04:00
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
#define NS_DEVICE_SENSORS_CID \
|
2010-06-25 16:25:31 +04:00
|
|
|
{ 0xecba5203, 0x77da, 0x465a, \
|
|
|
|
{ 0x86, 0x5e, 0x78, 0xb7, 0xaf, 0x10, 0xd8, 0xf7 } }
|
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
#define NS_DEVICE_SENSORS_CONTRACTID "@mozilla.org/devicesensors;1"
|
2010-06-25 16:25:31 +04:00
|
|
|
|
2009-08-21 18:42:37 +04:00
|
|
|
class nsIDOMWindow;
|
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
|
2009-08-21 18:42:37 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-03-25 04:29:57 +04:00
|
|
|
NS_DECL_NSIDEVICESENSORS
|
2009-08-21 18:42:37 +04:00
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
nsDeviceSensors();
|
2009-08-21 18:42:37 +04:00
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
virtual ~nsDeviceSensors();
|
2009-08-27 03:57:08 +04:00
|
|
|
|
2012-03-21 10:36:17 +04:00
|
|
|
void Notify(const mozilla::hal::SensorData& aSensorData);
|
|
|
|
|
2009-08-21 18:42:37 +04:00
|
|
|
private:
|
2012-03-25 04:29:49 +04:00
|
|
|
// sensor -> window listener
|
|
|
|
nsTArray<nsTArray<nsIDOMWindow*>* > mWindowListeners;
|
2012-05-02 20:43:45 +04:00
|
|
|
|
2013-03-09 15:34:29 +04:00
|
|
|
void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-02 20:43:45 +04:00
|
|
|
double value);
|
|
|
|
|
2013-03-09 15:34:29 +04:00
|
|
|
void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-02 20:43:45 +04:00
|
|
|
double aValue,
|
|
|
|
double aMin,
|
|
|
|
double aMax);
|
|
|
|
|
2013-03-09 15:34:29 +04:00
|
|
|
void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
|
2012-05-17 00:27:54 +04:00
|
|
|
bool aNear);
|
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
|
|
|
|
mozilla::dom::EventTarget* target,
|
2011-06-20 09:36:17 +04:00
|
|
|
double alpha,
|
|
|
|
double beta,
|
|
|
|
double gamma);
|
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
|
|
|
mozilla::dom::EventTarget* target,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t type,
|
2011-06-20 09:36:17 +04:00
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double z);
|
2012-03-14 02:29:29 +04:00
|
|
|
|
2012-03-09 22:40:43 +04:00
|
|
|
bool mEnabled;
|
2012-03-25 04:29:49 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline bool IsSensorEnabled(uint32_t aType) {
|
2012-03-25 04:29:49 +04:00
|
|
|
return mWindowListeners[aType]->Length() > 0;
|
|
|
|
}
|
|
|
|
|
2012-03-09 22:40:43 +04:00
|
|
|
mozilla::TimeStamp mLastDOMMotionEventTime;
|
2012-05-17 00:27:54 +04:00
|
|
|
bool mIsUserProximityNear;
|
2012-03-09 22:40:43 +04:00
|
|
|
nsRefPtr<nsDOMDeviceAcceleration> mLastAcceleration;
|
|
|
|
nsRefPtr<nsDOMDeviceAcceleration> mLastAccelerationIncluduingGravity;
|
|
|
|
nsRefPtr<nsDOMDeviceRotationRate> mLastRotationRate;
|
2009-08-21 18:42:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|