Bug 876238 - Convert DeviceAcceleration and DeviceRotationRate to WebIDL bindings. r=smaug
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Thu, 02 Jan 2014 07:52:47 +0900
changeset 162276 a19c708f134b425dcd0144ef07f157954c6b2ef9
parent 162275 370591efe014fd37c137b0fa3e686b13e49b67b4
child 162277 71a771fd043bd3e9933d82921c2737a5e029a15b
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerssmaug
bugs876238
milestone29.0a1
Bug 876238 - Convert DeviceAcceleration and DeviceRotationRate to WebIDL bindings. r=smaug
content/events/src/nsDOMDeviceMotionEvent.cpp
content/events/src/nsDOMDeviceMotionEvent.h
content/events/test/test_bug662678.html
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/bindings/Bindings.conf
dom/bindings/Codegen.py
dom/interfaces/events/moz.build
dom/interfaces/events/nsIDOMDeviceMotionEvent.idl
dom/system/nsDeviceSensors.cpp
dom/system/nsDeviceSensors.h
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/DeviceMotionEvent.webidl
--- a/content/events/src/nsDOMDeviceMotionEvent.cpp
+++ b/content/events/src/nsDOMDeviceMotionEvent.cpp
@@ -1,105 +1,96 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "nsDOMDeviceMotionEvent.h"
-#include "nsDOMClassInfoID.h"
+#include "nsContentUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED_3(nsDOMDeviceMotionEvent, nsDOMEvent,
                                      mAcceleration,
                                      mAccelerationIncludingGravity,
                                      mRotationRate)
 
 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,
-                                              bool aCanBubbleArg,
-                                              bool 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;
-}
-
 void
 nsDOMDeviceMotionEvent::InitDeviceMotionEvent(const nsAString& aType,
                                               bool aCanBubble,
                                               bool aCancelable,
-                                              nsIDOMDeviceAcceleration* aAcceleration,
-                                              nsIDOMDeviceAcceleration* aAccelerationIncludingGravity,
-                                              nsIDOMDeviceRotationRate* aRotationRate,
-                                              double aInterval,
+                                              const DeviceAccelerationInit& aAcceleration,
+                                              const DeviceAccelerationInit& aAccelerationIncludingGravity,
+                                              const DeviceRotationRateInit& aRotationRate,
+                                              Nullable<double> aInterval,
                                               ErrorResult& aRv)
 {
-  aRv = InitDeviceMotionEvent(aType,
-                              aCanBubble,
-                              aCancelable,
-                              aAcceleration,
-                              aAccelerationIncludingGravity,
-                              aRotationRate,
-                              aInterval);
-}
+  aRv = nsDOMEvent::InitEvent(aType, aCanBubble, aCancelable);
+  if (aRv.Failed()) {
+    return;
+  }
+
+  mAcceleration = new nsDOMDeviceAcceleration(this, aAcceleration.mX,
+                                              aAcceleration.mY,
+                                              aAcceleration.mZ);
 
-NS_IMETHODIMP
-nsDOMDeviceMotionEvent::GetAcceleration(nsIDOMDeviceAcceleration **aAcceleration)
-{
-  NS_ENSURE_ARG_POINTER(aAcceleration);
+  mAccelerationIncludingGravity =
+    new nsDOMDeviceAcceleration(this, aAccelerationIncludingGravity.mX,
+                                aAccelerationIncludingGravity.mY,
+                                aAccelerationIncludingGravity.mZ);
 
-  NS_IF_ADDREF(*aAcceleration = GetAcceleration());
-  return NS_OK;
+  mRotationRate = new nsDOMDeviceRotationRate(this, aRotationRate.mAlpha,
+                                              aRotationRate.mBeta,
+                                              aRotationRate.mGamma);
+  mInterval = aInterval;
 }
 
-NS_IMETHODIMP
-nsDOMDeviceMotionEvent::GetAccelerationIncludingGravity(nsIDOMDeviceAcceleration **aAccelerationIncludingGravity)
-{
-  NS_ENSURE_ARG_POINTER(aAccelerationIncludingGravity);
-
-  NS_IF_ADDREF(*aAccelerationIncludingGravity =
-               GetAccelerationIncludingGravity());
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMDeviceMotionEvent::GetRotationRate(nsIDOMDeviceRotationRate **aRotationRate)
+already_AddRefed<nsDOMDeviceMotionEvent>
+nsDOMDeviceMotionEvent::Constructor(const GlobalObject& aGlobal,
+                                    const nsAString& aType,
+                                    const DeviceMotionEventInit& aEventInitDict,
+                                    ErrorResult& aRv)
 {
-  NS_ENSURE_ARG_POINTER(aRotationRate);
+  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);
 
-  NS_IF_ADDREF(*aRotationRate = GetRotationRate());
-  return NS_OK;
-}
+  e->mAcceleration = new nsDOMDeviceAcceleration(e,
+    aEventInitDict.mAcceleration.mX,
+    aEventInitDict.mAcceleration.mY,
+    aEventInitDict.mAcceleration.mZ);
 
