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;
|
|
|
|
|
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
|
|
|
|
2012-05-02 20:43:45 +04:00
|
|
|
void FireDOMLightEvent(nsIDOMEventTarget *target,
|
|
|
|
double value);
|
|
|
|
|
2012-05-02 20:43:45 +04:00
|
|
|
void FireDOMProximityEvent(nsIDOMEventTarget *aTarget,
|
|
|
|
double aValue,
|
|
|
|
double aMin,
|
|
|
|
double aMax);
|
|
|
|
|
2012-05-17 00:27:54 +04:00
|
|
|
void FireDOMUserProximityEvent(nsIDOMEventTarget *aTarget,
|
|
|
|
bool aNear);
|
|
|
|
|
2011-06-20 09:36:17 +04:00
|
|
|
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
|
|
|
|
class nsIDOMEventTarget *target,
|
|
|
|
double alpha,
|
|
|
|
double beta,
|
|
|
|
double gamma);
|
|
|
|
|
|
|
|
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
|
|
|
class nsIDOMEventTarget *target,
|
2012-03-14 03:57:51 +04:00
|
|
|
PRUint32 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
|
|
|
|
|
|
|
inline bool IsSensorEnabled(PRUint32 aType) {
|
|
|
|
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
|