2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
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"
|
2014-02-27 14:51:12 +04:00
|
|
|
#include "mozilla/dom/DeviceMotionEvent.h"
|
2012-03-09 22:40:43 +04:00
|
|
|
#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
|
|
|
|
|
|
|
class nsIDOMWindow;
|
2018-01-31 23:18:11 +03:00
|
|
|
class nsIDocument;
|
2009-08-21 18:42:37 +04:00
|
|
|
|
2013-04-20 02:18:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-04-20 02:18:33 +04:00
|
|
|
|
2012-03-25 04:29:57 +04:00
|
|
|
class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
|
2009-08-21 18:42:37 +04:00
|
|
|
{
|
2014-01-02 02:52:47 +04:00
|
|
|
typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit;
|
|
|
|
typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit;
|
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
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
void Notify(const mozilla::hal::SensorData& aSensorData) override;
|
2012-03-21 10:36:17 +04:00
|
|
|
|
2009-08-21 18:42:37 +04:00
|
|
|
private:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~nsDeviceSensors();
|
|
|
|
|
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);
|
|
|
|
|
2014-07-01 03:02:03 +04:00
|
|
|
void FireDOMOrientationEvent(mozilla::dom::EventTarget* target,
|
2015-12-17 23:49:44 +03:00
|
|
|
double aAlpha,
|
|
|
|
double aBeta,
|
|
|
|
double aGamma,
|
|
|
|
bool aIsAbsolute);
|
2011-06-20 09:36:17 +04:00
|
|
|
|
2018-01-31 23:18:11 +03:00
|
|
|
void FireDOMMotionEvent(nsIDocument* domDoc,
|
2013-04-20 02:18:33 +04:00
|
|
|
mozilla::dom::EventTarget* target,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t type,
|
2016-04-04 20:22:59 +03:00
|
|
|
PRTime timestamp,
|
2011-06-20 09:36:17 +04:00
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double z);
|
2012-03-14 02:29:29 +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;
|
|
|
|
}
|
|
|
|
|
2017-07-24 11:07:00 +03:00
|
|
|
bool IsSensorAllowedByPref(uint32_t aType, nsIDOMWindow* aWindow);
|
2017-06-20 06:10:06 +03:00
|
|
|
|
2012-03-09 22:40:43 +04:00
|
|
|
mozilla::TimeStamp mLastDOMMotionEventTime;
|
2012-05-17 00:27:54 +04:00
|
|
|
bool mIsUserProximityNear;
|
2014-01-02 02:52:47 +04:00
|
|
|
mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
|
2014-11-08 07:48:38 +03:00
|
|
|
mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncludingGravity;
|
2014-01-02 02:52:47 +04:00
|
|
|
mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
|
2009-08-21 18:42:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|