-NS_IMETHODIMP
-nsDOMDeviceMotionEvent::GetInterval(double *aInterval)
-{
-  NS_ENSURE_ARG_POINTER(aInterval);
+  e->mAccelerationIncludingGravity = new nsDOMDeviceAcceleration(e,
+    aEventInitDict.mAccelerationIncludingGravity.mX,
+    aEventInitDict.mAccelerationIncludingGravity.mY,
+    aEventInitDict.mAccelerationIncludingGravity.mZ);
 
-  *aInterval = Interval();
-  return NS_OK;
+  e->mRotationRate = new nsDOMDeviceRotationRate(e,
+    aEventInitDict.mRotationRate.mAlpha,
+    aEventInitDict.mRotationRate.mBeta,
+    aEventInitDict.mRotationRate.mGamma);
+
+  e->mInterval = aEventInitDict.mInterval;
+  e->SetTrusted(trusted);
+
+  return e.forget();
 }
 
 
 nsresult
 NS_NewDOMDeviceMotionEvent(nsIDOMEvent** aInstancePtrResult,
                            mozilla::dom::EventTarget* aOwner,
                            nsPresContext* aPresContext,
                            WidgetEvent* aEvent) 
@@ -107,96 +98,44 @@ NS_NewDOMDeviceMotionEvent(nsIDOMEvent**
   NS_ENSURE_ARG_POINTER(aInstancePtrResult);
 
   nsDOMDeviceMotionEvent* it =
     new nsDOMDeviceMotionEvent(aOwner, aPresContext, aEvent);
   return CallQueryInterface(it, aInstancePtrResult);
 }
 
 
-DOMCI_DATA(DeviceAcceleration, nsDOMDeviceAcceleration)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMDeviceAcceleration, mOwner)
+
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsDOMDeviceAcceleration, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsDOMDeviceAcceleration, Release)
 
-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(nsDOMDeviceMotionEvent* aOwner,
+                                                 Nullable<double> aX,
+                                                 Nullable<double> aY,
+                                                 Nullable<double> aZ)
+: mOwner(aOwner), mX(aX), mY(aY), mZ(aZ)
 {
+  SetIsDOMBinding();
 }
 
 nsDOMDeviceAcceleration::~nsDOMDeviceAcceleration()
 {
 }
 
-NS_IMETHODIMP
-nsDOMDeviceAcceleration::GetX(double *aX)
-{
-  NS_ENSURE_ARG_POINTER(aX);
-  *aX = mX;
-  return NS_OK;
-}
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMDeviceRotationRate, mOwner)
+
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsDOMDeviceRotationRate, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsDOMDeviceRotationRate, Release)
 
-NS_IMETHODIMP
-nsDOMDeviceAcceleration::GetY(double *aY)
-{
-  NS_ENSURE_ARG_POINTER(aY);
-  *aY = mY;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMDeviceAcceleration::GetZ(double *aZ)
+nsDOMDeviceRotationRate::nsDOMDeviceRotationRate(nsDOMDeviceMotionEvent* aOwner,
+                                                 Nullable<double> aAlpha,
+                                                 Nullable<double> aBeta,
+                                                 Nullable<double> aGamma)
+: mOwner(aOwner), mAlpha(aAlpha), mBeta(aBeta), mGamma(aGamma)
 {
-  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)
-{
+  SetIsDOMBinding();
 }
 
 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;
-}
--- a/content/events/src/nsDOMDeviceMotionEvent.h
+++ b/content/events/src/nsDOMDeviceMotionEvent.h
@@ -1,106 +1,156 @@
 /* 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/. */
 
 #ifndef nsDOMDeviceMotionEvent_h__
 #define nsDOMDeviceMotionEvent_h__
 
-#include "nsIDOMDeviceMotionEvent.h"
 #include "nsDOMEvent.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/DeviceMotionEventBinding.h"
 
-class nsDOMDeviceRotationRate MOZ_FINAL : public nsIDOMDeviceRotationRate
+class nsDOMDeviceRotationRate MOZ_FINAL : public nsWrapperCache
 {
 public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIDOMDEVICEROTATIONRATE
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsDOMDeviceRotationRate)
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsDOMDeviceRotationRate)
+
+  nsDOMDeviceRotationRate(nsDOMDeviceMotionEvent* aOwner,
+                          Nullable<double> aAlpha, Nullable<double> aBeta,
+                          Nullable<double> aGamma);
+  nsDOMDeviceRotationRate(double aAlpha, double aBeta, double aGamma)
+  {
+    nsDOMDeviceRotationRate(nullptr, Nullable<double>(aAlpha),
+                            Nullable<double>(aBeta), Nullable<double>(aGamma));
+  }
 
