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"
|
2014-01-01 14:52:47 -08:00
|
|
|
#include "nsContentUtils.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_END_INHERITING(nsDOMEvent)
|
|
|
|
|
2013-04-16 06:03:46 -07:00
|
|
|
void
|
|
|
|
nsDOMDeviceMotionEvent::InitDeviceMotionEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2014-01-01 14:52:47 -08:00
|
|
|
const DeviceAccelerationInit& aAcceleration,
|
|
|
|
const DeviceAccelerationInit& aAccelerationIncludingGravity,
|
|
|
|
const DeviceRotationRateInit& aRotationRate,
|
|
|
|
Nullable<double> aInterval,
|
2013-04-16 06:03:46 -07:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-01-01 14:52:47 -08:00
|
|
|
aRv = nsDOMEvent::InitEvent(aType, aCanBubble, aCancelable);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-16 06:03:46 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
mAcceleration = new nsDOMDeviceAcceleration(this, aAcceleration.mX,
|
|
|
|
aAcceleration.mY,
|
|
|
|
aAcceleration.mZ);
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
mAccelerationIncludingGravity =
|
|
|
|
new nsDOMDeviceAcceleration(this, aAccelerationIncludingGravity.mX,
|
|
|
|
aAccelerationIncludingGravity.mY,
|
|
|
|
aAccelerationIncludingGravity.mZ);
|
|
|
|
|
|
|
|
mRotationRate = new nsDOMDeviceRotationRate(this, aRotationRate.mAlpha,
|
|
|
|
aRotationRate.mBeta,
|
|
|
|
aRotationRate.mGamma);
|
|
|
|
mInterval = aInterval;
|
2011-06-19 22:36:17 -07:00
|
|
|
}
|
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
already_AddRefed<nsDOMDeviceMotionEvent>
|
|
|
|
nsDOMDeviceMotionEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const DeviceMotionEventInit& aEventInitDict,
|
|
|
|
ErrorResult& aRv)
|
2011-06-19 22:36:17 -07:00
|
|
|
{
|
2014-01-01 14:52:47 -08:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> t =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
nsRefPtr<nsDOMDeviceMotionEvent> e =
|
|
|
|
new nsDOMDeviceMotionEvent(t, nullptr, nullptr);
|
|
|
|
aRv = e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
bool trusted = e->Init(t);
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
e->mAcceleration = new nsDOMDeviceAcceleration(e,
|
|
|
|
aEventInitDict.mAcceleration.mX,
|
|
|
|
aEventInitDict.mAcceleration.mY,
|
|
|
|
aEventInitDict.mAcceleration.mZ);
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
e->mAccelerationIncludingGravity = new nsDOMDeviceAcceleration(e,
|
|
|
|
aEventInitDict.mAccelerationIncludingGravity.mX,
|
|
|
|
aEventInitDict.mAccelerationIncludingGravity.mY,
|
|
|
|
aEventInitDict.mAccelerationIncludingGravity.mZ);
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
e->mRotationRate = new nsDOMDeviceRotationRate(e,
|
|
|
|
aEventInitDict.mRotationRate.mAlpha,
|
|
|
|
aEventInitDict.mRotationRate.mBeta,
|
|
|
|
aEventInitDict.mRotationRate.mGamma);
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
e->mInterval = aEventInitDict.mInterval;
|
|
|
|
e->SetTrusted(trusted);
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
return e.forget();
|
2011-06-19 22:36:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMDeviceAcceleration, mOwner)
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsDOMDeviceAcceleration, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsDOMDeviceAcceleration, Release)
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
nsDOMDeviceAcceleration::nsDOMDeviceAcceleration(nsDOMDeviceMotionEvent* aOwner,
|
|
|
|
Nullable<double> aX,
|
|
|
|
Nullable<double> aY,
|
|
|
|
Nullable<double> aZ)
|
|
|
|
: mOwner(aOwner), mX(aX), mY(aY), mZ(aZ)
|
2011-06-19 22:36:17 -07:00
|
|
|
{
|
2014-01-01 14:52:47 -08:00
|
|
|
SetIsDOMBinding();
|
2011-06-19 22:36:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMDeviceAcceleration::~nsDOMDeviceAcceleration()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMDeviceRotationRate, mOwner)
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsDOMDeviceRotationRate, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsDOMDeviceRotationRate, Release)
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2014-01-01 14:52:47 -08:00
|
|
|
nsDOMDeviceRotationRate::nsDOMDeviceRotationRate(nsDOMDeviceMotionEvent* aOwner,
|
|
|
|
Nullable<double> aAlpha,
|
|
|
|
Nullable<double> aBeta,
|
|
|
|
Nullable<double> aGamma)
|
|
|
|
: mOwner(aOwner), mAlpha(aAlpha), mBeta(aBeta), mGamma(aGamma)
|
2011-06-19 22:36:17 -07:00
|
|
|
{
|
2014-01-01 14:52:47 -08:00
|
|
|
SetIsDOMBinding();
|
2011-06-19 22:36:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMDeviceRotationRate::~nsDOMDeviceRotationRate()
|
|
|
|
{
|
|
|
|
}
|