2009-08-21 18:42:37 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Doug Turner <dougt@dougt.org>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
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
|