2013-05-21 16:23:53 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-06-19 22:36:17 -07:00
|
|
|
|
|
|
|
#include "nsDOMDeviceMotionEvent.h"
|
2013-05-20 12:34:12 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2013-04-16 06:03:46 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2013-05-21 16:23:53 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED_3(nsDOMDeviceMotionEvent, nsDOMEvent,
|
|
|
|
mAcceleration,
|
|
|
|
mAccelerationIncludingGravity,
|
|
|
|
mRotationRate)
|
2011-06-19 22:36:17 -07:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMDeviceMotionEvent, nsDOMEvent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMDeviceMotionEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceMotionEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMDeviceMotionEvent::InitDeviceMotionEvent(const nsAString & aEventTypeArg,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCanBubbleArg,
|
|
|
|
bool aCancelableArg,
|
2011-06-19 22:36:17 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-16 06:03:46 -07:00
|
|
|
void
|
|
|
|
nsDOMDeviceMotionEvent::InitDeviceMotionEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
nsIDOMDeviceAcceleration* aAcceleration,
|
|
|
|
nsIDOMDeviceAcceleration* aAccelerationIncludingGravity,
|
|
|
|
nsIDOMDeviceRotationRate* aRotationRate,
|
|
|
|
double aInterval,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = InitDeviceMotionEvent(aType,
|
|
|
|
aCanBubble,
|
|
|
|
aCancelable,
|
|
|
|
aAcceleration,
|
|
|
|
aAccelerationIncludingGravity,
|
|
|
|
aRotationRate,
|
|
|
|
aInterval);
|
|
|
|
}
|
|
|
|
|
2011-06-19 22:36:17 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMDeviceMotionEvent::GetAcceleration(nsIDOMDeviceAcceleration **aAcceleration)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAcceleration);
|
|
|
|
|
2013-04-16 06:03:46 -07:00
|
|
|
NS_IF_ADDREF(*aAcceleration = GetAcceleration());
|
2011-06-19 22:36:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMDeviceMotionEvent::GetAccelerationIncludingGravity(nsIDOMDeviceAcceleration **aAccelerationIncludingGravity)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAccelerationIncludingGravity);
|
|
|
|
|
2013-04-16 06:03:46 -07:00
|
|
|
NS_IF_ADDREF(*aAccelerationIncludingGravity =
|
|
|
|
GetAccelerationIncludingGravity());
|
2011-06-19 22:36:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMDeviceMotionEvent::GetRotationRate(nsIDOMDeviceRotationRate **aRotationRate)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRotationRate);
|
|
|
|
|
2013-04-16 06:03:46 -07:00
|
|
|
NS_IF_ADDREF(*aRotationRate = GetRotationRate());
|
2011-06-19 22:36:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMDeviceMotionEvent::GetInterval(double *aInterval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInterval);
|
|
|
|
|
2013-04-16 06:03:46 -07:00
|
|
|
*aInterval = Interval();
|
2011-06-19 22:36:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2011-06-19 22:36:17 -07:00
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* aEvent)
|
2011-06-19 22:36:17 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMDeviceMotionEvent* it =
|
|
|
|
new nsDOMDeviceMotionEvent(aOwner, aPresContext, aEvent);
|
2011-06-19 22:36:17 -07:00
|
|
|
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;
|
|
|
|
}
|