mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 615597 - Implement devicemotion and fix up deviceorientation events. r=smaug/azakai
--HG-- rename : content/events/src/nsDOMOrientationEvent.cpp => content/events/src/nsDOMDeviceOrientationEvent.cpp rename : content/events/src/nsDOMOrientationEvent.h => content/events/src/nsDOMDeviceOrientationEvent.h rename : dom/system/android/nsAccelerometerSystem.cpp => dom/system/android/nsDeviceMotionSystem.cpp rename : dom/system/android/nsAccelerometerSystem.h => dom/system/android/nsDeviceMotionSystem.h rename : dom/system/cocoa/nsAccelerometerSystem.h => dom/system/cocoa/nsDeviceMotionSystem.h rename : dom/system/cocoa/nsAccelerometerSystem.mm => dom/system/cocoa/nsDeviceMotionSystem.mm rename : dom/system/nsAccelerometer.cpp => dom/system/nsDeviceMotion.cpp rename : dom/system/nsAccelerometer.h => dom/system/nsDeviceMotion.h rename : dom/system/unix/nsAccelerometerSystem.cpp => dom/system/unix/nsDeviceMotionSystem.cpp rename : dom/system/unix/nsAccelerometerSystem.h => dom/system/unix/nsDeviceMotionSystem.h rename : dom/system/windows/nsAccelerometerSystem.cpp => dom/system/windows/nsDeviceMotionSystem.cpp rename : dom/system/windows/nsAccelerometerSystem.h => dom/system/windows/nsDeviceMotionSystem.h rename : xpcom/system/nsIAccelerometer.idl => xpcom/system/nsIDeviceMotion.idl
This commit is contained in:
parent
eafdcc3af5
commit
12569c1c97
@ -1699,6 +1699,7 @@ GK_ATOM(onMozTouchUp, "onMozTouchUp")
|
||||
|
||||
// orientation support
|
||||
GK_ATOM(ondeviceorientation, "ondeviceorientation")
|
||||
GK_ATOM(ondevicemotion, "ondevicemotion")
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Special atoms
|
||||
|
@ -92,6 +92,8 @@ NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, n
|
||||
nsresult
|
||||
NS_NewDOMDeviceOrientationEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
|
||||
nsresult
|
||||
NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
|
||||
nsresult
|
||||
NS_NewDOMTextEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsTextEvent* aEvent);
|
||||
nsresult
|
||||
NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
|
||||
|
@ -63,7 +63,8 @@ CPPSRCS = \
|
||||
nsDOMDragEvent.cpp \
|
||||
nsDOMMutationEvent.cpp \
|
||||
nsDOMPopupBlockedEvent.cpp \
|
||||
nsDOMOrientationEvent.cpp \
|
||||
nsDOMDeviceOrientationEvent.cpp \
|
||||
nsDOMDeviceMotionEvent.cpp \
|
||||
nsDOMBeforeUnloadEvent.cpp \
|
||||
nsDOMPageTransitionEvent.cpp \
|
||||
nsDOMXULCommandEvent.cpp \
|
||||
|
223
content/events/src/nsDOMDeviceMotionEvent.cpp
Normal file
223
content/events/src/nsDOMDeviceMotionEvent.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
/* ***** 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 Device Motion System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@dougt.org>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#include "nsDOMDeviceMotionEvent.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMDeviceMotionEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mAcceleration)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mAccelerationIncludingGravity)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRotationRate)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAcceleration)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAccelerationIncludingGravity)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRotationRate)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
|
||||
|
||||
DOMCI_DATA(DeviceMotionEvent, nsDOMDeviceMotionEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMDeviceMotionEvent)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDeviceMotionEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceMotionEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceMotionEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceMotionEvent::InitDeviceMotionEvent(const nsAString & aEventTypeArg,
|
||||
PRBool aCanBubbleArg,
|
||||
PRBool aCancelableArg,
|
||||
nsIDOMDeviceAcceleration* aAcceleration,
|
||||
nsIDOMDeviceAcceleration* aAccelerationIncludingGravity,
|
||||
nsIDOMDeviceRotationRate* aRotationRate,
|
||||
double aInterval)
|
||||
{
|
||||
nsresult rv = nsDOMEvent::InitEvent(aEventTypeArg, aCanBubbleArg, aCancelableArg);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mAcceleration = aAcceleration;
|
||||
mAccelerationIncludingGravity = aAccelerationIncludingGravity;
|
||||
mRotationRate = aRotationRate;
|
||||
mInterval = aInterval;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceMotionEvent::GetAcceleration(nsIDOMDeviceAcceleration **aAcceleration)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAcceleration);
|
||||
|
||||
NS_IF_ADDREF(*aAcceleration = mAcceleration);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceMotionEvent::GetAccelerationIncludingGravity(nsIDOMDeviceAcceleration **aAccelerationIncludingGravity)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAccelerationIncludingGravity);
|
||||
|
||||
NS_IF_ADDREF(*aAccelerationIncludingGravity = mAccelerationIncludingGravity);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceMotionEvent::GetRotationRate(nsIDOMDeviceRotationRate **aRotationRate)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRotationRate);
|
||||
|
||||
NS_IF_ADDREF(*aRotationRate = mRotationRate);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceMotionEvent::GetInterval(double *aInterval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInterval);
|
||||
|
||||
*aInterval = mInterval;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aInstancePtrResult,
|
||||
nsPresContext* aPresContext,
|
||||
nsEvent *aEvent)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsDOMDeviceMotionEvent* it = new nsDOMDeviceMotionEvent(aPresContext, aEvent);
|
||||
return CallQueryInterface(it, aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
DOMCI_DATA(DeviceAcceleration, nsDOMDeviceAcceleration)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMDeviceAcceleration)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDeviceAcceleration)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceAcceleration)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceAcceleration)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMDeviceAcceleration)
|
||||
NS_IMPL_RELEASE(nsDOMDeviceAcceleration)
|
||||
|
||||
nsDOMDeviceAcceleration::nsDOMDeviceAcceleration(double aX, double aY, double aZ)
|
||||
: mX(aX), mY(aY), mZ(aZ)
|
||||
{
|
||||
}
|
||||
|
||||
nsDOMDeviceAcceleration::~nsDOMDeviceAcceleration()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceAcceleration::GetX(double *aX)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aX);
|
||||
*aX = mX;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceAcceleration::GetY(double *aY)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aY);
|
||||
*aY = mY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceAcceleration::GetZ(double *aZ)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aZ);
|
||||
*aZ = mZ;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
DOMCI_DATA(DeviceRotationRate, nsDOMDeviceRotationRate)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMDeviceRotationRate)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDeviceRotationRate)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceRotationRate)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceRotationRate)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMDeviceRotationRate)
|
||||
NS_IMPL_RELEASE(nsDOMDeviceRotationRate)
|
||||
|
||||
nsDOMDeviceRotationRate::nsDOMDeviceRotationRate(double aAlpha, double aBeta, double aGamma)
|
||||
: mAlpha(aAlpha), mBeta(aBeta), mGamma(aGamma)
|
||||
{
|
||||
}
|
||||
|
||||
nsDOMDeviceRotationRate::~nsDOMDeviceRotationRate()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceRotationRate::GetAlpha(double *aAlpha)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAlpha);
|
||||
*aAlpha = mAlpha;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceRotationRate::GetBeta(double *aBeta)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBeta);
|
||||
*aBeta = mBeta;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMDeviceRotationRate::GetGamma(double *aGamma)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aGamma);
|
||||
*aGamma = mGamma;
|
||||
return NS_OK;
|
||||
}
|
99
content/events/src/nsDOMDeviceMotionEvent.h
Normal file
99
content/events/src/nsDOMDeviceMotionEvent.h
Normal file
@ -0,0 +1,99 @@
|
||||
/* ***** 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 Device Motion System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@dougt.org>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef nsDOMDeviceMotionEvent_h__
|
||||
#define nsDOMDeviceMotionEvent_h__
|
||||
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsDOMEvent.h"
|
||||
|
||||
class nsDOMDeviceRotationRate : public nsIDOMDeviceRotationRate
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMDEVICEROTATIONRATE
|
||||
|
||||
nsDOMDeviceRotationRate(double aAlpha, double aBeta, double aGamma);
|
||||
|
||||
private:
|
||||
~nsDOMDeviceRotationRate();
|
||||
|
||||
protected:
|
||||
double mAlpha, mBeta, mGamma;
|
||||
};
|
||||
|
||||
class nsDOMDeviceAcceleration : public nsIDOMDeviceAcceleration
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMDEVICEACCELERATION
|
||||
|
||||
nsDOMDeviceAcceleration(double aX, double aY, double aZ);
|
||||
|
||||
private:
|
||||
~nsDOMDeviceAcceleration();
|
||||
|
||||
protected:
|
||||
double mX, mY, mZ;
|
||||
};
|
||||
|
||||
class nsDOMDeviceMotionEvent : public nsDOMEvent,
|
||||
public nsIDOMDeviceMotionEvent
|
||||
{
|
||||
public:
|
||||
|
||||
nsDOMDeviceMotionEvent(nsPresContext* aPresContext, nsEvent* aEvent)
|
||||
: nsDOMEvent(aPresContext, aEvent)
|
||||
{}
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// Forward to nsDOMEvent
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
|
||||
// nsIDOMDeviceMotionEvent Interface
|
||||
NS_DECL_NSIDOMDEVICEMOTIONEVENT
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
|
||||
|
||||
nsCOMPtr<nsIDOMDeviceAcceleration> mAcceleration;
|
||||
nsCOMPtr<nsIDOMDeviceAcceleration> mAccelerationIncludingGravity;
|
||||
nsCOMPtr<nsIDOMDeviceRotationRate> mRotationRate;
|
||||
double mInterval;
|
||||
};
|
||||
|
||||
#endif
|
@ -34,26 +34,26 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsDOMOrientationEvent.h"
|
||||
#include "nsDOMDeviceOrientationEvent.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsDOMOrientationEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(nsDOMOrientationEvent, nsDOMEvent)
|
||||
NS_IMPL_ADDREF_INHERITED(nsDOMDeviceOrientationEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(nsDOMDeviceOrientationEvent, nsDOMEvent)
|
||||
|
||||
DOMCI_DATA(DeviceOrientationEvent, nsDOMOrientationEvent)
|
||||
DOMCI_DATA(DeviceOrientationEvent, nsDOMDeviceOrientationEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMOrientationEvent)
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMDeviceOrientationEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceOrientationEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceOrientationEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
NS_IMETHODIMP nsDOMOrientationEvent::InitDeviceOrientationEvent(const nsAString & aEventTypeArg,
|
||||
PRBool aCanBubbleArg,
|
||||
PRBool aCancelableArg,
|
||||
double aAlpha,
|
||||
double aBeta,
|
||||
double aGamma,
|
||||
PRBool aAbsolute)
|
||||
NS_IMETHODIMP nsDOMDeviceOrientationEvent::InitDeviceOrientationEvent(const nsAString & aEventTypeArg,
|
||||
PRBool aCanBubbleArg,
|
||||
PRBool aCancelableArg,
|
||||
double aAlpha,
|
||||
double aBeta,
|
||||
double aGamma,
|
||||
PRBool aAbsolute)
|
||||
{
|
||||
nsresult rv = nsDOMEvent::InitEvent(aEventTypeArg, aCanBubbleArg, aCancelableArg);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -66,7 +66,7 @@ NS_IMETHODIMP nsDOMOrientationEvent::InitDeviceOrientationEvent(const nsAString
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDOMOrientationEvent::GetAlpha(double *aAlpha)
|
||||
NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetAlpha(double *aAlpha)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAlpha);
|
||||
|
||||
@ -74,7 +74,7 @@ NS_IMETHODIMP nsDOMOrientationEvent::GetAlpha(double *aAlpha)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDOMOrientationEvent::GetBeta(double *aBeta)
|
||||
NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetBeta(double *aBeta)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBeta);
|
||||
|
||||
@ -82,7 +82,7 @@ NS_IMETHODIMP nsDOMOrientationEvent::GetBeta(double *aBeta)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDOMOrientationEvent::GetGamma(double *aGamma)
|
||||
NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetGamma(double *aGamma)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aGamma);
|
||||
|
||||
@ -90,7 +90,7 @@ NS_IMETHODIMP nsDOMOrientationEvent::GetGamma(double *aGamma)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDOMOrientationEvent::GetAbsolute(PRBool *aAbsolute)
|
||||
NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetAbsolute(PRBool *aAbsolute)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAbsolute);
|
||||
|
||||
@ -98,21 +98,13 @@ NS_IMETHODIMP nsDOMOrientationEvent::GetAbsolute(PRBool *aAbsolute)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDOMOrientationEvent::GetCompassCalibrated(PRBool *aCompassCalibrated)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCompassCalibrated);
|
||||
|
||||
*aCompassCalibrated = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult NS_NewDOMDeviceOrientationEvent(nsIDOMEvent** aInstancePtrResult,
|
||||
nsPresContext* aPresContext,
|
||||
nsEvent *aEvent)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsDOMOrientationEvent* it = new nsDOMOrientationEvent(aPresContext, aEvent);
|
||||
nsDOMDeviceOrientationEvent* it = new nsDOMDeviceOrientationEvent(aPresContext, aEvent);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
@ -34,18 +34,18 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDOMOrientationEvent_h__
|
||||
#define nsDOMOrientationEvent_h__
|
||||
#ifndef nsDOMDeviceOrientationEvent_h__
|
||||
#define nsDOMDeviceOrientationEvent_h__
|
||||
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsDOMEvent.h"
|
||||
|
||||
class nsDOMOrientationEvent : public nsDOMEvent,
|
||||
public nsIDOMDeviceOrientationEvent
|
||||
class nsDOMDeviceOrientationEvent : public nsDOMEvent,
|
||||
public nsIDOMDeviceOrientationEvent
|
||||
{
|
||||
public:
|
||||
|
||||
nsDOMOrientationEvent(nsPresContext* aPresContext, nsEvent* aEvent)
|
||||
nsDOMDeviceOrientationEvent(nsPresContext* aPresContext, nsEvent* aEvent)
|
||||
: nsDOMEvent(aPresContext, aEvent),
|
||||
mAlpha(0),
|
||||
mBeta(0),
|
||||
@ -57,7 +57,7 @@ public:
|
||||
// Forward to nsDOMEvent
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
|
||||
// nsIDOMOrientationEvent Interface
|
||||
// nsIDOMDeviceOrientationEvent Interface
|
||||
NS_DECL_NSIDOMDEVICEORIENTATIONEVENT
|
||||
|
||||
protected:
|
@ -837,6 +837,8 @@ nsEventDispatcher::CreateEvent(nsPresContext* aPresContext,
|
||||
return NS_NewDOMPopupBlockedEvent(aDOMEvent, aPresContext, nsnull);
|
||||
if (aEventType.LowerCaseEqualsLiteral("deviceorientationevent"))
|
||||
return NS_NewDOMDeviceOrientationEvent(aDOMEvent, aPresContext, nsnull);
|
||||
if (aEventType.LowerCaseEqualsLiteral("devicemotionevent"))
|
||||
return NS_NewDOMDeviceMotionEvent(aDOMEvent, aPresContext, nsnull);
|
||||
if (aEventType.LowerCaseEqualsLiteral("uievent") ||
|
||||
aEventType.LowerCaseEqualsLiteral("uievents"))
|
||||
return NS_NewDOMUIEvent(aDOMEvent, aPresContext, nsnull);
|
||||
|
@ -500,7 +500,8 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
|
||||
kAllMutationBits :
|
||||
MutationBitForEventType(aType));
|
||||
}
|
||||
} else if (aTypeAtom == nsGkAtoms::ondeviceorientation) {
|
||||
} else if (aTypeAtom == nsGkAtoms::ondeviceorientation ||
|
||||
aTypeAtom == nsGkAtoms::ondevicemotion) {
|
||||
nsPIDOMWindow* window = GetInnerWindowForTarget();
|
||||
if (window)
|
||||
window->SetHasOrientationEventListener();
|
||||
|
@ -104,6 +104,7 @@ _TEST_FILES = \
|
||||
test_bug656379-1.html \
|
||||
test_bug656379-2.html \
|
||||
test_bug656954.html \
|
||||
test_bug662678.html \
|
||||
$(NULL)
|
||||
|
||||
#bug 585630
|
||||
|
@ -25,7 +25,6 @@ window.addEventListener("deviceorientation", function(event) {
|
||||
is(event.beta, 2.25);
|
||||
is(event.gamma, 3.667);
|
||||
is(event.absolute, true);
|
||||
is(event.compassCalibrated, true);
|
||||
SimpleTest.finish();
|
||||
}, true);
|
||||
|
||||
|
53
content/events/test/test_bug662678.html
Normal file
53
content/events/test/test_bug662678.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=662678
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 662678</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=662678">Mozilla Bug 662678</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 662678 **/
|
||||
|
||||
window.addEventListener("devicemotion", function(event) {
|
||||
is(event.acceleration.x, 1.5);
|
||||
is(event.acceleration.y, 1.5);
|
||||
is(event.acceleration.z, 1.5);
|
||||
|
||||
is(event.accelerationIncludingGravity.x, 1.5);
|
||||
is(event.accelerationIncludingGravity.y, 1.5);
|
||||
is(event.accelerationIncludingGravity.z, 1.5);
|
||||
|
||||
is(event.rotationRate.alpha, 1.5);
|
||||
is(event.rotationRate.beta, 1.5);
|
||||
is(event.rotationRate.gamma, 1.5);
|
||||
SimpleTest.finish();
|
||||
}, true);
|
||||
|
||||
var event = DeviceMotionEvent;
|
||||
ok(!!event, "Should have seen DeviceMotionEvent!");
|
||||
|
||||
event = document.createEvent("DeviceMotionEvent");
|
||||
event.initDeviceMotionEvent('devicemotion', true, true,
|
||||
{x:1.5,y:1.5,z:1.5},
|
||||
{x:1.5,y:1.5,z:1.5},
|
||||
{alpha:1.5,beta:1.5,gamma:1.5},
|
||||
0);
|
||||
window.dispatchEvent(event);
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -332,6 +332,7 @@
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsDOMCSSValueList.h"
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIDOMNSRange.h"
|
||||
#include "nsIDOMRangeException.h"
|
||||
@ -750,8 +751,15 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(PopupBlockedEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
// Device Orientation
|
||||
NS_DEFINE_CLASSINFO_DATA(DeviceOrientationEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(DeviceMotionEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(DeviceAcceleration, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(DeviceRotationRate, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
|
||||
// Misc HTML classes
|
||||
NS_DEFINE_CLASSINFO_DATA(HTMLDocument, nsHTMLDocumentSH,
|
||||
@ -2564,6 +2572,21 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(DeviceMotionEvent, nsIDOMDeviceMotionEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceMotionEvent)
|
||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(DeviceAcceleration, nsIDOMDeviceAcceleration)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceAcceleration)
|
||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(DeviceRotationRate, nsIDOMDeviceRotationRate)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceRotationRate)
|
||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(SmartCardEvent, nsIDOMSmartCardEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSmartCardEvent)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
@ -76,6 +76,9 @@ DOMCI_CLASS(DragEvent)
|
||||
DOMCI_CLASS(KeyboardEvent)
|
||||
DOMCI_CLASS(PopupBlockedEvent)
|
||||
DOMCI_CLASS(DeviceOrientationEvent)
|
||||
DOMCI_CLASS(DeviceMotionEvent)
|
||||
DOMCI_CLASS(DeviceAcceleration)
|
||||
DOMCI_CLASS(DeviceRotationRate)
|
||||
|
||||
// HTML classes
|
||||
DOMCI_CLASS(HTMLDocument)
|
||||
|
@ -97,7 +97,7 @@
|
||||
#include "nsCanvasFrame.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsAccelerometer.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIContentViewerEdit.h"
|
||||
#include "nsIDocShell.h"
|
||||
@ -830,7 +830,7 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
|
||||
#endif
|
||||
mShowFocusRingForContent(PR_FALSE),
|
||||
mFocusByKeyOccurred(PR_FALSE),
|
||||
mHasAcceleration(PR_FALSE),
|
||||
mHasDeviceMotion(PR_FALSE),
|
||||
mNotifiedIDDestroyed(PR_FALSE),
|
||||
mTimeoutInsertionPoint(nsnull),
|
||||
mTimeoutPublicIdCounter(1),
|
||||
@ -1137,8 +1137,8 @@ nsGlobalWindow::CleanUp(PRBool aIgnoreModalDialog)
|
||||
inner->CleanUp(aIgnoreModalDialog);
|
||||
}
|
||||
|
||||
DisableAccelerationUpdates();
|
||||
mHasAcceleration = PR_FALSE;
|
||||
DisableDeviceMotionUpdates();
|
||||
mHasDeviceMotion = PR_FALSE;
|
||||
|
||||
if (mCleanMessageManager) {
|
||||
NS_ABORT_IF_FALSE(mIsChrome, "only chrome should have msg manager cleaned");
|
||||
@ -7537,13 +7537,12 @@ void nsGlobalWindow::UpdateTouchState()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsGlobalWindow::EnableAccelerationUpdates()
|
||||
nsGlobalWindow::EnableDeviceMotionUpdates()
|
||||
{
|
||||
if (mHasAcceleration) {
|
||||
nsCOMPtr<nsIAccelerometer> ac =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (mHasDeviceMotion) {
|
||||
nsCOMPtr<nsIDeviceMotion> ac =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (ac) {
|
||||
ac->AddWindowListener(this);
|
||||
}
|
||||
@ -7551,11 +7550,11 @@ nsGlobalWindow::EnableAccelerationUpdates()
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::DisableAccelerationUpdates()
|
||||
nsGlobalWindow::DisableDeviceMotionUpdates()
|
||||
{
|
||||
if (mHasAcceleration) {
|
||||
nsCOMPtr<nsIAccelerometer> ac =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (mHasDeviceMotion) {
|
||||
nsCOMPtr<nsIDeviceMotion> ac =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (ac) {
|
||||
ac->RemoveWindowListener(this);
|
||||
}
|
||||
@ -9858,7 +9857,7 @@ nsGlobalWindow::SuspendTimeouts(PRUint32 aIncrease,
|
||||
mTimeoutsSuspendDepth += aIncrease;
|
||||
|
||||
if (!suspended) {
|
||||
DisableAccelerationUpdates();
|
||||
DisableDeviceMotionUpdates();
|
||||
|
||||
nsDOMThreadService* dts = nsDOMThreadService::get();
|
||||
if (dts) {
|
||||
@ -9934,7 +9933,7 @@ nsGlobalWindow::ResumeTimeouts(PRBool aThawChildren)
|
||||
nsresult rv;
|
||||
|
||||
if (shouldResume) {
|
||||
EnableAccelerationUpdates();
|
||||
EnableDeviceMotionUpdates();
|
||||
|
||||
nsDOMThreadService* dts = nsDOMThreadService::get();
|
||||
if (dts) {
|
||||
@ -10053,8 +10052,8 @@ nsGlobalWindow::SetScriptTypeID(PRUint32 aScriptType)
|
||||
void
|
||||
nsGlobalWindow::SetHasOrientationEventListener()
|
||||
{
|
||||
mHasAcceleration = PR_TRUE;
|
||||
EnableAccelerationUpdates();
|
||||
mHasDeviceMotion = PR_TRUE;
|
||||
EnableDeviceMotionUpdates();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -571,10 +571,10 @@ public:
|
||||
|
||||
private:
|
||||
// Enable updates for the accelerometer.
|
||||
void EnableAccelerationUpdates();
|
||||
void EnableDeviceMotionUpdates();
|
||||
|
||||
// Disables updates for the accelerometer.
|
||||
void DisableAccelerationUpdates();
|
||||
void DisableDeviceMotionUpdates();
|
||||
|
||||
protected:
|
||||
friend class HashchangeCallback;
|
||||
@ -889,8 +889,8 @@ protected:
|
||||
// should be displayed.
|
||||
PRPackedBool mFocusByKeyOccurred : 1;
|
||||
|
||||
// Indicates whether this window is getting acceleration change events
|
||||
PRPackedBool mHasAcceleration : 1;
|
||||
// Indicates whether this window is getting device motion change events
|
||||
PRPackedBool mHasDeviceMotion : 1;
|
||||
|
||||
// whether we've sent the destroy notification for our window id
|
||||
PRPackedBool mNotifiedIDDestroyed : 1;
|
||||
|
@ -80,7 +80,8 @@ XPIDLSRCS = \
|
||||
nsIDOMSimpleGestureEvent.idl \
|
||||
nsIDOMNSMouseEvent.idl \
|
||||
nsIDOMMozTouchEvent.idl \
|
||||
nsIDOMDeviceOrientationEvent.idl \
|
||||
nsIDOMDeviceOrientationEvent.idl\
|
||||
nsIDOMDeviceMotionEvent.idl \
|
||||
nsIDOMScrollAreaEvent.idl \
|
||||
nsIDOMTransitionEvent.idl \
|
||||
nsIDOMPopStateEvent.idl \
|
||||
|
72
dom/interfaces/events/nsIDOMDeviceMotionEvent.idl
Normal file
72
dom/interfaces/events/nsIDOMDeviceMotionEvent.idl
Normal file
@ -0,0 +1,72 @@
|
||||
/* ***** 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
|
||||
* Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* 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 ***** */
|
||||
|
||||
#include "nsIDOMEvent.idl"
|
||||
|
||||
[scriptable, uuid(2AD6EBC0-35AB-41D0-A755-0CA6A0E21565)]
|
||||
interface nsIDOMDeviceAcceleration : nsISupports
|
||||
{
|
||||
readonly attribute double x;
|
||||
readonly attribute double y;
|
||||
readonly attribute double z;
|
||||
};
|
||||
|
||||
[scriptable, uuid(E76AC929-61FE-4519-9EAC-D496A53CBC9B)]
|
||||
interface nsIDOMDeviceRotationRate : nsISupports
|
||||
{
|
||||
readonly attribute double alpha;
|
||||
readonly attribute double beta;
|
||||
readonly attribute double gamma;
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(66E8D2C9-0826-444C-8FB8-E509BC9615F8)]
|
||||
interface nsIDOMDeviceMotionEvent : nsIDOMEvent
|
||||
{
|
||||
void initDeviceMotionEvent(in DOMString eventTypeArg,
|
||||
in boolean canBubbleArg,
|
||||
in boolean cancelableArg,
|
||||
in nsIDOMDeviceAcceleration acceleration,
|
||||
in nsIDOMDeviceAcceleration accelerationIncludingGravity,
|
||||
in nsIDOMDeviceRotationRate rotationRate,
|
||||
in double interval);
|
||||
|
||||
readonly attribute nsIDOMDeviceAcceleration acceleration;
|
||||
readonly attribute nsIDOMDeviceAcceleration accelerationIncludingGravity;
|
||||
readonly attribute nsIDOMDeviceRotationRate rotationRate;
|
||||
readonly attribute double interval;
|
||||
};
|
||||
|
@ -71,6 +71,5 @@ interface nsIDOMDeviceOrientationEvent : nsIDOMEvent
|
||||
readonly attribute double beta;
|
||||
readonly attribute double gamma;
|
||||
readonly attribute boolean absolute;
|
||||
readonly attribute boolean compassCalibrated;
|
||||
};
|
||||
|
||||
|
@ -93,7 +93,7 @@
|
||||
#include "nsPermissionManager.h"
|
||||
#endif
|
||||
|
||||
#include "nsAccelerometer.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
#if defined(ANDROID)
|
||||
#include "APKOpen.h"
|
||||
@ -647,14 +647,16 @@ ContentChild::RecvAddPermission(const IPC::Permission& permission)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvAccelerationChanged(const double& x, const double& y,
|
||||
ContentChild::RecvDeviceMotionChanged(const long int& type,
|
||||
const double& x, const double& y,
|
||||
const double& z)
|
||||
{
|
||||
nsCOMPtr<nsIAccelerometerUpdate> acu =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (acu)
|
||||
acu->AccelerationChanged(x, y, z);
|
||||
nsCOMPtr<nsIDeviceMotionUpdate> dmu =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (dmu)
|
||||
dmu->DeviceMotionChanged(type, x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,8 @@ public:
|
||||
|
||||
virtual bool RecvAddPermission(const IPC::Permission& permission);
|
||||
|
||||
virtual bool RecvAccelerationChanged(const double& x, const double& y,
|
||||
virtual bool RecvDeviceMotionChanged(const long int& type,
|
||||
const double& x, const double& y,
|
||||
const double& z);
|
||||
|
||||
virtual bool RecvScreenSizeChanged(const gfxIntSize &size);
|
||||
|
@ -93,7 +93,7 @@
|
||||
#include "mozilla/dom/StorageParent.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "nsAccelerometer.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsMemoryReporterManager.h"
|
||||
@ -271,7 +271,7 @@ ContentParent::ActorDestroy(ActorDestroyReason why)
|
||||
}
|
||||
|
||||
RecvRemoveGeolocationListener();
|
||||
RecvRemoveAccelerometerListener();
|
||||
RecvRemoveDeviceMotionListener();
|
||||
|
||||
nsCOMPtr<nsIThreadInternal>
|
||||
threadInt(do_QueryInterface(NS_GetCurrentThread()));
|
||||
@ -1072,22 +1072,22 @@ ContentParent::RecvRemoveGeolocationListener()
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvAddAccelerometerListener()
|
||||
ContentParent::RecvAddDeviceMotionListener()
|
||||
{
|
||||
nsCOMPtr<nsIAccelerometer> ac =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (ac)
|
||||
ac->AddListener(this);
|
||||
nsCOMPtr<nsIDeviceMotion> dm =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (dm)
|
||||
dm->AddListener(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::RecvRemoveAccelerometerListener()
|
||||
ContentParent::RecvRemoveDeviceMotionListener()
|
||||
{
|
||||
nsCOMPtr<nsIAccelerometer> ac =
|
||||
do_GetService(NS_ACCELEROMETER_CONTRACTID);
|
||||
if (ac)
|
||||
ac->RemoveListener(this);
|
||||
nsCOMPtr<nsIDeviceMotion> dm =
|
||||
do_GetService(NS_DEVICE_MOTION_CONTRACTID);
|
||||
if (dm)
|
||||
dm->RemoveListener(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1134,14 +1134,15 @@ ContentParent::RecvScriptError(const nsString& aMessage,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContentParent::OnAccelerationChange(nsIAcceleration *aAcceleration)
|
||||
{
|
||||
double alpha, beta, gamma;
|
||||
aAcceleration->GetAlpha(&alpha);
|
||||
aAcceleration->GetBeta(&beta);
|
||||
aAcceleration->GetGamma(&gamma);
|
||||
ContentParent::OnMotionChange(nsIDeviceMotionData *aDeviceData) {
|
||||
PRUint32 type;
|
||||
double x, y, z;
|
||||
aDeviceData->GetType(&type);
|
||||
aDeviceData->GetX(&x);
|
||||
aDeviceData->GetY(&y);
|
||||
aDeviceData->GetZ(&z);
|
||||
|
||||
unused << SendAccelerationChanged(alpha, beta, gamma);
|
||||
unused << SendDeviceMotionChanged(type, x, y, z);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIDOMGeoPositionCallback.h"
|
||||
#include "nsIAccelerometer.h"
|
||||
#include "nsIDeviceMotion.h"
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
@ -70,7 +70,7 @@ class ContentParent : public PContentParent
|
||||
, public nsIObserver
|
||||
, public nsIThreadObserver
|
||||
, public nsIDOMGeoPositionCallback
|
||||
, public nsIAccelerationListener
|
||||
, public nsIDeviceMotionListener
|
||||
{
|
||||
private:
|
||||
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
|
||||
@ -88,7 +88,7 @@ public:
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSITHREADOBSERVER
|
||||
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
|
||||
NS_DECL_NSIACCELERATIONLISTENER
|
||||
NS_DECL_NSIDEVICEMOTIONLISTENER
|
||||
|
||||
TabParent* CreateTab(PRUint32 aChromeFlags);
|
||||
|
||||
@ -200,8 +200,8 @@ private:
|
||||
|
||||
virtual bool RecvAddGeolocationListener();
|
||||
virtual bool RecvRemoveGeolocationListener();
|
||||
virtual bool RecvAddAccelerometerListener();
|
||||
virtual bool RecvRemoveAccelerometerListener();
|
||||
virtual bool RecvAddDeviceMotionListener();
|
||||
virtual bool RecvRemoveDeviceMotionListener();
|
||||
|
||||
virtual bool RecvConsoleMessage(const nsString& aMessage);
|
||||
virtual bool RecvScriptError(const nsString& aMessage,
|
||||
|
@ -123,7 +123,7 @@ child:
|
||||
// nsIPermissionManager messages
|
||||
AddPermission(Permission permission);
|
||||
|
||||
AccelerationChanged(double x, double y, double z);
|
||||
DeviceMotionChanged(long type, double x, double y, double z);
|
||||
|
||||
ScreenSizeChanged(gfxIntSize size);
|
||||
|
||||
@ -172,8 +172,8 @@ parent:
|
||||
|
||||
AddGeolocationListener();
|
||||
RemoveGeolocationListener();
|
||||
AddAccelerometerListener();
|
||||
RemoveAccelerometerListener();
|
||||
AddDeviceMotionListener();
|
||||
RemoveDeviceMotionListener();
|
||||
|
||||
ConsoleMessage(nsString message);
|
||||
ScriptError(nsString message, nsString sourceName, nsString sourceLine,
|
||||
|
@ -62,9 +62,12 @@ DIRS = android
|
||||
endif
|
||||
|
||||
CPPSRCS = \
|
||||
nsAccelerometer.cpp \
|
||||
nsDeviceMotion.cpp \
|
||||
$(NULL)
|
||||
|
||||
# We fire the nsDOMDeviceAcceleration
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
|
||||
|
||||
# On Systems that have build in geolocation providers,
|
||||
# we really do not need these.
|
||||
ifneq (Android,$(OS_TARGET))
|
||||
@ -77,7 +80,7 @@ EXTRA_COMPONENTS = \
|
||||
endif
|
||||
|
||||
EXPORTS = \
|
||||
nsAccelerometer.h \
|
||||
nsDeviceMotion.h \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
@ -53,7 +53,7 @@ include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
nsAccelerometerSystem.cpp \
|
||||
nsDeviceMotionSystem.cpp \
|
||||
AndroidLocationProvider.cpp \
|
||||
nsHapticFeedback.cpp \
|
||||
$(NULL)
|
||||
|
@ -36,38 +36,38 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "nsAccelerometerSystem.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
|
||||
#include "AndroidBridge.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
extern nsAccelerometerSystem *gAccel;
|
||||
extern nsDeviceMotionSystem *gDeviceMotionSystem;
|
||||
|
||||
nsAccelerometerSystem::nsAccelerometerSystem()
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem()
|
||||
{
|
||||
gAccel = this;
|
||||
gDeviceMotionSystem = this;
|
||||
}
|
||||
|
||||
nsAccelerometerSystem::~nsAccelerometerSystem()
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Startup()
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default)
|
||||
AndroidBridge::Bridge()->EnableAccelerometer(true);
|
||||
AndroidBridge::Bridge()->EnableDeviceMotion(true);
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendAddAccelerometerListener();
|
||||
SendAddDeviceMotionListener();
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Shutdown()
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Default)
|
||||
AndroidBridge::Bridge()->EnableAccelerometer(false);
|
||||
AndroidBridge::Bridge()->EnableDeviceMotion(false);
|
||||
else
|
||||
mozilla::dom::ContentChild::GetSingleton()->
|
||||
SendRemoveAccelerometerListener();
|
||||
SendRemoveDeviceMotionListener();
|
||||
}
|
@ -34,21 +34,21 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsAccelerometerSystem_h
|
||||
#define nsAccelerometerSystem_h
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include "nsAccelerometer.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
class nsAccelerometerSystem : public nsAccelerometer
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsAccelerometerSystem();
|
||||
virtual ~nsAccelerometerSystem();
|
||||
nsDeviceMotionSystem();
|
||||
virtual ~nsDeviceMotionSystem();
|
||||
|
||||
private:
|
||||
virtual void Startup();
|
||||
virtual void Shutdown();
|
||||
};
|
||||
|
||||
#endif /* nsAccelerometerSystem_h */
|
||||
#endif /* nsDeviceMotionSystem_h */
|
||||
|
@ -52,7 +52,7 @@ EXPORT_LIBRARY = 1
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CMMSRCS = \
|
||||
nsAccelerometerSystem.mm \
|
||||
nsDeviceMotionSystem.mm \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -34,19 +34,19 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsAccelerometerSystem_h
|
||||
#define nsAccelerometerSystem_h
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <mach/mach_port.h>
|
||||
|
||||
#include "nsAccelerometer.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
class nsAccelerometerSystem : public nsAccelerometer
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsAccelerometerSystem();
|
||||
~nsAccelerometerSystem();
|
||||
nsDeviceMotionSystem();
|
||||
~nsDeviceMotionSystem();
|
||||
|
||||
void Startup();
|
||||
void Shutdown();
|
@ -34,7 +34,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsAccelerometerSystem.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
@ -45,11 +45,11 @@
|
||||
#define MODEL_NAME_LENGTH 64
|
||||
static char gModelName[MODEL_NAME_LENGTH];
|
||||
|
||||
nsAccelerometerSystem::nsAccelerometerSystem()
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
nsAccelerometerSystem::~nsAccelerometerSystem()
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
@ -72,9 +72,9 @@ typedef struct
|
||||
#define SMSDATA_USED_SIZE (sizeof(SmsData) - SMSDATA_PADDING_SIZE)
|
||||
|
||||
void
|
||||
nsAccelerometerSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
nsAccelerometerSystem *self = reinterpret_cast<nsAccelerometerSystem *>(aClosure);
|
||||
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
|
||||
if (!self) {
|
||||
NS_ERROR("no self");
|
||||
return;
|
||||
@ -143,10 +143,10 @@ nsAccelerometerSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
free(input);
|
||||
free(output);
|
||||
|
||||
self->AccelerationChanged( xf, yf, zf );
|
||||
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, xf, yf, zf );
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Startup()
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
// we can fail, and that just means the caller will not see any changes.
|
||||
|
||||
@ -194,7 +194,7 @@ void nsAccelerometerSystem::Startup()
|
||||
nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Shutdown()
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (mSmsConnection)
|
||||
::IOServiceClose(mSmsConnection);
|
@ -1,287 +0,0 @@
|
||||
/* ***** 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 ***** */
|
||||
|
||||
#include "nsAccelerometer.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefService.h"
|
||||
|
||||
class nsAcceleration : public nsIAcceleration
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIACCELERATION
|
||||
|
||||
nsAcceleration(double alpha, double beta, double gamma);
|
||||
|
||||
private:
|
||||
~nsAcceleration();
|
||||
|
||||
protected:
|
||||
/* additional members */
|
||||
double mAlpha, mBeta, mGamma;
|
||||
};
|
||||
|
||||
/* Implementation file */
|
||||
NS_IMPL_ISUPPORTS1(nsAcceleration, nsIAcceleration)
|
||||
|
||||
nsAcceleration::nsAcceleration(double alpha, double beta, double gamma)
|
||||
:mAlpha(alpha), mBeta(beta), mGamma(gamma)
|
||||
{
|
||||
}
|
||||
|
||||
nsAcceleration::~nsAcceleration()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAcceleration::GetAlpha(double *aAlpha)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAlpha);
|
||||
*aAlpha = mAlpha;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAcceleration::GetBeta(double *aBeta)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBeta);
|
||||
*aBeta = mBeta;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAcceleration::GetGamma(double *aGamma)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aGamma);
|
||||
*aGamma = mGamma;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsAccelerometer, nsIAccelerometer, nsIAccelerometerUpdate)
|
||||
|
||||
nsAccelerometer::nsAccelerometer()
|
||||
: mLastAlpha(-200), /* initialize to values that can't be possible */
|
||||
mLastBeta(-200),
|
||||
mLastGamma(-200),
|
||||
mStarted(PR_FALSE),
|
||||
mNewListener(PR_FALSE),
|
||||
mUpdateInterval(50), /* default to 50 ms */
|
||||
mEnabled(PR_TRUE)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefSrv) {
|
||||
PRInt32 value;
|
||||
nsresult rv = prefSrv->GetIntPref("accelerometer.update.interval", &value);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mUpdateInterval = value;
|
||||
|
||||
PRBool bvalue;
|
||||
rv = prefSrv->GetBoolPref("accelerometer.enabled", &bvalue);
|
||||
if (NS_SUCCEEDED(rv) && bvalue == PR_FALSE)
|
||||
mEnabled = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
nsAccelerometer::~nsAccelerometer()
|
||||
{
|
||||
if (mTimeoutTimer)
|
||||
mTimeoutTimer->Cancel();
|
||||
}
|
||||
|
||||
void
|
||||
nsAccelerometer::StartDisconnectTimer()
|
||||
{
|
||||
if (mTimeoutTimer)
|
||||
mTimeoutTimer->Cancel();
|
||||
|
||||
mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
if (mTimeoutTimer)
|
||||
mTimeoutTimer->InitWithFuncCallback(TimeoutHandler,
|
||||
this,
|
||||
2000,
|
||||
nsITimer::TYPE_ONE_SHOT);
|
||||
}
|
||||
|
||||
void
|
||||
nsAccelerometer::TimeoutHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
// the reason that we use self, instead of just using nsITimerCallback or nsIObserver
|
||||
// is so that subclasses are free to use timers without worry about the base classes's
|
||||
// usage.
|
||||
nsAccelerometer *self = reinterpret_cast<nsAccelerometer *>(aClosure);
|
||||
if (!self) {
|
||||
NS_ERROR("no self");
|
||||
return;
|
||||
}
|
||||
|
||||
// what about listeners that don't clean up properly? they will leak
|
||||
if (self->mListeners.Count() == 0 && self->mWindowListeners.Count() == 0) {
|
||||
self->Shutdown();
|
||||
self->mStarted = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAccelerometer::AddListener(nsIAccelerationListener *aListener)
|
||||
{
|
||||
if (mListeners.IndexOf(aListener) >= 0)
|
||||
return NS_OK; // already exists
|
||||
|
||||
if (mStarted == PR_FALSE) {
|
||||
mStarted = PR_TRUE;
|
||||
mNewListener = PR_TRUE;
|
||||
Startup();
|
||||
}
|
||||
|
||||
mListeners.AppendObject(aListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAccelerometer::RemoveListener(nsIAccelerationListener *aListener)
|
||||
{
|
||||
if (mListeners.IndexOf(aListener) < 0)
|
||||
return NS_OK; // doesn't exist
|
||||
|
||||
mListeners.RemoveObject(aListener);
|
||||
StartDisconnectTimer();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAccelerometer::AddWindowListener(nsIDOMWindow *aWindow)
|
||||
{
|
||||
if (mWindowListeners.IndexOf(aWindow) >= 0)
|
||||
return NS_OK; // already exists
|
||||
|
||||
if (mStarted == PR_FALSE) {
|
||||
mStarted = PR_TRUE;
|
||||
mNewListener = PR_TRUE;
|
||||
Startup();
|
||||
}
|
||||
|
||||
mWindowListeners.AppendObject(aWindow);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAccelerometer::RemoveWindowListener(nsIDOMWindow *aWindow)
|
||||
{
|
||||
if (mWindowListeners.IndexOf(aWindow) < 0)
|
||||
return NS_OK; // doesn't exist
|
||||
|
||||
mWindowListeners.RemoveObject(aWindow);
|
||||
StartDisconnectTimer();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAccelerometer::AccelerationChanged(double alpha, double beta, double gamma)
|
||||
{
|
||||
if (!mEnabled)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (alpha > 360)
|
||||
alpha = 360;
|
||||
if (alpha < 0)
|
||||
alpha = 0;
|
||||
|
||||
if (beta > 180)
|
||||
beta = 180;
|
||||
if (beta < -180)
|
||||
beta = -180;
|
||||
|
||||
if (gamma > 90)
|
||||
gamma = 90;
|
||||
if (gamma < -90)
|
||||
gamma = -90;
|
||||
|
||||
if (!mNewListener) {
|
||||
if (PR_ABS(mLastAlpha - alpha) < 1 &&
|
||||
PR_ABS(mLastBeta - beta) < 1 &&
|
||||
PR_ABS(mLastGamma - gamma) < 1)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mLastAlpha = alpha;
|
||||
mLastBeta = beta;
|
||||
mLastGamma = gamma;
|
||||
mNewListener = PR_FALSE;
|
||||
|
||||
for (PRUint32 i = mListeners.Count(); i > 0 ; ) {
|
||||
--i;
|
||||
nsRefPtr<nsIAcceleration> a = new nsAcceleration(alpha, beta, gamma);
|
||||
mListeners[i]->OnAccelerationChange(a);
|
||||
}
|
||||
|
||||
for (PRUint32 i = mWindowListeners.Count(); i > 0 ; ) {
|
||||
--i;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||
mWindowListeners[i]->GetDocument(getter_AddRefs(domdoc));
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
|
||||
PRBool defaultActionEnabled = PR_TRUE;
|
||||
|
||||
if (domdoc) {
|
||||
domdoc->CreateEvent(NS_LITERAL_STRING("DeviceOrientationEvent"), getter_AddRefs(event));
|
||||
|
||||
nsCOMPtr<nsIDOMDeviceOrientationEvent> oe = do_QueryInterface(event);
|
||||
|
||||
if (event) {
|
||||
oe->InitDeviceOrientationEvent(NS_LITERAL_STRING("deviceorientation"),
|
||||
PR_TRUE,
|
||||
PR_FALSE,
|
||||
alpha,
|
||||
beta,
|
||||
gamma,
|
||||
PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||
if (privateEvent)
|
||||
privateEvent->SetTrusted(PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mWindowListeners[i]);
|
||||
target->DispatchEvent(event, &defaultActionEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
316
dom/system/nsDeviceMotion.cpp
Normal file
316
dom/system/nsDeviceMotion.cpp
Normal file
@ -0,0 +1,316 @@
|
||||
/* ***** 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 ***** */
|
||||
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsIDOMDeviceOrientationEvent.h"
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsDOMDeviceMotionEvent.h"
|
||||
|
||||
class nsDeviceMotionData : public nsIDeviceMotionData
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDEVICEMOTIONDATA
|
||||
|
||||
nsDeviceMotionData(unsigned long type, double x, double y, double z);
|
||||
|
||||
private:
|
||||
~nsDeviceMotionData();
|
||||
|
||||
protected:
|
||||
unsigned long mType;
|
||||
double mX, mY, mZ;
|
||||
};
|
||||
|
||||
nsDeviceMotionData::nsDeviceMotionData(unsigned long type, double x, double y, double z)
|
||||
: mType(type), mX(x), mY(y), mZ(z)
|
||||
{
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDeviceMotionData)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDeviceMotionData)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(nsDeviceMotionData)
|
||||
NS_IMPL_RELEASE(nsDeviceMotionData)
|
||||
|
||||
nsDeviceMotionData::~nsDeviceMotionData()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotionData::GetType(PRUint32 *aType)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aType);
|
||||
*aType = mType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotionData::GetX(double *aX)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aX);
|
||||
*aX = mX;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotionData::GetY(double *aY)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aY);
|
||||
*aY = mY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotionData::GetZ(double *aZ)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aZ);
|
||||
*aZ = mZ;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsDeviceMotion, nsIDeviceMotion, nsIDeviceMotionUpdate)
|
||||
|
||||
nsDeviceMotion::nsDeviceMotion()
|
||||
: mStarted(PR_FALSE),
|
||||
mUpdateInterval(50), /* default to 50 ms */
|
||||
mEnabled(PR_TRUE)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefSrv) {
|
||||
PRInt32 value;
|
||||
nsresult rv = prefSrv->GetIntPref("device.motion.update.interval", &value);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mUpdateInterval = value;
|
||||
|
||||
PRBool bvalue;
|
||||
rv = prefSrv->GetBoolPref("device.motion.enabled", &bvalue);
|
||||
if (NS_SUCCEEDED(rv) && bvalue == PR_FALSE)
|
||||
mEnabled = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
nsDeviceMotion::~nsDeviceMotion()
|
||||
{
|
||||
if (mTimeoutTimer)
|
||||
mTimeoutTimer->Cancel();
|
||||
}
|
||||
|
||||
void
|
||||
nsDeviceMotion::StartDisconnectTimer()
|
||||
{
|
||||
if (mTimeoutTimer)
|
||||
mTimeoutTimer->Cancel();
|
||||
|
||||
mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
if (mTimeoutTimer)
|
||||
mTimeoutTimer->InitWithFuncCallback(TimeoutHandler,
|
||||
this,
|
||||
2000,
|
||||
nsITimer::TYPE_ONE_SHOT);
|
||||
}
|
||||
|
||||
void
|
||||
nsDeviceMotion::TimeoutHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
// the reason that we use self, instead of just using nsITimerCallback or nsIObserver
|
||||
// is so that subclasses are free to use timers without worry about the base classes's
|
||||
// usage.
|
||||
nsDeviceMotion *self = reinterpret_cast<nsDeviceMotion *>(aClosure);
|
||||
if (!self) {
|
||||
NS_ERROR("no self");
|
||||
return;
|
||||
}
|
||||
|
||||
// what about listeners that don't clean up properly? they will leak
|
||||
if (self->mListeners.Count() == 0 && self->mWindowListeners.Count() == 0) {
|
||||
self->Shutdown();
|
||||
self->mStarted = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotion::AddListener(nsIDeviceMotionListener *aListener)
|
||||
{
|
||||
if (mListeners.IndexOf(aListener) >= 0)
|
||||
return NS_OK; // already exists
|
||||
|
||||
if (mStarted == PR_FALSE) {
|
||||
mStarted = PR_TRUE;
|
||||
Startup();
|
||||
}
|
||||
|
||||
mListeners.AppendObject(aListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotion::RemoveListener(nsIDeviceMotionListener *aListener)
|
||||
{
|
||||
if (mListeners.IndexOf(aListener) < 0)
|
||||
return NS_OK; // doesn't exist
|
||||
|
||||
mListeners.RemoveObject(aListener);
|
||||
StartDisconnectTimer();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotion::AddWindowListener(nsIDOMWindow *aWindow)
|
||||
{
|
||||
if (mWindowListeners.IndexOf(aWindow) >= 0)
|
||||
return NS_OK; // already exists
|
||||
|
||||
if (mStarted == PR_FALSE) {
|
||||
mStarted = PR_TRUE;
|
||||
Startup();
|
||||
}
|
||||
|
||||
mWindowListeners.AppendObject(aWindow);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceMotion::RemoveWindowListener(nsIDOMWindow *aWindow)
|
||||
{
|
||||
if (mWindowListeners.IndexOf(aWindow) < 0)
|
||||
return NS_OK; // doesn't exist
|
||||
|
||||
mWindowListeners.RemoveObject(aWindow);
|
||||
StartDisconnectTimer();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
|
||||
{
|
||||
if (!mEnabled)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
for (PRUint32 i = mListeners.Count(); i > 0 ; ) {
|
||||
--i;
|
||||
nsRefPtr<nsDeviceMotionData> a = new nsDeviceMotionData(type, x, y, z);
|
||||
mListeners[i]->OnMotionChange(a);
|
||||
}
|
||||
|
||||
for (PRUint32 i = mWindowListeners.Count(); i > 0 ; ) {
|
||||
--i;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||
mWindowListeners[i]->GetDocument(getter_AddRefs(domdoc));
|
||||
|
||||
if (domdoc) {
|
||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mWindowListeners[i]);
|
||||
if (type == nsIDeviceMotionData::TYPE_ACCELERATION)
|
||||
FireDOMMotionEvent(domdoc, target, x, y, z);
|
||||
else if (type == nsIDeviceMotionData::TYPE_ORIENTATION)
|
||||
FireDOMOrientationEvent(domdoc, target, x, y, z);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsDeviceMotion::FireDOMOrientationEvent(nsIDOMDocument *domdoc,
|
||||
nsIDOMEventTarget *target,
|
||||
double alpha,
|
||||
double beta,
|
||||
double gamma)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
PRBool defaultActionEnabled = PR_TRUE;
|
||||
domdoc->CreateEvent(NS_LITERAL_STRING("DeviceOrientationEvent"), getter_AddRefs(event));
|
||||
|
||||
nsCOMPtr<nsIDOMDeviceOrientationEvent> oe = do_QueryInterface(event);
|
||||
|
||||
if (!oe) {
|
||||
return;
|
||||
}
|
||||
|
||||
oe->InitDeviceOrientationEvent(NS_LITERAL_STRING("deviceorientation"),
|
||||
PR_TRUE,
|
||||
PR_FALSE,
|
||||
alpha,
|
||||
beta,
|
||||
gamma,
|
||||
PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||
if (privateEvent)
|
||||
privateEvent->SetTrusted(PR_TRUE);
|
||||
|
||||
target->DispatchEvent(event, &defaultActionEnabled);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
|
||||
nsIDOMEventTarget *target,
|
||||
double x,
|
||||
double y,
|
||||
double z) {
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
PRBool defaultActionEnabled = PR_TRUE;
|
||||
domdoc->CreateEvent(NS_LITERAL_STRING("DeviceMotionEvent"), getter_AddRefs(event));
|
||||
|
||||
nsCOMPtr<nsIDOMDeviceMotionEvent> me = do_QueryInterface(event);
|
||||
|
||||
if (!me) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Currently acceleration as determined includes gravity.
|
||||
nsRefPtr<nsDOMDeviceAcceleration> acceleration = new nsDOMDeviceAcceleration(x, y, z);
|
||||
|
||||
me->InitDeviceMotionEvent(NS_LITERAL_STRING("devicemotion"),
|
||||
PR_TRUE,
|
||||
PR_FALSE,
|
||||
nsnull,
|
||||
acceleration,
|
||||
nsnull,
|
||||
0);
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||
if (privateEvent)
|
||||
privateEvent->SetTrusted(PR_TRUE);
|
||||
|
||||
target->DispatchEvent(event, &defaultActionEnabled);
|
||||
}
|
||||
|
@ -34,51 +34,59 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsAccelerometer_h
|
||||
#define nsAccelerometer_h
|
||||
#ifndef nsDeviceMotion_h
|
||||
#define nsDeviceMotion_h
|
||||
|
||||
#include "nsIAccelerometer.h"
|
||||
#include "nsIDeviceMotion.h"
|
||||
#include "nsIDOMDeviceMotionEvent.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
#define NS_ACCELEROMETER_CID \
|
||||
#define NS_DEVICE_MOTION_CID \
|
||||
{ 0xecba5203, 0x77da, 0x465a, \
|
||||
{ 0x86, 0x5e, 0x78, 0xb7, 0xaf, 0x10, 0xd8, 0xf7 } }
|
||||
|
||||
#define NS_ACCELEROMETER_CONTRACTID "@mozilla.org/accelerometer;1"
|
||||
#define NS_DEVICE_MOTION_CONTRACTID "@mozilla.org/devicemotion;1"
|
||||
|
||||
class nsIDOMWindow;
|
||||
|
||||
class nsAccelerometer : public nsIAccelerometerUpdate
|
||||
class nsDeviceMotion : public nsIDeviceMotionUpdate
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIACCELEROMETER
|
||||
NS_DECL_NSIACCELEROMETERUPDATE
|
||||
NS_DECL_NSIDEVICEMOTION
|
||||
NS_DECL_NSIDEVICEMOTIONUPDATE
|
||||
|
||||
nsAccelerometer();
|
||||
nsDeviceMotion();
|
||||
|
||||
virtual ~nsAccelerometer();
|
||||
|
||||
double mLastAlpha;
|
||||
double mLastBeta;
|
||||
double mLastGamma;
|
||||
virtual ~nsDeviceMotion();
|
||||
|
||||
private:
|
||||
nsCOMArray<nsIAccelerationListener> mListeners;
|
||||
nsCOMArray<nsIDeviceMotionListener> mListeners;
|
||||
nsCOMArray<nsIDOMWindow> mWindowListeners;
|
||||
|
||||
void StartDisconnectTimer();
|
||||
|
||||
PRBool mStarted;
|
||||
PRBool mNewListener;
|
||||
|
||||
nsCOMPtr<nsITimer> mTimeoutTimer;
|
||||
static void TimeoutHandler(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
protected:
|
||||
|
||||
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
|
||||
class nsIDOMEventTarget *target,
|
||||
double alpha,
|
||||
double beta,
|
||||
double gamma);
|
||||
|
||||
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
||||
class nsIDOMEventTarget *target,
|
||||
double x,
|
||||
double y,
|
||||
double z);
|
||||
|
||||
PRUint32 mUpdateInterval;
|
||||
PRBool mEnabled;
|
||||
|
@ -52,7 +52,7 @@ EXPORT_LIBRARY = 1
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
nsAccelerometerSystem.cpp \
|
||||
nsDeviceMotionSystem.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_MAEMO_LIBLOCATION
|
||||
|
@ -36,16 +36,16 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "nsAccelerometerSystem.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
typedef struct {
|
||||
const char* mPosition;
|
||||
const char* mCalibrate;
|
||||
nsAccelerometerSystemDriver mToken;
|
||||
} Accelerometer;
|
||||
nsDeviceMotionSystemDriver mToken;
|
||||
} DeviceMotion;
|
||||
|
||||
static const Accelerometer gAccelerometers[] = {
|
||||
static const DeviceMotion gDeviceMotions[] = {
|
||||
// MacBook
|
||||
{"/sys/devices/platform/applesmc.768/position",
|
||||
"/sys/devices/platform/applesmc.768/calibrate",
|
||||
@ -64,21 +64,21 @@ static const Accelerometer gAccelerometers[] = {
|
||||
eHPdv7Sensor},
|
||||
};
|
||||
|
||||
nsAccelerometerSystem::nsAccelerometerSystem() :
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem() :
|
||||
mPositionFile(NULL),
|
||||
mCalibrateFile(NULL),
|
||||
mType(eNoSensor)
|
||||
{
|
||||
}
|
||||
|
||||
nsAccelerometerSystem::~nsAccelerometerSystem()
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
nsAccelerometerSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
nsAccelerometerSystem *self = reinterpret_cast<nsAccelerometerSystem *>(aClosure);
|
||||
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
|
||||
if (!self) {
|
||||
NS_ERROR("no self");
|
||||
return;
|
||||
@ -187,20 +187,20 @@ nsAccelerometerSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
return;
|
||||
}
|
||||
|
||||
self->AccelerationChanged( xf, yf, zf );
|
||||
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, xf, yf, zf );
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Startup()
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
// Accelerometers in Linux are used by reading a file (yay UNIX!), which is
|
||||
// DeviceMotions in Linux are used by reading a file (yay UNIX!), which is
|
||||
// in a slightly different location depending on the driver.
|
||||
for (unsigned int i = 0; i < NS_ARRAY_LENGTH(gAccelerometers); i++) {
|
||||
if (!(mPositionFile = fopen(gAccelerometers[i].mPosition, "r")))
|
||||
for (unsigned int i = 0; i < NS_ARRAY_LENGTH(gDeviceMotions); i++) {
|
||||
if (!(mPositionFile = fopen(gDeviceMotions[i].mPosition, "r")))
|
||||
continue;
|
||||
|
||||
mType = gAccelerometers[i].mToken;
|
||||
if (gAccelerometers[i].mCalibrate) {
|
||||
mCalibrateFile = fopen(gAccelerometers[i].mCalibrate, "r");
|
||||
mType = gDeviceMotions[i].mToken;
|
||||
if (gDeviceMotions[i].mCalibrate) {
|
||||
mCalibrateFile = fopen(gDeviceMotions[i].mCalibrate, "r");
|
||||
if (!mCalibrateFile) {
|
||||
fclose(mPositionFile);
|
||||
mPositionFile = nsnull;
|
||||
@ -222,7 +222,7 @@ void nsAccelerometerSystem::Startup()
|
||||
nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Shutdown()
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (mPositionFile) {
|
||||
fclose(mPositionFile);
|
@ -35,13 +35,13 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsAccelerometerSystem_h
|
||||
#define nsAccelerometerSystem_h
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include <unistd.h>
|
||||
#include "nsAccelerometer.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
|
||||
enum nsAccelerometerSystemDriver
|
||||
enum nsDeviceMotionSystemDriver
|
||||
{
|
||||
eNoSensor,
|
||||
eAppleSensor,
|
||||
@ -50,18 +50,18 @@ enum nsAccelerometerSystemDriver
|
||||
eHPdv7Sensor
|
||||
};
|
||||
|
||||
class nsAccelerometerSystem : public nsAccelerometer
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsAccelerometerSystem();
|
||||
~nsAccelerometerSystem();
|
||||
nsDeviceMotionSystem();
|
||||
~nsDeviceMotionSystem();
|
||||
|
||||
void Startup();
|
||||
void Shutdown();
|
||||
|
||||
FILE* mPositionFile;
|
||||
FILE* mCalibrateFile;
|
||||
nsAccelerometerSystemDriver mType;
|
||||
nsDeviceMotionSystemDriver mType;
|
||||
|
||||
nsCOMPtr<nsITimer> mUpdateTimer;
|
||||
static void UpdateHandler(nsITimer *aTimer, void *aClosure);
|
@ -52,7 +52,7 @@ EXPORT_LIBRARY = 1
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
nsAccelerometerSystem.cpp \
|
||||
nsDeviceMotionSystem.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -35,7 +35,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsAccelerometerSystem.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "windows.h"
|
||||
|
||||
@ -52,11 +52,11 @@ typedef struct {
|
||||
char temp; // raw value (could be deg celsius?)
|
||||
unsigned short x0; // Used for "auto-center"
|
||||
unsigned short y0; // Used for "auto-center"
|
||||
} ThinkPadAccelerometerData;
|
||||
} ThinkPadDeviceMotionData;
|
||||
|
||||
typedef void (__stdcall *ShockproofGetAccelerometerData)(ThinkPadAccelerometerData*);
|
||||
typedef void (__stdcall *ShockproofGetDeviceMotionData)(ThinkPadDeviceMotionData*);
|
||||
|
||||
ShockproofGetAccelerometerData gShockproofGetAccelerometerData = nsnull;
|
||||
ShockproofGetDeviceMotionData gShockproofGetDeviceMotionData = nsnull;
|
||||
|
||||
class ThinkPadSensor : public Sensor
|
||||
{
|
||||
@ -85,9 +85,9 @@ ThinkPadSensor::Startup()
|
||||
if (!mLibrary)
|
||||
return PR_FALSE;
|
||||
|
||||
gShockproofGetAccelerometerData = (ShockproofGetAccelerometerData)
|
||||
GetProcAddress(mLibrary, "ShockproofGetAccelerometerData");
|
||||
if (!gShockproofGetAccelerometerData) {
|
||||
gShockproofGetDeviceMotionData = (ShockproofGetDeviceMotionData)
|
||||
GetProcAddress(mLibrary, "ShockproofGetDeviceMotionData");
|
||||
if (!gShockproofGetDeviceMotionData) {
|
||||
FreeLibrary(mLibrary);
|
||||
mLibrary = nsnull;
|
||||
return PR_FALSE;
|
||||
@ -101,15 +101,15 @@ ThinkPadSensor::Shutdown()
|
||||
NS_ASSERTION(mLibrary, "Shutdown called when mLibrary is null?");
|
||||
FreeLibrary(mLibrary);
|
||||
mLibrary = nsnull;
|
||||
gShockproofGetAccelerometerData = nsnull;
|
||||
gShockproofGetDeviceMotionData = nsnull;
|
||||
}
|
||||
|
||||
void
|
||||
ThinkPadSensor::GetValues(double *x, double *y, double *z)
|
||||
{
|
||||
ThinkPadAccelerometerData accelData;
|
||||
ThinkPadDeviceMotionData accelData;
|
||||
|
||||
gShockproofGetAccelerometerData(&accelData);
|
||||
gShockproofGetDeviceMotionData(&accelData);
|
||||
|
||||
// accelData.x and accelData.y is the acceleration measured from the accelerometer.
|
||||
// x and y is switched from what we use, and the accelerometer does not support z axis.
|
||||
@ -119,23 +119,23 @@ ThinkPadSensor::GetValues(double *x, double *y, double *z)
|
||||
*z = 1.0;
|
||||
}
|
||||
|
||||
nsAccelerometerSystem::nsAccelerometerSystem(){}
|
||||
nsAccelerometerSystem::~nsAccelerometerSystem(){}
|
||||
nsDeviceMotionSystem::nsDeviceMotionSystem(){}
|
||||
nsDeviceMotionSystem::~nsDeviceMotionSystem(){}
|
||||
|
||||
void
|
||||
nsAccelerometerSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
nsDeviceMotionSystem::UpdateHandler(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
nsAccelerometerSystem *self = reinterpret_cast<nsAccelerometerSystem *>(aClosure);
|
||||
nsDeviceMotionSystem *self = reinterpret_cast<nsDeviceMotionSystem *>(aClosure);
|
||||
if (!self || !self->mSensor) {
|
||||
NS_ERROR("no self or sensor");
|
||||
return;
|
||||
}
|
||||
double x, y, z;
|
||||
self->mSensor->GetValues(&x, &y, &z);
|
||||
self->AccelerationChanged(x, y, z);
|
||||
self->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, x, y, z);
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Startup()
|
||||
void nsDeviceMotionSystem::Startup()
|
||||
{
|
||||
NS_ASSERTION(!mSensor, "mSensor should be null. Startup called twice?");
|
||||
|
||||
@ -156,7 +156,7 @@ void nsAccelerometerSystem::Startup()
|
||||
nsITimer::TYPE_REPEATING_SLACK);
|
||||
}
|
||||
|
||||
void nsAccelerometerSystem::Shutdown()
|
||||
void nsDeviceMotionSystem::Shutdown()
|
||||
{
|
||||
if (mUpdateTimer) {
|
||||
mUpdateTimer->Cancel();
|
@ -34,10 +34,10 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsAccelerometerSystem_h
|
||||
#define nsAccelerometerSystem_h
|
||||
#ifndef nsDeviceMotionSystem_h
|
||||
#define nsDeviceMotionSystem_h
|
||||
|
||||
#include "nsAccelerometer.h"
|
||||
#include "nsDeviceMotion.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
class Sensor
|
||||
@ -48,11 +48,11 @@ class Sensor
|
||||
virtual void GetValues(double *x, double *y, double *z) = 0;
|
||||
};
|
||||
|
||||
class nsAccelerometerSystem : public nsAccelerometer
|
||||
class nsDeviceMotionSystem : public nsDeviceMotion
|
||||
{
|
||||
public:
|
||||
nsAccelerometerSystem();
|
||||
~nsAccelerometerSystem();
|
||||
nsDeviceMotionSystem();
|
||||
~nsDeviceMotionSystem();
|
||||
|
||||
void Startup();
|
||||
void Shutdown();
|
@ -579,18 +579,29 @@ public class GeckoAppShell
|
||||
tmp.countDown();
|
||||
}
|
||||
|
||||
public static void enableAccelerometer(boolean enable) {
|
||||
static Sensor gAccelerometerSensor = null;
|
||||
static Sensor gOrientationSensor = null;
|
||||
|
||||
public static void enableDeviceMotion(boolean enable) {
|
||||
|
||||
SensorManager sm = (SensorManager)
|
||||
GeckoApp.surfaceView.getContext().getSystemService(Context.SENSOR_SERVICE);
|
||||
|
||||
if (enable) {
|
||||
Sensor accelSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
if (accelSensor == null)
|
||||
return;
|
||||
if (gAccelerometerSensor == null || gOrientationSensor == null) {
|
||||
gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
gOrientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
||||
}
|
||||
|
||||
sm.registerListener(GeckoApp.surfaceView, accelSensor, SensorManager.SENSOR_DELAY_GAME);
|
||||
if (enable) {
|
||||
if (gAccelerometerSensor != null)
|
||||
sm.registerListener(GeckoApp.surfaceView, gAccelerometerSensor, SensorManager.SENSOR_DELAY_GAME);
|
||||
if (gOrientationSensor != null)
|
||||
sm.registerListener(GeckoApp.surfaceView, gOrientationSensor, SensorManager.SENSOR_DELAY_GAME);
|
||||
} else {
|
||||
sm.unregisterListener(GeckoApp.surfaceView);
|
||||
if (gAccelerometerSensor != null)
|
||||
sm.unregisterListener(GeckoApp.surfaceView, gAccelerometerSensor);
|
||||
if (gOrientationSensor != null)
|
||||
sm.unregisterListener(GeckoApp.surfaceView, gOrientationSensor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,18 +59,19 @@ public class GeckoEvent {
|
||||
public static final int NATIVE_POKE = 0;
|
||||
public static final int KEY_EVENT = 1;
|
||||
public static final int MOTION_EVENT = 2;
|
||||
public static final int SENSOR_EVENT = 3;
|
||||
public static final int LOCATION_EVENT = 4;
|
||||
public static final int IME_EVENT = 5;
|
||||
public static final int DRAW = 6;
|
||||
public static final int SIZE_CHANGED = 7;
|
||||
public static final int ACTIVITY_STOPPING = 8;
|
||||
public static final int ACTIVITY_PAUSING = 9;
|
||||
public static final int ACTIVITY_SHUTDOWN = 10;
|
||||
public static final int LOAD_URI = 11;
|
||||
public static final int SURFACE_CREATED = 12;
|
||||
public static final int SURFACE_DESTROYED = 13;
|
||||
public static final int GECKO_EVENT_SYNC = 14;
|
||||
public static final int ORIENTATION_EVENT = 3;
|
||||
public static final int ACCELERATION_EVENT = 4;
|
||||
public static final int LOCATION_EVENT = 5;
|
||||
public static final int IME_EVENT = 6;
|
||||
public static final int DRAW = 7;
|
||||
public static final int SIZE_CHANGED = 8;
|
||||
public static final int ACTIVITY_STOPPING = 9;
|
||||
public static final int ACTIVITY_PAUSING = 10;
|
||||
public static final int ACTIVITY_SHUTDOWN = 11;
|
||||
public static final int LOAD_URI = 12;
|
||||
public static final int SURFACE_CREATED = 13;
|
||||
public static final int SURFACE_DESTROYED = 14;
|
||||
public static final int GECKO_EVENT_SYNC = 15;
|
||||
|
||||
public static final int IME_COMPOSITION_END = 0;
|
||||
public static final int IME_COMPOSITION_BEGIN = 1;
|
||||
@ -96,6 +97,7 @@ public class GeckoEvent {
|
||||
public long mTime;
|
||||
public Point mP0, mP1;
|
||||
public Rect mRect;
|
||||
public double mX, mY, mZ;
|
||||
public double mAlpha, mBeta, mGamma;
|
||||
|
||||
public int mMetaState, mFlags;
|
||||
@ -140,18 +142,20 @@ public class GeckoEvent {
|
||||
}
|
||||
|
||||
public GeckoEvent(SensorEvent s) {
|
||||
mType = SENSOR_EVENT;
|
||||
// We interpret the accelerometer readings as the direction of gravity.
|
||||
// Note that we will be mistaken if there is any additional
|
||||
// acceleration on the device. We can detect that to some degree
|
||||
// by comparing the magnitude to SensorManager.GRAVITY_EARTH, but
|
||||
// don't have any easy way to use that information...
|
||||
float magnitude = FloatMath.sqrt(s.values[0] * s.values[0] +
|
||||
s.values[1] * s.values[1] +
|
||||
s.values[2] * s.values[2]);
|
||||
mAlpha = 0; // This should be null; we do not have enough info to calculate it
|
||||
mBeta = Math.toDegrees(Math.asin(s.values[1] / magnitude));
|
||||
mGamma = -Math.toDegrees(Math.asin(s.values[0] / magnitude));
|
||||
|
||||
if (s.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
|
||||
mType = ACCELERATION_EVENT;
|
||||
mX = s.values[0] / SensorManager.GRAVITY_EARTH;
|
||||
mY = s.values[1] / SensorManager.GRAVITY_EARTH;
|
||||
mZ = s.values[2] / SensorManager.GRAVITY_EARTH;
|
||||
}
|
||||
else {
|
||||
mType = ORIENTATION_EVENT;
|
||||
mAlpha = -s.values[0];
|
||||
mBeta = -s.values[1];
|
||||
mGamma = -s.values[2];
|
||||
Log.i("GeckoEvent", "SensorEvent type = " + s.sensor.getType() + " " + s.sensor.getName() + " " + mAlpha + " " + mBeta + " " + mGamma );
|
||||
}
|
||||
}
|
||||
|
||||
public GeckoEvent(Location l, Address a) {
|
||||
|
@ -289,7 +289,7 @@ static void Shutdown();
|
||||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
#include "nsAccelerometerSystem.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#endif
|
||||
#include "nsCSPService.h"
|
||||
|
||||
@ -322,7 +322,7 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(IndexedDatabaseManager,
|
||||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAccelerometerSystem)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceMotionSystem)
|
||||
#endif
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ThirdPartyUtil, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWorkerFactory)
|
||||
@ -872,7 +872,7 @@ NS_DEFINE_NAMED_CID(NS_STRUCTUREDCLONECONTAINER_CID);
|
||||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
NS_DEFINE_NAMED_CID(NS_ACCELEROMETER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DEVICE_MOTION_CID);
|
||||
#endif
|
||||
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
|
||||
NS_DEFINE_NAMED_CID(NS_HAPTICFEEDBACK_CID);
|
||||
@ -1013,7 +1013,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
|
||||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
{ &kNS_ACCELEROMETER_CID, false, NULL, nsAccelerometerSystemConstructor },
|
||||
{ &kNS_DEVICE_MOTION_CID, false, NULL, nsDeviceMotionSystemConstructor },
|
||||
#endif
|
||||
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
|
||||
{ &kNS_HAPTICFEEDBACK_CID, false, NULL, nsHapticFeedbackConstructor },
|
||||
@ -1150,7 +1150,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
||||
defined(_WINDOWS) || \
|
||||
defined(machintosh) || \
|
||||
defined(android)
|
||||
{ NS_ACCELEROMETER_CONTRACTID, &kNS_ACCELEROMETER_CID },
|
||||
{ NS_DEVICE_MOTION_CONTRACTID, &kNS_DEVICE_MOTION_CID },
|
||||
#endif
|
||||
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
|
||||
{ "@mozilla.org/widget/hapticfeedback;1", &kNS_HAPTICFEEDBACK_CID },
|
||||
|
@ -3204,7 +3204,7 @@ pref("layers.prefer-d3d9", false);
|
||||
pref("geo.enabled", true);
|
||||
|
||||
// Enable/Disable the orientation API for content
|
||||
pref("accelerometer.enabled", true);
|
||||
pref("device.motion.enabled", true);
|
||||
|
||||
// Enable/Disable HTML5 parser
|
||||
pref("html5.parser.enable", true);
|
||||
|
@ -115,7 +115,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
|
||||
jNotifyIMEChange = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIMEChange", "(Ljava/lang/String;III)V");
|
||||
jAcknowledgeEventSync = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "acknowledgeEventSync", "()V");
|
||||
|
||||
jEnableAccelerometer = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableAccelerometer", "(Z)V");
|
||||
jEnableDeviceMotion = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableDeviceMotion", "(Z)V");
|
||||
jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V");
|
||||
jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V");
|
||||
jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V");
|
||||
@ -303,10 +303,10 @@ AndroidBridge::AcknowledgeEventSync()
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::EnableAccelerometer(bool aEnable)
|
||||
AndroidBridge::EnableDeviceMotion(bool aEnable)
|
||||
{
|
||||
ALOG_BRIDGE("AndroidBridge::EnableAccelerometer");
|
||||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableAccelerometer, aEnable);
|
||||
ALOG_BRIDGE("AndroidBridge::EnableDeviceMotion");
|
||||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableDeviceMotion, aEnable);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -130,7 +130,7 @@ public:
|
||||
|
||||
void AcknowledgeEventSync();
|
||||
|
||||
void EnableAccelerometer(bool aEnable);
|
||||
void EnableDeviceMotion(bool aEnable);
|
||||
|
||||
void EnableLocation(bool aEnable);
|
||||
|
||||
@ -283,7 +283,7 @@ protected:
|
||||
jmethodID jNotifyIMEEnabled;
|
||||
jmethodID jNotifyIMEChange;
|
||||
jmethodID jAcknowledgeEventSync;
|
||||
jmethodID jEnableAccelerometer;
|
||||
jmethodID jEnableDeviceMotion;
|
||||
jmethodID jEnableLocation;
|
||||
jmethodID jReturnIMEQueryResult;
|
||||
jmethodID jNotifyAppShellReady;
|
||||
|
@ -49,6 +49,9 @@ jfieldID AndroidGeckoEvent::jP1Field = 0;
|
||||
jfieldID AndroidGeckoEvent::jAlphaField = 0;
|
||||
jfieldID AndroidGeckoEvent::jBetaField = 0;
|
||||
jfieldID AndroidGeckoEvent::jGammaField = 0;
|
||||
jfieldID AndroidGeckoEvent::jXField = 0;
|
||||
jfieldID AndroidGeckoEvent::jYField = 0;
|
||||
jfieldID AndroidGeckoEvent::jZField = 0;
|
||||
jfieldID AndroidGeckoEvent::jRectField = 0;
|
||||
jfieldID AndroidGeckoEvent::jNativeWindowField = 0;
|
||||
|
||||
@ -147,6 +150,9 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
|
||||
jAlphaField = getField("mAlpha", "D");
|
||||
jBetaField = getField("mBeta", "D");
|
||||
jGammaField = getField("mGamma", "D");
|
||||
jXField = getField("mX", "D");
|
||||
jYField = getField("mY", "D");
|
||||
jZField = getField("mZ", "D");
|
||||
jRectField = getField("mRect", "Landroid/graphics/Rect;");
|
||||
|
||||
jCharactersField = getField("mCharacters", "Ljava/lang/String;");
|
||||
@ -402,12 +408,18 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
|
||||
ReadRectField(jenv);
|
||||
break;
|
||||
|
||||
case SENSOR_EVENT:
|
||||
case ORIENTATION_EVENT:
|
||||
mAlpha = jenv->GetDoubleField(jobj, jAlphaField);
|
||||
mBeta = jenv->GetDoubleField(jobj, jBetaField);
|
||||
mGamma = jenv->GetDoubleField(jobj, jGammaField);
|
||||
break;
|
||||
|
||||
case ACCELERATION_EVENT:
|
||||
mX = jenv->GetDoubleField(jobj, jXField);
|
||||
mY = jenv->GetDoubleField(jobj, jYField);
|
||||
mZ = jenv->GetDoubleField(jobj, jZField);
|
||||
break;
|
||||
|
||||
case LOCATION_EVENT: {
|
||||
jobject location = jenv->GetObjectField(jobj, jLocationField);
|
||||
jobject address = jenv->GetObjectField(jobj, jAddressField);
|
||||
|
@ -399,6 +399,9 @@ public:
|
||||
double Alpha() { return mAlpha; }
|
||||
double Beta() { return mBeta; }
|
||||
double Gamma() { return mGamma; }
|
||||
double X() { return mX; }
|
||||
double Y() { return mY; }
|
||||
double Z() { return mZ; }
|
||||
const nsIntRect& Rect() { return mRect; }
|
||||
nsAString& Characters() { return mCharacters; }
|
||||
int KeyCode() { return mKeyCode; }
|
||||
@ -427,6 +430,7 @@ protected:
|
||||
int mRangeType, mRangeStyles;
|
||||
int mRangeForeColor, mRangeBackColor;
|
||||
double mAlpha, mBeta, mGamma;
|
||||
double mX, mY, mZ;
|
||||
nsString mCharacters;
|
||||
nsRefPtr<nsGeoPosition> mGeoPosition;
|
||||
nsRefPtr<nsGeoPositionAddress> mGeoAddress;
|
||||
@ -445,6 +449,9 @@ protected:
|
||||
static jfieldID jAlphaField;
|
||||
static jfieldID jBetaField;
|
||||
static jfieldID jGammaField;
|
||||
static jfieldID jXField;
|
||||
static jfieldID jYField;
|
||||
static jfieldID jZField;
|
||||
static jfieldID jRectField;
|
||||
static jfieldID jNativeWindowField;
|
||||
|
||||
@ -467,18 +474,19 @@ public:
|
||||
NATIVE_POKE = 0,
|
||||
KEY_EVENT = 1,
|
||||
MOTION_EVENT = 2,
|
||||
SENSOR_EVENT = 3,
|
||||
LOCATION_EVENT = 4,
|
||||
IME_EVENT = 5,
|
||||
DRAW = 6,
|
||||
SIZE_CHANGED = 7,
|
||||
ACTIVITY_STOPPING = 8,
|
||||
ACTIVITY_PAUSING = 9,
|
||||
ACTIVITY_SHUTDOWN = 10,
|
||||
LOAD_URI = 11,
|
||||
SURFACE_CREATED = 12,
|
||||
SURFACE_DESTROYED = 13,
|
||||
GECKO_EVENT_SYNC = 14,
|
||||
ORIENTATION_EVENT = 3,
|
||||
ACCELERATION_EVENT = 4,
|
||||
LOCATION_EVENT = 5,
|
||||
IME_EVENT = 6,
|
||||
DRAW = 7,
|
||||
SIZE_CHANGED = 8,
|
||||
ACTIVITY_STOPPING = 9,
|
||||
ACTIVITY_PAUSING = 10,
|
||||
ACTIVITY_SHUTDOWN = 11,
|
||||
LOAD_URI = 12,
|
||||
SURFACE_CREATED = 13,
|
||||
SURFACE_DESTROYED = 14,
|
||||
GECKO_EVENT_SYNC = 15,
|
||||
dummy_java_enum_list_end
|
||||
};
|
||||
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include "prenv.h"
|
||||
|
||||
#include "AndroidBridge.h"
|
||||
#include "nsAccelerometerSystem.h"
|
||||
#include "nsDeviceMotionSystem.h"
|
||||
#include <android/log.h>
|
||||
#include <pthread.h>
|
||||
#include <wchar.h>
|
||||
@ -72,7 +72,7 @@ using namespace mozilla;
|
||||
PRLogModuleInfo *gWidgetLog = nsnull;
|
||||
#endif
|
||||
|
||||
nsAccelerometerSystem *gAccel = nsnull;
|
||||
nsDeviceMotionSystem *gDeviceMotionSystem = nsnull;
|
||||
nsIGeolocationUpdate *gLocationCallback = nsnull;
|
||||
|
||||
nsAppShell *nsAppShell::gAppShell = nsnull;
|
||||
@ -292,8 +292,18 @@ nsAppShell::ProcessNextNativeEvent(PRBool mayWait)
|
||||
NativeEventCallback();
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::SENSOR_EVENT:
|
||||
gAccel->AccelerationChanged(-curEvent->Alpha(), curEvent->Beta(), curEvent->Gamma());
|
||||
case AndroidGeckoEvent::ACCELERATION_EVENT:
|
||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
|
||||
-curEvent->X(),
|
||||
curEvent->Y(),
|
||||
curEvent->Z());
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::ORIENTATION_EVENT:
|
||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
|
||||
-curEvent->Alpha(),
|
||||
curEvent->Beta(),
|
||||
curEvent->Gamma());
|
||||
break;
|
||||
|
||||
case AndroidGeckoEvent::LOCATION_EVENT: {
|
||||
|
@ -53,7 +53,7 @@ XPIDLSRCS = \
|
||||
nsIBlocklistService.idl \
|
||||
nsIGIOService.idl \
|
||||
nsIGSettingsService.idl \
|
||||
nsIAccelerometer.idl \
|
||||
nsIDeviceMotion.idl \
|
||||
nsIGeolocationProvider.idl \
|
||||
nsIHapticFeedback.idl \
|
||||
$(NULL)
|
||||
|
@ -38,25 +38,30 @@
|
||||
|
||||
interface nsIDOMWindow;
|
||||
|
||||
[scriptable, uuid(0ec7ed95-dc9e-4d20-a5e2-8fc6a03bce67)]
|
||||
interface nsIAcceleration : nsISupports
|
||||
[scriptable, uuid(1B406E32-CF42-471E-A470-6FD600BF4C7B)]
|
||||
interface nsIDeviceMotionData : nsISupports
|
||||
{
|
||||
readonly attribute double alpha;
|
||||
readonly attribute double beta;
|
||||
readonly attribute double gamma;
|
||||
const unsigned long TYPE_ACCELERATION = 0;
|
||||
const unsigned long TYPE_ORIENTATION = 1;
|
||||
|
||||
readonly attribute unsigned long type;
|
||||
|
||||
readonly attribute double x;
|
||||
readonly attribute double y;
|
||||
readonly attribute double z;
|
||||
};
|
||||
|
||||
[scriptable, uuid(3386BED8-7393-4704-8FFC-1EB2C35432FF)]
|
||||
interface nsIAccelerationListener : nsISupports
|
||||
[scriptable, uuid(f01774a2-3b7e-4630-954b-196dc178221f)]
|
||||
interface nsIDeviceMotionListener : nsISupports
|
||||
{
|
||||
void onAccelerationChange(in nsIAcceleration aAcceleration);
|
||||
void onMotionChange(in nsIDeviceMotionData aMotionData);
|
||||
};
|
||||
|
||||
[scriptable, uuid(4B04E228-0B33-43FC-971F-AF60CEDB1C21)]
|
||||
interface nsIAccelerometer : nsISupports
|
||||
interface nsIDeviceMotion : nsISupports
|
||||
{
|
||||
void addListener(in nsIAccelerationListener aListener);
|
||||
void removeListener(in nsIAccelerationListener aListener);
|
||||
void addListener(in nsIDeviceMotionListener aListener);
|
||||
void removeListener(in nsIDeviceMotionListener aListener);
|
||||
|
||||
void addWindowListener(in nsIDOMWindow aWindow);
|
||||
void removeWindowListener(in nsIDOMWindow aWindow);
|
||||
@ -64,11 +69,11 @@ interface nsIAccelerometer : nsISupports
|
||||
};
|
||||
|
||||
/* for use by IPC system to notify non-chrome processes of
|
||||
* accelerometer events
|
||||
* device motion events
|
||||
*/
|
||||
[uuid(22dd1d8a-51bf-406f-8b6d-d1919f8f1c7d)]
|
||||
interface nsIAccelerometerUpdate : nsIAccelerometer
|
||||
[uuid(d3a56f08-b7b1-46bb-9dc1-fc3665a3631a)]
|
||||
interface nsIDeviceMotionUpdate : nsIDeviceMotion
|
||||
{
|
||||
/* must be called on the main thread or else */
|
||||
void accelerationChanged(in double alpha, in double beta, in double gamma);
|
||||
void deviceMotionChanged(in unsigned long type, in double x, in double y, in double z);
|
||||
};
|
Loading…
Reference in New Issue
Block a user