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"
|
2011-06-19 22:36:17 -07:00
|
|
|
#include "nsIDOMDeviceMotionEvent.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-05-02 09:43:45 -07:00
|
|
|
#include "nsIDOMDeviceLightEvent.h"
|
2012-03-09 10:40:43 -08:00
|
|
|
#include "nsIDOMDeviceOrientationEvent.h"
|
2012-05-02 09:43:45 -07:00
|
|
|
#include "nsIDOMDeviceProximityEvent.h"
|
2012-05-16 13:27:54 -07:00
|
|
|
#include "nsIDOMUserProximityEvent.h"
|
2012-03-09 10:40:43 -08:00
|
|
|
#include "nsIDOMDeviceMotionEvent.h"
|
|
|
|
#include "nsDOMDeviceMotionEvent.h"
|
|
|
|
#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
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
#define NS_DEVICE_SENSORS_CID \
|
2010-06-25 05:25:31 -07:00
|
|
|
{ 0xecba5203, 0x77da, 0x465a, \
|
|
|
|
{ 0x86, 0x5e, 0x78, 0xb7, 0xaf, 0x10, 0xd8, 0xf7 } }
|
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
#define NS_DEVICE_SENSORS_CONTRACTID "@mozilla.org/devicesensors;1"
|
2010-06-25 05:25:31 -07:00
|
|
|
|
2009-08-21 07:42:37 -07:00
|
|
|
class nsIDOMWindow;
|
|
|
|
|
2012-03-24 17:29:57 -07:00
|
|
|
class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
|
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
|
|
|
|
2012-05-02 09:43:45 -07:00
|
|
|
void FireDOMLightEvent(nsIDOMEventTarget *target,
|
|
|
|
double value);
|
|
|
|
|
2012-05-02 09:43:45 -07:00
|
|
|
void FireDOMProximityEvent(nsIDOMEventTarget *aTarget,
|
|
|
|
double aValue,
|
|
|
|
double aMin,
|
|
|
|
double aMax);
|
|
|
|
|
2012-05-16 13:27:54 -07:00
|
|
|
void FireDOMUserProximityEvent(nsIDOMEventTarget *aTarget,
|
|
|
|
bool aNear);
|
|
|
|
|
2011-06-19 22:36:17 -07:00
|
|
|
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
|
|
|
|
class nsIDOMEventTarget *target,
|
|
|
|
double alpha,
|
|
|
|
double beta,
|
|
|
|
double gamma);
|
|
|
|
|
|
|
|
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
|
|
|
class nsIDOMEventTarget *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;
|
2012-03-09 10:40:43 -08:00
|
|
|
nsRefPtr<nsDOMDeviceAcceleration> mLastAcceleration;
|
|
|
|
nsRefPtr<nsDOMDeviceAcceleration> mLastAccelerationIncluduingGravity;
|
|
|
|
nsRefPtr<nsDOMDeviceRotationRate> mLastRotationRate;
|
2009-08-21 07:42:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|