-  nsDOMDeviceRotationRate(double aAlpha, double aBeta, double aGamma);
+  nsDOMDeviceMotionEvent* GetParentObject() const
+  {
+    return mOwner;
+  }
+
+  virtual JSObject* WrapObject(JSContext* aCx,
+                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
+  {
+    return mozilla::dom::DeviceRotationRateBinding::Wrap(aCx, aScope, this);
+  }
+
+  Nullable<double> GetAlpha() const { return mAlpha; }
+  Nullable<double> GetBeta() const { return mBeta; }
+  Nullable<double> GetGamma() const { return mGamma; }
 
 private:
   ~nsDOMDeviceRotationRate();
 
 protected:
-  double mAlpha, mBeta, mGamma;
+  nsRefPtr<nsDOMDeviceMotionEvent> mOwner;
+  Nullable<double> mAlpha, mBeta, mGamma;
 };
 
-class nsDOMDeviceAcceleration MOZ_FINAL : public nsIDOMDeviceAcceleration
+class nsDOMDeviceAcceleration MOZ_FINAL : public nsWrapperCache
 {
 public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIDOMDEVICEACCELERATION
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsDOMDeviceAcceleration)
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsDOMDeviceAcceleration)
+
+  nsDOMDeviceAcceleration(nsDOMDeviceMotionEvent* aOwner,
+                          Nullable<double> aX, Nullable<double> aY,
+                          Nullable<double> aZ);
+  nsDOMDeviceAcceleration(double aX, double aY, double aZ)
+  {
+    nsDOMDeviceAcceleration(nullptr, Nullable<double>(aX),
+                            Nullable<double>(aY), Nullable<double>(aZ));
+  }
 
-  nsDOMDeviceAcceleration(double aX, double aY, double aZ);
+  nsDOMDeviceMotionEvent* GetParentObject() const
+  {
+    return mOwner;
+  }
+
+  virtual JSObject* WrapObject(JSContext* aCx,
+                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
+  {
+    return mozilla::dom::DeviceAccelerationBinding::Wrap(aCx, aScope, this);
+  }
+
+  Nullable<double> GetX() const { return mX; }
+  Nullable<double> GetY() const { return mY; }
+  Nullable<double> GetZ() const { return mZ; }
 
 private:
   ~nsDOMDeviceAcceleration();
 
 protected:
-  double mX, mY, mZ;
+  nsRefPtr<nsDOMDeviceMotionEvent> mOwner;
+  Nullable<double> mX, mY, mZ;
 };
 
