1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/DeviceMotionEvent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/dom/DeviceMotionEvent.h" 1.11 +#include "nsContentUtils.h" 1.12 + 1.13 +namespace mozilla { 1.14 +namespace dom { 1.15 + 1.16 +/****************************************************************************** 1.17 + * DeviceMotionEvent 1.18 + *****************************************************************************/ 1.19 + 1.20 +NS_IMPL_CYCLE_COLLECTION_INHERITED(DeviceMotionEvent, Event, 1.21 + mAcceleration, 1.22 + mAccelerationIncludingGravity, 1.23 + mRotationRate) 1.24 + 1.25 +NS_IMPL_ADDREF_INHERITED(DeviceMotionEvent, Event) 1.26 +NS_IMPL_RELEASE_INHERITED(DeviceMotionEvent, Event) 1.27 + 1.28 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DeviceMotionEvent) 1.29 +NS_INTERFACE_MAP_END_INHERITING(Event) 1.30 + 1.31 +void 1.32 +DeviceMotionEvent::InitDeviceMotionEvent( 1.33 + const nsAString& aType, 1.34 + bool aCanBubble, 1.35 + bool aCancelable, 1.36 + const DeviceAccelerationInit& aAcceleration, 1.37 + const DeviceAccelerationInit& aAccelIncludingGravity, 1.38 + const DeviceRotationRateInit& aRotationRate, 1.39 + Nullable<double> aInterval, 1.40 + ErrorResult& aRv) 1.41 +{ 1.42 + aRv = Event::InitEvent(aType, aCanBubble, aCancelable); 1.43 + if (aRv.Failed()) { 1.44 + return; 1.45 + } 1.46 + 1.47 + mAcceleration = new DeviceAcceleration(this, aAcceleration.mX, 1.48 + aAcceleration.mY, 1.49 + aAcceleration.mZ); 1.50 + 1.51 + mAccelerationIncludingGravity = 1.52 + new DeviceAcceleration(this, aAccelIncludingGravity.mX, 1.53 + aAccelIncludingGravity.mY, 1.54 + aAccelIncludingGravity.mZ); 1.55 + 1.56 + mRotationRate = new DeviceRotationRate(this, aRotationRate.mAlpha, 1.57 + aRotationRate.mBeta, 1.58 + aRotationRate.mGamma); 1.59 + mInterval = aInterval; 1.60 +} 1.61 + 1.62 +already_AddRefed<DeviceMotionEvent> 1.63 +DeviceMotionEvent::Constructor(const GlobalObject& aGlobal, 1.64 + const nsAString& aType, 1.65 + const DeviceMotionEventInit& aEventInitDict, 1.66 + ErrorResult& aRv) 1.67 +{ 1.68 + nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); 1.69 + nsRefPtr<DeviceMotionEvent> e = new DeviceMotionEvent(t, nullptr, nullptr); 1.70 + aRv = e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable); 1.71 + if (aRv.Failed()) { 1.72 + return nullptr; 1.73 + } 1.74 + bool trusted = e->Init(t); 1.75 + 1.76 + e->mAcceleration = new DeviceAcceleration(e, 1.77 + aEventInitDict.mAcceleration.mX, 1.78 + aEventInitDict.mAcceleration.mY, 1.79 + aEventInitDict.mAcceleration.mZ); 1.80 + 1.81 + e->mAccelerationIncludingGravity = new DeviceAcceleration(e, 1.82 + aEventInitDict.mAccelerationIncludingGravity.mX, 1.83 + aEventInitDict.mAccelerationIncludingGravity.mY, 1.84 + aEventInitDict.mAccelerationIncludingGravity.mZ); 1.85 + 1.86 + e->mRotationRate = new DeviceRotationRate(e, 1.87 + aEventInitDict.mRotationRate.mAlpha, 1.88 + aEventInitDict.mRotationRate.mBeta, 1.89 + aEventInitDict.mRotationRate.mGamma); 1.90 + 1.91 + e->mInterval = aEventInitDict.mInterval; 1.92 + e->SetTrusted(trusted); 1.93 + 1.94 + return e.forget(); 1.95 +} 1.96 + 1.97 +/****************************************************************************** 1.98 + * DeviceAcceleration 1.99 + *****************************************************************************/ 1.100 + 1.101 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DeviceAcceleration, mOwner) 1.102 + 1.103 +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DeviceAcceleration, AddRef) 1.104 +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DeviceAcceleration, Release) 1.105 + 1.106 +DeviceAcceleration::DeviceAcceleration(DeviceMotionEvent* aOwner, 1.107 + Nullable<double> aX, 1.108 + Nullable<double> aY, 1.109 + Nullable<double> aZ) 1.110 + : mOwner(aOwner) 1.111 + , mX(aX) 1.112 + , mY(aY) 1.113 + , mZ(aZ) 1.114 +{ 1.115 + SetIsDOMBinding(); 1.116 +} 1.117 + 1.118 +DeviceAcceleration::~DeviceAcceleration() 1.119 +{ 1.120 +} 1.121 + 1.122 +/****************************************************************************** 1.123 + * DeviceRotationRate 1.124 + *****************************************************************************/ 1.125 + 1.126 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(DeviceRotationRate, mOwner) 1.127 + 1.128 +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DeviceRotationRate, AddRef) 1.129 +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DeviceRotationRate, Release) 1.130 + 1.131 +DeviceRotationRate::DeviceRotationRate(DeviceMotionEvent* aOwner, 1.132 + Nullable<double> aAlpha, 1.133 + Nullable<double> aBeta, 1.134 + Nullable<double> aGamma) 1.135 + : mOwner(aOwner) 1.136 + , mAlpha(aAlpha) 1.137 + , mBeta(aBeta) 1.138 + , mGamma(aGamma) 1.139 +{ 1.140 + SetIsDOMBinding(); 1.141 +} 1.142 + 1.143 +DeviceRotationRate::~DeviceRotationRate() 1.144 +{ 1.145 +} 1.146 + 1.147 +} // namespace dom 1.148 +} // namespace mozilla 1.149 + 1.150 +using namespace mozilla; 1.151 +using namespace mozilla::dom; 1.152 + 1.153 +nsresult 1.154 +NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aInstancePtrResult, 1.155 + EventTarget* aOwner, 1.156 + nsPresContext* aPresContext, 1.157 + WidgetEvent* aEvent) 1.158 +{ 1.159 + NS_ENSURE_ARG_POINTER(aInstancePtrResult); 1.160 + 1.161 + DeviceMotionEvent* it = new DeviceMotionEvent(aOwner, aPresContext, aEvent); 1.162 + NS_ADDREF(it); 1.163 + *aInstancePtrResult = static_cast<Event*>(it); 1.164 + return NS_OK; 1.165 +}