-class nsDOMDeviceMotionEvent MOZ_FINAL : public nsDOMEvent,
-                                         public nsIDOMDeviceMotionEvent
+class nsDOMDeviceMotionEvent MOZ_FINAL : public nsDOMEvent
 {
+  typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit;
+  typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit;
 public:
 
   nsDOMDeviceMotionEvent(mozilla::dom::EventTarget* aOwner,
                          nsPresContext* aPresContext,
                          mozilla::WidgetEvent* aEvent)
   : nsDOMEvent(aOwner, 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)
 
   virtual JSObject* WrapObject(JSContext* aCx,
 			       JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
   {
     return mozilla::dom::DeviceMotionEventBinding::Wrap(aCx, aScope, this);
   }
 
-  nsIDOMDeviceAcceleration* GetAcceleration()
+  nsDOMDeviceAcceleration* GetAcceleration() const
   {
     return mAcceleration;
   }
 
-  nsIDOMDeviceAcceleration* GetAccelerationIncludingGravity()
+  nsDOMDeviceAcceleration* GetAccelerationIncludingGravity() const
   {
     return mAccelerationIncludingGravity;
   }
 
-  nsIDOMDeviceRotationRate* GetRotationRate()
+  nsDOMDeviceRotationRate* GetRotationRate() const
   {
     return mRotationRate;
   }
 
-  double Interval() const
+  Nullable<double> GetInterval() const
   {
     return mInterval;
   }
 
   void InitDeviceMotionEvent(const nsAString& aType,
                              bool aCanBubble,
                              bool aCancelable,
-                             nsIDOMDeviceAcceleration* aAcceleration,
-                             nsIDOMDeviceAcceleration* aAccelerationIncludingGravity,
-                             nsIDOMDeviceRotationRate* aRotationRate,
-                             double aInterval,
+                             const DeviceAccelerationInit& aAcceleration,
+                             const DeviceAccelerationInit& aAccelerationIncludingGravity,
+                             const DeviceRotationRateInit& aRotationRate,
+                             Nullable<double> aInterval,
                              mozilla::ErrorResult& aRv);
 
-  nsCOMPtr<nsIDOMDeviceAcceleration> mAcceleration;
-  nsCOMPtr<nsIDOMDeviceAcceleration> mAccelerationIncludingGravity;
-  nsCOMPtr<nsIDOMDeviceRotationRate> mRotationRate;
-  double mInterval;
+  static already_AddRefed<nsDOMDeviceMotionEvent>
+  Constructor(const mozilla::dom::GlobalObject& aGlobal,
+              const nsAString& aType,
+              const mozilla::dom::DeviceMotionEventInit& aEventInitDict,
+              mozilla::ErrorResult& aRv);
+
+protected:
+  nsRefPtr<nsDOMDeviceAcceleration> mAcceleration;
+  nsRefPtr<nsDOMDeviceAcceleration> mAccelerationIncludingGravity;
+  nsRefPtr<nsDOMDeviceRotationRate> mRotationRate;
+  Nullable<double> mInterval;
 };
 
 #endif
--- a/content/events/test/test_bug662678.html
+++ b/content/events/test/test_bug662678.html
@@ -18,62 +18,136 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script type="application/javascript">
 
 /** Test for Bug 662678 **/
 SimpleTest.waitForExplicitFinish();
 
 var checkMotion = function(event) {
   window.removeEventListener("devicemotion", checkMotion, true);
 
-  is(event.acceleration.x, 1.5);
-  is(event.acceleration.y, 2.5);
-  is(event.acceleration.z, 3.5);
-
-  is(event.accelerationIncludingGravity.x, 4.5);
-  is(event.accelerationIncludingGravity.y, 5.5);
-  is(event.accelerationIncludingGravity.z, 6.5);
-
-  is(event.rotationRate.alpha, 7.5);
-  is(event.rotationRate.beta, 8.5);
-  is(event.rotationRate.gamma, 9.5);
+  is(event.acceleration.x, 1.5, "acceleration.x");
+  is(event.acceleration.y, 2.5, "acceleration.y");
+  is(event.acceleration.z, 3.5, "acceleration.z");
+  is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x");
+  is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y");
+  is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z");
+  is(event.rotationRate.alpha, 7.5, "rotationRate.alpha");
+  is(event.rotationRate.beta, 8.5, "rotationRate.beta");
+  is(event.rotationRate.gamma, 9.5, "rotationRate.gamma");
+  is(event.interval, 0.5, "interval");
 
   var e = document.createEvent("DeviceMotionEvent");
   e.initDeviceMotionEvent('devicemotion', true, true,
-                              null, null, null, 0);
-  is(e.acceleration, null);
-  is(e.accelerationIncludingGravity, null);
-  is(e.rotationRate, null);
+                          null, null, null, null);
+  is(e.acceleration.x, null, "acceleration.x");
+  is(e.acceleration.y, null, "acceleration.y");
+  is(e.acceleration.z, null, "acceleration.z");
+  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
+  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
+  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
+  is(e.rotationRate.alpha, null, "rotationRate.alpha");
+  is(e.rotationRate.beta, null, "rotationRate.beta");
+  is(e.rotationRate.gamma, null, "rotationRate.gamma");
+  is(e.interval, null, "interval");
 
   e.initDeviceMotionEvent('devicemotion', true, true,
                           {}, {}, {}, 0);
+  is(e.acceleration.x, null, "acceleration.x");
+  is(e.acceleration.y, null, "acceleration.y");
+  is(e.acceleration.z, null, "acceleration.z");
+  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
+  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
+  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
+  is(e.rotationRate.alpha, null, "rotationRate.alpha");
+  is(e.rotationRate.beta, null, "rotationRate.beta");
+  is(e.rotationRate.gamma, null, "rotationRate.gamma");
+  is(e.interval, 0, "interval");
 
-  ok(isNaN(e.acceleration.x));
-  ok(isNaN(e.acceleration.y));
-  ok(isNaN(e.acceleration.z));
+  window.addEventListener("devicemotion", checkMotionCtor, true);
+
+  event = new DeviceMotionEvent('devicemotion', {
+    bubbles: true, cancelable: true,
+    acceleration: {x:1.5,y:2.5,z:3.5},
+    accelerationIncludingGravity: {x:4.5,y:5.5,z:6.5},
+    rotationRate: {alpha:7.5,beta:8.5,gamma:9.5},
+    interval: 0.5
+  });
+  window.dispatchEvent(event);
+};
+
+var checkMotionCtor = function(event) {
+  window.removeEventListener("devicemotion", checkMotionCtor, true);
+
+  is(event.acceleration.x, 1.5, "acceleration.x");
+  is(event.acceleration.y, 2.5, "acceleration.y");
+  is(event.acceleration.z, 3.5, "acceleration.z");
+  is(event.accelerationIncludingGravity.x, 4.5, "accelerationIncludingGravity.x");
+  is(event.accelerationIncludingGravity.y, 5.5, "accelerationIncludingGravity.y");
+  is(event.accelerationIncludingGravity.z, 6.5, "accelerationIncludingGravity.z");
+  is(event.rotationRate.alpha, 7.5, "rotationRate.alpha");
+  is(event.rotationRate.beta, 8.5, "rotationRate.beta");
+  is(event.rotationRate.gamma, 9.5, "rotationRate.gamma");
+  is(event.interval, 0.5, "interval");
 
-  ok(isNaN(e.accelerationIncludingGravity.x));
-  ok(isNaN(e.accelerationIncludingGravity.y));
-  ok(isNaN(e.accelerationIncludingGravity.z));
+  var e = new DeviceMotionEvent('devicemotion');
+  is(e.acceleration.x, null, "acceleration.x");
+  is(e.acceleration.y, null, "acceleration.y");
+  is(e.acceleration.z, null, "acceleration.z");
+  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
+  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
+  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
+  is(e.rotationRate.alpha, null, "rotationRate.alpha");
+  is(e.rotationRate.beta, null, "rotationRate.beta");
+  is(e.rotationRate.gamma, null, "rotationRate.gamma");
+  is(e.interval, null, "interval");
 
-  ok(isNaN(e.rotationRate.alpha));
-  ok(isNaN(e.rotationRate.beta));
-  ok(isNaN(e.rotationRate.gamma));
+  e = new DeviceMotionEvent('devicemotion', {
+    bubbles: true, cancelable: true,
+    acceleration: null, accelerationIncludingGravity: null,
+    rotationRate: null, interval: null
+  });
+  is(e.acceleration.x, null, "acceleration.x");
+  is(e.acceleration.y, null, "acceleration.y");
+  is(e.acceleration.z, null, "acceleration.z");
+  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
+  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
+  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
+  is(e.rotationRate.alpha, null, "rotationRate.alpha");
+  is(e.rotationRate.beta, null, "rotationRate.beta");
+  is(e.rotationRate.gamma, null, "rotationRate.gamma");
+  is(e.interval, null, "interval");
+
+  e = new DeviceMotionEvent('devicemotion', {
+    bubbles: true, cancelable: true,
+    acceleration: {}, accelerationIncludingGravity: {},
+    rotationRate: {}, interval: 0
+  });
+  is(e.acceleration.x, null, "acceleration.x");
+  is(e.acceleration.y, null, "acceleration.y");
+  is(e.acceleration.z, null, "acceleration.z");
+  is(e.accelerationIncludingGravity.x, null, "accelerationIncludingGravity.x");
+  is(e.accelerationIncludingGravity.y, null, "accelerationIncludingGravity.y");
+  is(e.accelerationIncludingGravity.z, null, "accelerationIncludingGravity.z");
+  is(e.rotationRate.alpha, null, "rotationRate.alpha");
+  is(e.rotationRate.beta, null, "rotationRate.beta");
+  is(e.rotationRate.gamma, null, "rotationRate.gamma");
+  is(e.interval, 0, "interval");
 
   SimpleTest.finish();
 };
 
 window.addEventListener("devicemotion", checkMotion, true);
 
 var event = DeviceMotionEvent;
 ok(!!event, "Should have seen DeviceMotionEvent!");
 
 event = document.createEvent("DeviceMotionEvent");
 event.initDeviceMotionEvent('devicemotion', true, true, 
                             {x:1.5,y:2.5,z:3.5},
                             {x:4.5,y:5.5,z:6.5},
                             {alpha:7.5,beta:8.5,gamma:9.5},
-                            0);
+                            0.5);
 window.dispatchEvent(event);
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -104,17 +104,16 @@
 #include "nsIDOMCSSFontFaceRule.h"
 #include "nsIDOMCSSMozDocumentRule.h"
 #include "nsIDOMCSSSupportsRule.h"
 #include "nsIDOMMozCSSKeyframeRule.h"
 #include "nsIDOMMozCSSKeyframesRule.h"
 #include "nsIDOMCSSPageRule.h"
 #include "nsIDOMCSSStyleRule.h"
 #include "nsIDOMCSSStyleSheet.h"
-#include "nsIDOMDeviceMotionEvent.h" //nsIDOMDeviceAcceleration
 #include "nsIDOMXULCommandDispatcher.h"
 #ifndef MOZ_DISABLE_CRYPTOLEGACY
 #include "nsIDOMCRMFObject.h"
 #endif
 #include "nsIControllers.h"
 #include "nsIBoxObject.h"
 #ifdef MOZ_XUL
 #include "nsITreeSelection.h"
@@ -322,21 +321,16 @@ static nsDOMClassInfoData sClassInfoData
                            nsIXPCScriptable::WANT_NEWRESOLVE |
                            nsIXPCScriptable::WANT_HASINSTANCE |
                            nsIXPCScriptable::WANT_CALL |
                            nsIXPCScriptable::WANT_CONSTRUCT |
                            nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
 
   // Misc Core related classes
 
-  NS_DEFINE_CLASSINFO_DATA(DeviceAcceleration, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
-  NS_DEFINE_CLASSINFO_DATA(DeviceRotationRate, nsDOMGenericSH,
-                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
-
   // CSS classes
   NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CSSCharsetRule, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsDOMGenericSH,
@@ -992,24 +986,16 @@ nsDOMClassInfo::Init()
   DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(DOMPrototype, nsIDOMDOMConstructor)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(DOMConstructor, nsIDOMDOMConstructor)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor)
   DOM_CLASSINFO_MAP_END
 
-  DOM_CLASSINFO_MAP_BEGIN(DeviceAcceleration, nsIDOMDeviceAcceleration)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceAcceleration)
-  DOM_CLASSINFO_MAP_END
-
-  DOM_CLASSINFO_MAP_BEGIN(DeviceRotationRate, nsIDOMDeviceRotationRate)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceRotationRate)
-  DOM_CLASSINFO_MAP_END
-
   DOM_CLASSINFO_MAP_BEGIN(CSSStyleRule, nsIDOMCSSStyleRule)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(CSSCharsetRule, nsIDOMCSSCharsetRule)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCharsetRule)
   DOM_CLASSINFO_MAP_END
 
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -4,19 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 // IWYU pragma: private, include "nsDOMClassInfoID.h"
 
 DOMCI_CLASS(Window)
 DOMCI_CLASS(Location)
 DOMCI_CLASS(DOMPrototype)
 DOMCI_CLASS(DOMConstructor)
 
-DOMCI_CLASS(DeviceAcceleration)
-DOMCI_CLASS(DeviceRotationRate)
-
 // CSS classes
 DOMCI_CLASS(CSSStyleRule)
 DOMCI_CLASS(CSSCharsetRule)
 DOMCI_CLASS(CSSImportRule)
 DOMCI_CLASS(CSSMediaRule)
 DOMCI_CLASS(CSSNameSpaceRule)
 DOMCI_CLASS(CSSRuleList)
 DOMCI_CLASS(StyleSheetList)
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -298,20 +298,30 @@ DOMInterfaces = {
     'headerFile': 'mozilla/dom/WorkerScope.h',
     'workers': True,
 },
 
 'DelayNode': {
     'resultNotAddRefed': [ 'delayTime' ],
 },
 
+'DeviceAcceleration': {
+    'nativeType': 'nsDOMDeviceAcceleration',
+    'headerFile': 'nsDOMDeviceMotionEvent.h',
+},
+
 'DeviceMotionEvent': {
     'nativeType': 'nsDOMDeviceMotionEvent',
 },
 
+'DeviceRotationRate': {
+    'nativeType': 'nsDOMDeviceRotationRate',
+    'headerFile': 'nsDOMDeviceMotionEvent.h',
+},
+
 'DeviceStorage': {
     'nativeType': 'nsDOMDeviceStorage',
     'headerFile': 'DeviceStorage.h',
 },
 
 'Document': [
 {
     'nativeType': 'nsIDocument',
@@ -1852,18 +1862,16 @@ def addExternalIface(iface, nativeType=N
     domInterface['notflattened'] = notflattened
     DOMInterfaces[iface] = domInterface
 
 addExternalIface('ApplicationCache', nativeType='nsIDOMOfflineResourceList')
 addExternalIface('ActivityOptions', nativeType='nsIDOMMozActivityOptions',
                  headerFile='nsIDOMActivityOptions.h')
 addExternalIface('Counter')
 addExternalIface('CSSRule')
-addExternalIface('DeviceAcceleration', headerFile='nsIDOMDeviceMotionEvent.h', notflattened=True)
-addExternalIface('DeviceRotationRate', headerFile='nsIDOMDeviceMotionEvent.h', notflattened=True)
 addExternalIface('mozIDOMApplication', nativeType='mozIDOMApplication', headerFile='nsIDOMApplicationRegistry.h')
 addExternalIface('CSSRuleList')
 addExternalIface('DOMStringList')
 addExternalIface('RTCDataChannel', nativeType='nsIDOMDataChannel')
 addExternalIface('File')
 addExternalIface('HitRegionOptions', nativeType='nsISupports')
 addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver')
 addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -9745,16 +9745,17 @@ class CGBindingRoot(CGThing):
                                              callbackDescriptors + jsImplemented),
                        curr],
                       "\n")
 
         # Add header includes.
         bindingHeaders = [header for (header, include) in
                           bindingHeaders.iteritems() if include]
         declareIncludes = ['mozilla/dom/BindingDeclarations.h',
+                          'mozilla/dom/Nullable.h',
                           'mozilla/ErrorResult.h',
                           'jspubtd.h',
                           'js/RootingAPI.h',
                           ]
         if jsImplemented:
             declareIncludes.append('nsWeakReference.h')
 
         curr = CGHeaders(descriptors,
--- a/dom/interfaces/events/moz.build
+++ b/dom/interfaces/events/moz.build
@@ -9,17 +9,16 @@ XPIDL_SOURCES += [
     'nsIDOMBeforeUnloadEvent.idl',
     'nsIDOMClipboardEvent.idl',
     'nsIDOMCloseEvent.idl',
     'nsIDOMCommandEvent.idl',
     'nsIDOMCompositionEvent.idl',
     'nsIDOMCustomEvent.idl',
     'nsIDOMDataContainerEvent.idl',
     'nsIDOMDataTransfer.idl',
-    'nsIDOMDeviceMotionEvent.idl',
     'nsIDOMDeviceOrientationEvent.idl',
     'nsIDOMDOMTransactionEvent.idl',
     'nsIDOMDragEvent.idl',
     'nsIDOMElementReplaceEvent.idl',
     'nsIDOMEvent.idl',
     'nsIDOMEventListener.idl',
     'nsIDOMEventTarget.idl',
     'nsIDOMFocusEvent.idl',
deleted file mode 100644
--- a/dom/interfaces/events/nsIDOMDeviceMotionEvent.idl
+++ /dev/null
@@ -1,40 +0,0 @@
-/* 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/. */
-
-#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, builtinclass, uuid(64c300f8-4bf9-47d0-86bc-2fafd7de38c7)]
-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;
-};
-
--- a/dom/system/nsDeviceSensors.cpp
+++ b/dom/system/nsDeviceSensors.cpp
@@ -343,48 +343,64 @@ nsDeviceSensors::FireDOMMotionEvent(nsID
                                     double y,
                                     double z)
 {
   // Attempt to coalesce events
   bool fireEvent = TimeStamp::Now() > mLastDOMMotionEventTime + TimeDuration::FromMilliseconds(DEFAULT_SENSOR_POLL);
 
   switch (type) {
   case nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION:
-    mLastAcceleration = new nsDOMDeviceAcceleration(x, y, z);
+    if (mLastAcceleration.empty()) {
+      mLastAcceleration.construct();
+    }
+    mLastAcceleration.ref().mX.SetValue(x);
+    mLastAcceleration.ref().mY.SetValue(y);
+    mLastAcceleration.ref().mZ.SetValue(z);
     break;
   case nsIDeviceSensorData::TYPE_ACCELERATION:
-    mLastAccelerationIncluduingGravity = new nsDOMDeviceAcceleration(x, y, z);
+    if (mLastAccelerationIncluduingGravity.empty()) {
+      mLastAccelerationIncluduingGravity.construct();
+    }
+    mLastAccelerationIncluduingGravity.ref().mX.SetValue(x);
+    mLastAccelerationIncluduingGravity.ref().mY.SetValue(y);
+    mLastAccelerationIncluduingGravity.ref().mZ.SetValue(z);
     break;
   case nsIDeviceSensorData::TYPE_GYROSCOPE:
-    mLastRotationRate = new nsDOMDeviceRotationRate(x, y, z);
+    if (mLastRotationRate.empty()) {
+      mLastRotationRate.construct();
+    }
+    mLastRotationRate.ref().mAlpha.SetValue(x);
+    mLastRotationRate.ref().mBeta.SetValue(y);
+    mLastRotationRate.ref().mGamma.SetValue(z);
     break;
   }
 
-  if (!fireEvent && (!mLastAcceleration || !mLastAccelerationIncluduingGravity || !mLastRotationRate)) {
+  if (!fireEvent && (mLastAcceleration.empty() ||
+                     mLastAccelerationIncluduingGravity.empty() ||
+                     mLastRotationRate.empty())) {
     return;
   }
 
   nsCOMPtr<nsIDOMEvent> event;
   domdoc->CreateEvent(NS_LITERAL_STRING("DeviceMotionEvent"), getter_AddRefs(event));
 
-  nsCOMPtr<nsIDOMDeviceMotionEvent> me = do_QueryInterface(event);
+  nsDOMDeviceMotionEvent* me = static_cast<nsDOMDeviceMotionEvent*>(event.get());
 
-  if (!me)
-    return;
-
+  ErrorResult rv;
   me->InitDeviceMotionEvent(NS_LITERAL_STRING("devicemotion"),
                             true,
                             false,
-                            mLastAcceleration,
-                            mLastAccelerationIncluduingGravity,
-                            mLastRotationRate,
-                            DEFAULT_SENSOR_POLL);
+                            mLastAcceleration.ref(),
+                            mLastAccelerationIncluduingGravity.ref(),
+                            mLastRotationRate.ref(),
+                            Nullable<double>(DEFAULT_SENSOR_POLL),
+                            rv);
 
   event->SetTrusted(true);
 
   bool defaultActionEnabled = true;
   target->DispatchEvent(event, &defaultActionEnabled);
 
-  mLastRotationRate = nullptr;
-  mLastAccelerationIncluduingGravity = nullptr;
-  mLastAcceleration = nullptr;
+  mLastRotationRate.destroy();
+  mLastAccelerationIncluduingGravity.destroy();
+  mLastAcceleration.destroy();
   mLastDOMMotionEventTime = TimeStamp::Now();
 }
--- a/dom/system/nsDeviceSensors.h
+++ b/dom/system/nsDeviceSensors.h
@@ -1,38 +1,38 @@
 /* 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/. */
 
 #ifndef nsDeviceSensors_h
 #define nsDeviceSensors_h
 
 #include "nsIDeviceSensors.h"
-#include "nsIDOMDeviceMotionEvent.h"
 #include "nsCOMArray.h"
 #include "nsTArray.h"
 #include "nsCOMPtr.h"
 #include "nsITimer.h"
 #include "nsIDOMDeviceOrientationEvent.h"
-#include "nsIDOMDeviceMotionEvent.h"
 #include "nsDOMDeviceMotionEvent.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/HalSensor.h"
 #include "nsDataHashtable.h"
 
 class nsIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 class EventTarget;
 }
 }
 
 class nsDeviceSensors : public nsIDeviceSensors, public mozilla::hal::ISensorObserver
 {
+  typedef mozilla::dom::DeviceAccelerationInit DeviceAccelerationInit;
+  typedef mozilla::dom::DeviceRotationRateInit DeviceRotationRateInit;
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDEVICESENSORS
 
   nsDeviceSensors();
 
   virtual ~nsDeviceSensors();
 
@@ -69,14 +69,14 @@ private:
   bool mEnabled;
 
   inline bool IsSensorEnabled(uint32_t aType) {
     return mWindowListeners[aType]->Length() > 0;
   }
 
   mozilla::TimeStamp mLastDOMMotionEventTime;
   bool mIsUserProximityNear;
-  nsRefPtr<nsDOMDeviceAcceleration> mLastAcceleration;
-  nsRefPtr<nsDOMDeviceAcceleration> mLastAccelerationIncluduingGravity;
-  nsRefPtr<nsDOMDeviceRotationRate> mLastRotationRate;
+  mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
+  mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncluduingGravity;
+  mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
 };
 
 #endif
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -189,22 +189,20 @@ var interfaceNamesInGlobalScope =
     {name: "DataErrorEvent", b2g: true, pref: "dom.mobileconnection.enabled"},
     {name: "DataStore", b2g: true, release: false},
     {name: "DataStoreChangeEvent", b2g: true, release: false},
     {name: "DataStoreCursor", b2g: true, release: false},
     "DataTransfer",
     "DelayNode",
     "DesktopNotification",
     "DesktopNotificationCenter",
-    "DeviceAcceleration",
     "DeviceLightEvent",
     "DeviceMotionEvent",
     "DeviceOrientationEvent",
     "DeviceProximityEvent",
-    "DeviceRotationRate",
     "DeviceStorage",
     "DeviceStorageChangeEvent",
     "Document",
     "DocumentFragment",
     "DocumentType",
     {name: "DOMConstructor", xbl: true},
     "DOMCursor",
     "DOMError",
--- a/dom/webidl/DeviceMotionEvent.webidl
+++ b/dom/webidl/DeviceMotionEvent.webidl
@@ -1,26 +1,58 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/.
  */
 
-interface DeviceAcceleration;
-interface DeviceRotationRate;
+[NoInterfaceObject]
+interface DeviceAcceleration {
+  readonly attribute double? x;
+  readonly attribute double? y;
+  readonly attribute double? z;
+};
+
+[NoInterfaceObject]
+interface DeviceRotationRate {
+  readonly attribute double? alpha;
+  readonly attribute double? beta;
+  readonly attribute double? gamma;
+};
+
+[Constructor(DOMString type, optional DeviceMotionEventInit eventInitDict)]
+interface DeviceMotionEvent : Event {
+  readonly attribute DeviceAcceleration? acceleration;
+  readonly attribute DeviceAcceleration? accelerationIncludingGravity;
+  readonly attribute DeviceRotationRate? rotationRate;
+  readonly attribute double? interval;
+};
 
-interface DeviceMotionEvent : Event
-{
+dictionary DeviceAccelerationInit {
+  double? x = null;
+  double? y = null;
+  double? z = null;
+};
+
+dictionary DeviceRotationRateInit {
+  double? alpha = null;
+  double? beta = null;
+  double? gamma = null;
+};
+
+dictionary DeviceMotionEventInit : EventInit {
+  DeviceAccelerationInit acceleration;
+  DeviceAccelerationInit accelerationIncludingGravity;
+  DeviceRotationRateInit rotationRate;
+  double? interval = null;
+};
+
+// Mozilla extensions.
+partial interface DeviceMotionEvent {
   [Throws]
   void initDeviceMotionEvent(DOMString type,
                              boolean canBubble,
                              boolean cancelable,
-                             DeviceAcceleration? acceleration,
-                             DeviceAcceleration? accelerationIncludingGravity,
-                             DeviceRotationRate? rotationRate,
-                             double interval);
-
-  readonly attribute DeviceAcceleration? acceleration;
-  readonly attribute DeviceAcceleration? accelerationIncludingGravity;
-  readonly attribute DeviceRotationRate? rotationRate;
-  readonly attribute double interval;
+                             DeviceAccelerationInit acceleration,
+                             DeviceAccelerationInit accelerationIncludingGravity,
+                             DeviceRotationRateInit rotationRate,
+                             double? interval);
 };
-