Bug 615597 - Implement devicemotion and fix up deviceorientation events. r=smaug/azakai
authorDoug Turner <dougt@dougt.org>
Sun, 19 Jun 2011 22:36:17 -0700
changeset 71308 d48792c8de6702298d2738805d7bf9967995a94b
parent 71307 a8e2f5953d1ca40cb6388b2a3a0e0c509223f3ea
child 71309 aeed034b74d048f7d4d9a81cfd66686afafb4ccb
push id20527
push usermlamouri@mozilla.com
push dateMon, 20 Jun 2011 11:45:12 +0000
treeherdermozilla-central@aeed034b74d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, azakai
bugs615597
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 615597 - Implement devicemotion and fix up deviceorientation events. r=smaug/azakai
content/base/src/nsGkAtomList.h
content/events/public/nsIPrivateDOMEvent.h
content/events/src/Makefile.in
content/events/src/nsDOMDeviceMotionEvent.cpp
content/events/src/nsDOMDeviceMotionEvent.h
content/events/src/nsDOMDeviceOrientationEvent.cpp
content/events/src/nsDOMDeviceOrientationEvent.h
content/events/src/nsDOMOrientationEvent.cpp
content/events/src/nsDOMOrientationEvent.h
content/events/src/nsEventDispatcher.cpp
content/events/src/nsEventListenerManager.cpp
content/events/test/Makefile.in
content/events/test/test_bug615597.html
content/events/test/test_bug662678.html
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
dom/interfaces/events/Makefile.in
dom/interfaces/events/nsIDOMDeviceMotionEvent.idl
dom/interfaces/events/nsIDOMDeviceOrientationEvent.idl
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
dom/system/Makefile.in
dom/system/android/Makefile.in
dom/system/android/nsAccelerometerSystem.cpp
dom/system/android/nsAccelerometerSystem.h
dom/system/android/nsDeviceMotionSystem.cpp
dom/system/android/nsDeviceMotionSystem.h
dom/system/cocoa/Makefile.in
dom/system/cocoa/nsAccelerometerSystem.h
dom/system/cocoa/nsAccelerometerSystem.mm
dom/system/cocoa/nsDeviceMotionSystem.h
dom/system/cocoa/nsDeviceMotionSystem.mm
dom/system/nsAccelerometer.cpp
dom/system/nsAccelerometer.h
dom/system/nsDeviceMotion.cpp
dom/system/nsDeviceMotion.h
dom/system/unix/Makefile.in
dom/system/unix/nsAccelerometerSystem.cpp
dom/system/unix/nsAccelerometerSystem.h
dom/system/unix/nsDeviceMotionSystem.cpp
dom/system/unix/nsDeviceMotionSystem.h
dom/system/windows/Makefile.in
dom/system/windows/nsAccelerometerSystem.cpp
dom/system/windows/nsAccelerometerSystem.h
dom/system/windows/nsDeviceMotionSystem.cpp
dom/system/windows/nsDeviceMotionSystem.h
embedding/android/GeckoAppShell.java
embedding/android/GeckoEvent.java
layout/build/nsLayoutModule.cpp
modules/libpref/src/init/all.js
widget/src/android/AndroidBridge.cpp
widget/src/android/AndroidBridge.h
widget/src/android/AndroidJavaWrappers.cpp
widget/src/android/AndroidJavaWrappers.h
widget/src/android/nsAppShell.cpp
xpcom/system/Makefile.in
xpcom/system/nsIAccelerometer.idl
xpcom/system/nsIDeviceMotion.idl
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -1694,16 +1694,17 @@ GK_ATOM(onMozPressTapGesture, "onMozPres
 
 // Touch events
 GK_ATOM(onMozTouchDown, "onMozTouchDown")
 GK_ATOM(onMozTouchMove, "onMozTouchMove")
 GK_ATOM(onMozTouchUp, "onMozTouchUp")
 
 // orientation support
 GK_ATOM(ondeviceorientation, "ondeviceorientation")
+GK_ATOM(ondevicemotion, "ondevicemotion")
 
 //---------------------------------------------------------------------------
 // Special atoms
 //---------------------------------------------------------------------------
 
 // Node types
 GK_ATOM(cdataTagName, "#cdata-section")
 GK_ATOM(commentTagName, "#comment")
--- a/content/events/public/nsIPrivateDOMEvent.h
+++ b/content/events/public/nsIPrivateDOMEvent.h
@@ -87,16 +87,18 @@ nsresult
 NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsKeyEvent *aEvent);
 nsresult
 NS_NewDOMMutationEvent(nsIDOMEvent** aResult NS_OUTPARAM, nsPresContext* aPresContext, class nsMutationEvent* aEvent);
 nsresult
 NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
 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);
 nsresult
 NS_NewDOMPageTransitionEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
 nsresult
 NS_NewDOMSVGEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsEvent* aEvent);
 nsresult
--- a/content/events/src/Makefile.in
+++ b/content/events/src/Makefile.in
@@ -58,17 +58,18 @@ CPPSRCS		= \
 		nsDOMUIEvent.cpp \
 		nsDOMKeyboardEvent.cpp \
 		nsDOMTextEvent.cpp \
 		nsDOMMouseEvent.cpp \
 		nsDOMMouseScrollEvent.cpp \
 		nsDOMDragEvent.cpp \
 		nsDOMMutationEvent.cpp \
 		nsDOMPopupBlockedEvent.cpp \
-		nsDOMOrientationEvent.cpp \
+		nsDOMDeviceOrientationEvent.cpp \
+		nsDOMDeviceMotionEvent.cpp \
 		nsDOMBeforeUnloadEvent.cpp \
 		nsDOMPageTransitionEvent.cpp \
 		nsDOMXULCommandEvent.cpp \
 		nsDOMCommandEvent.cpp \
 		nsDOMMessageEvent.cpp \
 		nsPaintRequest.cpp \
 		nsPrivateTextRange.cpp \
 		nsDOMEventGroup.cpp \
new file mode 100644
--- /dev/null
+++ b/content/events/src/nsDOMDeviceMotionEvent.cpp
@@ -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;
+}
new file mode 100644
--- /dev/null
+++ b/content/events/src/nsDOMDeviceMotionEvent.h
@@ -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
rename from content/events/src/nsDOMOrientationEvent.cpp
rename to content/events/src/nsDOMDeviceOrientationEvent.cpp
--- a/content/events/src/nsDOMOrientationEvent.cpp
+++ b/content/events/src/nsDOMDeviceOrientationEvent.cpp
@@ -29,93 +29,85 @@
  * 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 "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);
 
   mAlpha = aAlpha;
   mBeta = aBeta;
   mGamma = aGamma;
   mAbsolute = aAbsolute;
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsDOMOrientationEvent::GetAlpha(double *aAlpha)
+NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetAlpha(double *aAlpha)
 {
   NS_ENSURE_ARG_POINTER(aAlpha);
 
   *aAlpha = mAlpha;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsDOMOrientationEvent::GetBeta(double *aBeta)
+NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetBeta(double *aBeta)
 {
   NS_ENSURE_ARG_POINTER(aBeta);
 
   *aBeta = mBeta;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsDOMOrientationEvent::GetGamma(double *aGamma)
+NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetGamma(double *aGamma)
 {
   NS_ENSURE_ARG_POINTER(aGamma);
 
   *aGamma = mGamma;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsDOMOrientationEvent::GetAbsolute(PRBool *aAbsolute)
+NS_IMETHODIMP nsDOMDeviceOrientationEvent::GetAbsolute(PRBool *aAbsolute)
 {
   NS_ENSURE_ARG_POINTER(aAbsolute);
 
   *aAbsolute = mAbsolute;
   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;
   }
 
   return CallQueryInterface(it, aInstancePtrResult);
 }
rename from content/events/src/nsDOMOrientationEvent.h
rename to content/events/src/nsDOMDeviceOrientationEvent.h
--- a/content/events/src/nsDOMOrientationEvent.h
+++ b/content/events/src/nsDOMDeviceOrientationEvent.h
@@ -29,40 +29,40 @@
  * 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 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),
     mGamma(0),
     mAbsolute(PR_TRUE) {}
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // Forward to nsDOMEvent
   NS_FORWARD_TO_NSDOMEVENT
 
-  // nsIDOMOrientationEvent Interface
+  // nsIDOMDeviceOrientationEvent Interface
   NS_DECL_NSIDOMDEVICEORIENTATIONEVENT
 
 protected:
   double mAlpha, mBeta, mGamma;
   PRBool mAbsolute;
 };
 
 #endif
--- a/content/events/src/nsEventDispatcher.cpp
+++ b/content/events/src/nsEventDispatcher.cpp
@@ -832,16 +832,18 @@ nsEventDispatcher::CreateEvent(nsPresCon
     return NS_NewDOMMutationEvent(aDOMEvent, aPresContext, nsnull);
   if (aEventType.LowerCaseEqualsLiteral("textevent") ||
       aEventType.LowerCaseEqualsLiteral("textevents"))
     return NS_NewDOMTextEvent(aDOMEvent, aPresContext, nsnull);
   if (aEventType.LowerCaseEqualsLiteral("popupblockedevents"))
     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);
   if (aEventType.LowerCaseEqualsLiteral("event") ||
       aEventType.LowerCaseEqualsLiteral("events") ||
       aEventType.LowerCaseEqualsLiteral("htmlevents"))
     return NS_NewDOMEvent(aDOMEvent, aPresContext, nsnull);
   if (aEventType.LowerCaseEqualsLiteral("svgevent") ||
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -495,17 +495,18 @@ nsEventListenerManager::AddEventListener
     nsPIDOMWindow* window = GetInnerWindowForTarget();
     if (window) {
       // If aType is NS_MUTATION_SUBTREEMODIFIED, we need to listen all
       // mutations. nsContentUtils::HasMutationListeners relies on this.
       window->SetMutationListeners((aType == NS_MUTATION_SUBTREEMODIFIED) ?
                                    kAllMutationBits :
                                    MutationBitForEventType(aType));
     }
-  } else if (aTypeAtom == nsGkAtoms::ondeviceorientation) {
+  } else if (aTypeAtom == nsGkAtoms::ondeviceorientation ||
+             aTypeAtom == nsGkAtoms::ondevicemotion) {
     nsPIDOMWindow* window = GetInnerWindowForTarget();
     if (window)
       window->SetHasOrientationEventListener();
   } else if ((aType >= NS_MOZTOUCH_DOWN && aType <= NS_MOZTOUCH_UP) ||
              (aTypeAtom == nsGkAtoms::ontouchstart ||
               aTypeAtom == nsGkAtoms::ontouchend ||
               aTypeAtom == nsGkAtoms::ontouchmove ||
               aTypeAtom == nsGkAtoms::ontouchenter ||
--- a/content/events/test/Makefile.in
+++ b/content/events/test/Makefile.in
@@ -99,16 +99,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug624127.html \
 		test_bug650493.html \
 		test_bug641477.html \
 		test_bug648573.html \
 		test_bug615597.html \
 		test_bug656379-1.html \
 		test_bug656379-2.html \
 		test_bug656954.html \
+ 		test_bug662678.html \
 		$(NULL)
 
 #bug 585630
 ifneq (mobile,$(MOZ_BUILD_APP))
 _TEST_FILES += \
 		test_dragstart.html \
 		$(NULL)
 endif
--- a/content/events/test/test_bug615597.html
+++ b/content/events/test/test_bug615597.html
@@ -20,17 +20,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 615597 **/
 
 window.addEventListener("deviceorientation", function(event) {
   is(event.alpha, 1.5);
   is(event.beta, 2.25);
   is(event.gamma, 3.667);
   is(event.absolute, true);
-  is(event.compassCalibrated, true);
   SimpleTest.finish();
 }, true);
 
 var event = DeviceOrientationEvent;
 ok(!!event, "Should have seen DeviceOrientationEvent!");
 
 event = document.createEvent("DeviceOrientationEvent");
 event.initDeviceOrientationEvent('deviceorientation', true, true, 1.5, 2.25, 3.667, true);
new file mode 100644
--- /dev/null
+++ b/content/events/test/test_bug662678.html
@@ -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>
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -327,16 +327,17 @@
 #include "nsIDOMMozCSSKeyframeRule.h"
 #include "nsIDOMMozCSSKeyframesRule.h"
 #endif
 #include "nsIDOMCSSPrimitiveValue.h"
 #include "nsIDOMCSSStyleRule.h"
 #include "nsIDOMCSSStyleSheet.h"
 #include "nsDOMCSSValueList.h"
 #include "nsIDOMDeviceOrientationEvent.h"
+#include "nsIDOMDeviceMotionEvent.h"
 #include "nsIDOMRange.h"
 #include "nsIDOMNSRange.h"
 #include "nsIDOMRangeException.h"
 #include "nsIDOMNodeIterator.h"
 #include "nsIDOMTreeWalker.h"
 #include "nsIDOMXULDocument.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMXULCommandDispatcher.h"
@@ -745,18 +746,25 @@ static nsDOMClassInfoData sClassInfoData
   NS_DEFINE_CLASSINFO_DATA(MouseScrollEvent, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(DragEvent, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(KeyboardEvent, nsDOMGenericSH,
                            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,
                            DOCUMENT_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(HTMLOptionsCollection,
                            nsHTMLOptionsCollectionSH,
                            ARRAY_SCRIPTABLE_FLAGS |
                            nsIXPCScriptable::WANT_SETPROPERTY)
@@ -2559,16 +2567,31 @@ nsDOMClassInfo::Init()
     DOM_CLASSINFO_EVENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(DeviceOrientationEvent, nsIDOMDeviceOrientationEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceOrientationEvent)
     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
 
   DOM_CLASSINFO_MAP_BEGIN(PageTransitionEvent, nsIDOMPageTransitionEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMPageTransitionEvent)
     DOM_CLASSINFO_EVENT_MAP_ENTRIES
   DOM_CLASSINFO_MAP_END
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -71,16 +71,19 @@ DOMCI_CLASS(Event)
 DOMCI_CLASS(MutationEvent)
 DOMCI_CLASS(UIEvent)
 DOMCI_CLASS(MouseEvent)
 DOMCI_CLASS(MouseScrollEvent)
 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)
 DOMCI_CLASS(HTMLOptionsCollection)
 DOMCI_CLASS(HTMLCollection)
 
 // HTML element classes
 DOMCI_CLASS(HTMLElement)
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -92,17 +92,17 @@
 #include "nsAutoJSValHolder.h"
 #include "nsDOMMediaQueryList.h"
 
 // Interfaces Needed
 #include "nsIFrame.h"
 #include "nsCanvasFrame.h"
 #include "nsIWidget.h"
 #include "nsIBaseWindow.h"
-#include "nsAccelerometer.h"
+#include "nsDeviceMotion.h"
 #include "nsIContent.h"
 #include "nsIContentViewerEdit.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellLoadInfo.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeNode.h"
 #include "nsIEditorDocShell.h"
 #include "nsIDocCharset.h"
@@ -825,17 +825,17 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalW
     mShowAccelerators(PR_FALSE),
     mShowFocusRings(PR_FALSE),
 #else
     mShowAccelerators(PR_TRUE),
     mShowFocusRings(PR_TRUE),
 #endif
     mShowFocusRingForContent(PR_FALSE),
     mFocusByKeyOccurred(PR_FALSE),
-    mHasAcceleration(PR_FALSE),
+    mHasDeviceMotion(PR_FALSE),
     mNotifiedIDDestroyed(PR_FALSE),
     mTimeoutInsertionPoint(nsnull),
     mTimeoutPublicIdCounter(1),
     mTimeoutFiringDepth(0),
     mJSObject(nsnull),
     mPendingStorageEventsObsolete(nsnull),
     mTimeoutsSuspendDepth(0),
     mFocusMethod(0),
@@ -1132,18 +1132,18 @@ nsGlobalWindow::CleanUp(PRBool aIgnoreMo
   mParentTarget = nsnull;
 
   nsGlobalWindow *inner = GetCurrentInnerWindowInternal();
 
   if (inner) {
     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");
     nsGlobalChromeWindow *asChrome = static_cast<nsGlobalChromeWindow*>(this);
     if (asChrome->mMessageManager) {
       static_cast<nsFrameMessageManager*>(
         asChrome->mMessageManager.get())->Disconnect();
     }
@@ -7532,35 +7532,34 @@ void nsGlobalWindow::UpdateTouchState()
 
   if (mMayHaveTouchEventListener) {
     mainWidget->RegisterTouchWindow();
   } else {
     mainWidget->UnregisterTouchWindow();
   }
 }
 
-
 void
-nsGlobalWindow::EnableAccelerationUpdates()
-{
-  if (mHasAcceleration) {
-    nsCOMPtr<nsIAccelerometer> ac =
-      do_GetService(NS_ACCELEROMETER_CONTRACTID);
+nsGlobalWindow::EnableDeviceMotionUpdates()
+{
+  if (mHasDeviceMotion) {
+    nsCOMPtr<nsIDeviceMotion> ac =
+      do_GetService(NS_DEVICE_MOTION_CONTRACTID);
     if (ac) {
       ac->AddWindowListener(this);
     }
   }
 }
 
 void
-nsGlobalWindow::DisableAccelerationUpdates()
-{
-  if (mHasAcceleration) {
-    nsCOMPtr<nsIAccelerometer> ac =
-      do_GetService(NS_ACCELEROMETER_CONTRACTID);
+nsGlobalWindow::DisableDeviceMotionUpdates()
+{
+  if (mHasDeviceMotion) {
+    nsCOMPtr<nsIDeviceMotion> ac =
+      do_GetService(NS_DEVICE_MOTION_CONTRACTID);
     if (ac) {
       ac->RemoveWindowListener(this);
     }
   }
 }
 
 void
 nsGlobalWindow::SetChromeEventHandler(nsPIDOMEventTarget* aChromeEventHandler)
@@ -9853,17 +9852,17 @@ nsGlobalWindow::SuspendTimeouts(PRUint32
                                 PRBool aFreezeChildren)
 {
   FORWARD_TO_INNER_VOID(SuspendTimeouts, (aIncrease, aFreezeChildren));
 
   PRBool suspended = (mTimeoutsSuspendDepth != 0);
   mTimeoutsSuspendDepth += aIncrease;
 
   if (!suspended) {
-    DisableAccelerationUpdates();
+    DisableDeviceMotionUpdates();
 
     nsDOMThreadService* dts = nsDOMThreadService::get();
     if (dts) {
       dts->SuspendWorkersForGlobal(static_cast<nsIScriptGlobalObject*>(this));
     }
   
     TimeStamp now = TimeStamp::Now();
     for (nsTimeout *t = FirstTimeout(); IsTimeout(t); t = t->Next()) {
@@ -9929,17 +9928,17 @@ nsGlobalWindow::ResumeTimeouts(PRBool aT
   FORWARD_TO_INNER(ResumeTimeouts, (), NS_ERROR_NOT_INITIALIZED);
 
   NS_ASSERTION(mTimeoutsSuspendDepth, "Mismatched calls to ResumeTimeouts!");
   --mTimeoutsSuspendDepth;
   PRBool shouldResume = (mTimeoutsSuspendDepth == 0);
   nsresult rv;
 
   if (shouldResume) {
-    EnableAccelerationUpdates();
+    EnableDeviceMotionUpdates();
 
     nsDOMThreadService* dts = nsDOMThreadService::get();
     if (dts) {
       dts->ResumeWorkersForGlobal(static_cast<nsIScriptGlobalObject*>(this));
     }
 
     // Restore all of the timeouts, using the stored time remaining
     // (stored in timeout->mTimeRemaining).
@@ -10048,18 +10047,18 @@ nsGlobalWindow::SetScriptTypeID(PRUint32
 {
   NS_ERROR("Can't change default script type for a document");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 void
 nsGlobalWindow::SetHasOrientationEventListener()
 {
-  mHasAcceleration = PR_TRUE;
-  EnableAccelerationUpdates();
+  mHasDeviceMotion = PR_TRUE;
+  EnableDeviceMotionUpdates();
 }
 
 NS_IMETHODIMP
 nsGlobalWindow::GetURL(nsIDOMMozURLProperty** aURL)
 {
   FORWARD_TO_INNER(GetURL, (aURL), NS_ERROR_UNEXPECTED);
 
   if (!mURLProperty) {
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -566,20 +566,20 @@ public:
   static nsGlobalWindow* GetOuterWindowWithId(PRUint64 aWindowID) {
     return sOuterWindowsById ? sOuterWindowsById->Get(aWindowID) : nsnull;
   }
 
   static bool HasIndexedDBSupport();
 
 private:
   // Enable updates for the accelerometer.
-  void EnableAccelerationUpdates();
+  void EnableDeviceMotionUpdates();
 
   // Disables updates for the accelerometer.
-  void DisableAccelerationUpdates();
+  void DisableDeviceMotionUpdates();
 
 protected:
   friend class HashchangeCallback;
   friend class nsBarProp;
 
   // Object Management
   virtual ~nsGlobalWindow();
   void CleanUp(PRBool aIgnoreModalDialog);
@@ -884,18 +884,18 @@ protected:
   // when true, show focus rings for the current focused content only.
   // This will be reset when another element is focused
   PRPackedBool           mShowFocusRingForContent : 1;
 
   // true if tab navigation has occurred for this window. Focus rings
   // 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;
 
   nsCOMPtr<nsIScriptContext>    mContext;
   nsWeakPtr                     mOpener;
   nsCOMPtr<nsIControllers>      mControllers;
   nsCOMPtr<nsIArray>            mArguments;
--- a/dom/interfaces/events/Makefile.in
+++ b/dom/interfaces/events/Makefile.in
@@ -75,17 +75,18 @@ XPIDLSRCS =					\
 	nsIDOMMessageEvent.idl			\
 	nsIDOMNotifyPaintEvent.idl              \
 	nsIDOMNotifyAudioAvailableEvent.idl     \
 	nsIDOMPaintRequest.idl			\
 	nsIDOMPaintRequestList.idl		\
 	nsIDOMSimpleGestureEvent.idl		\
 	nsIDOMNSMouseEvent.idl			\
 	nsIDOMMozTouchEvent.idl			\
-	nsIDOMDeviceOrientationEvent.idl			\
+	nsIDOMDeviceOrientationEvent.idl\
+	nsIDOMDeviceMotionEvent.idl		\
 	nsIDOMScrollAreaEvent.idl		\
 	nsIDOMTransitionEvent.idl		\
 	nsIDOMPopStateEvent.idl			\
 	nsIDOMCloseEvent.idl			\
 	nsIDOMEventException.idl		\
 	nsIDOMTouchEvent.idl			\
 	nsIDOMHashChangeEvent.idl		\
 	nsIDOMCustomEvent.idl			\
new file mode 100644
--- /dev/null
+++ b/dom/interfaces/events/nsIDOMDeviceMotionEvent.idl
@@ -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;
+};
+
--- a/dom/interfaces/events/nsIDOMDeviceOrientationEvent.idl
+++ b/dom/interfaces/events/nsIDOMDeviceOrientationEvent.idl
@@ -66,11 +66,10 @@ interface nsIDOMDeviceOrientationEvent :
    * 3) Rotate it by gamma degrees around its Y axis (tilting it sideways, like
    *    rolling an aircraft); gamma is in [-90,90).
    */
 
   readonly attribute double alpha;
   readonly attribute double beta;
   readonly attribute double gamma;
   readonly attribute boolean absolute;
-  readonly attribute boolean compassCalibrated;
 };
 
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -88,17 +88,17 @@
 #include "nsIGeolocationProvider.h"
 #include "mozilla/dom/PMemoryReportRequestChild.h"
 
 #ifdef MOZ_PERMISSIONS
 #include "nsPermission.h"
 #include "nsPermissionManager.h"
 #endif
 
-#include "nsAccelerometer.h"
+#include "nsDeviceMotion.h"
 
 #if defined(ANDROID)
 #include "APKOpen.h"
 #endif
 
 #ifdef XP_WIN
 #include <process.h>
 #define getpid _getpid
@@ -642,24 +642,26 @@ ContentChild::RecvAddPermission(const IP
                                  permission.expireType,
                                  permission.expireTime,
                                  nsPermissionManager::eNotify,
                                  nsPermissionManager::eNoDBOperation);
 #endif
 
   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;
 }
 
 bool
 ContentChild::RecvScreenSizeChanged(const gfxIntSize& size)
 {
 #ifdef ANDROID
     mScreenSize = size;
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -133,17 +133,18 @@ public:
     virtual bool RecvNotifyAlertsObserver(const nsCString& aType, const nsString& aData);
 
     virtual bool RecvAsyncMessage(const nsString& aMsg, const nsString& aJSON);
 
     virtual bool RecvGeolocationUpdate(const GeoPosition& somewhere);
 
     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);
 
     virtual bool RecvFlushMemory(const nsString& reason);
 
 #ifdef ANDROID
     gfxIntSize GetScreenSize() { return mScreenSize; }
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -88,17 +88,17 @@
 #include "nsICrashReporter.h"
 #include "nsExceptionHandler.h"
 #endif
 
 #include "mozilla/dom/ExternalHelperAppParent.h"
 #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"
 #include "mozilla/dom/PMemoryReportRequestParent.h"
 
 #ifdef ANDROID
 #include "gfxAndroidPlatform.h"
 #include "AndroidBridge.h"
@@ -266,17 +266,17 @@ ContentParent::ActorDestroy(ActorDestroy
     // remove the global remote preferences observers
     nsCOMPtr<nsIPrefBranch2> prefs 
             (do_GetService(NS_PREFSERVICE_CONTRACTID));
     if (prefs) { 
         prefs->RemoveObserver("", this);
     }
 
     RecvRemoveGeolocationListener();
-    RecvRemoveAccelerometerListener();
+    RecvRemoveDeviceMotionListener();
 
     nsCOMPtr<nsIThreadInternal>
         threadInt(do_QueryInterface(NS_GetCurrentThread()));
     if (threadInt)
         threadInt->SetObserver(mOldObserver);
     if (mRunToCompletionDepth)
         mRunToCompletionDepth = 0;
 
@@ -1067,32 +1067,32 @@ ContentParent::RecvRemoveGeolocationList
     }
     geo->ClearWatch(mGeolocationWatchID);
     mGeolocationWatchID = -1;
   }
   return true;
 }
 
 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;
 }
 
 NS_IMETHODIMP
 ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
 {
   unused << SendGeolocationUpdate(GeoPosition(postion));
   return NS_OK;
@@ -1129,22 +1129,23 @@ ContentParent::RecvScriptError(const nsS
   if (NS_FAILED(rv))
     return true;
 
   svc->LogMessage(msg);
   return true;
 }
 
 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;
 }
 
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -46,17 +46,17 @@
 #include "mozilla/ipc/GeckoChildProcessHost.h"
 
 #include "nsIObserver.h"
 #include "nsIThreadInternal.h"
 #include "nsNetUtil.h"
 #include "nsIPrefService.h"
 #include "nsIPermissionManager.h"
 #include "nsIDOMGeoPositionCallback.h"
-#include "nsIAccelerometer.h"
+#include "nsIDeviceMotion.h"
 #include "nsIMemoryReporter.h"
 #include "nsCOMArray.h"
 
 namespace mozilla {
 
 namespace ipc {
 class TestShellParent;
 }
@@ -65,17 +65,17 @@ namespace dom {
 
 class TabParent;
 class PStorageParent;
 
 class ContentParent : public PContentParent
                     , public nsIObserver
                     , public nsIThreadObserver
                     , public nsIDOMGeoPositionCallback
-                    , public nsIAccelerationListener
+                    , public nsIDeviceMotionListener
 {
 private:
     typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
     typedef mozilla::ipc::TestShellParent TestShellParent;
 
 public:
     static ContentParent* GetSingleton(PRBool aForceNew = PR_TRUE);
 
@@ -83,17 +83,17 @@ public:
     // TODO: implement this somewhere!
     static ContentParent* FreeSingleton();
 #endif
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
     NS_DECL_NSITHREADOBSERVER
     NS_DECL_NSIDOMGEOPOSITIONCALLBACK
-    NS_DECL_NSIACCELERATIONLISTENER
+    NS_DECL_NSIDEVICEMOTIONLISTENER
 
     TabParent* CreateTab(PRUint32 aChromeFlags);
 
     TestShellParent* CreateTestShell();
     bool DestroyTestShell(TestShellParent* aTestShell);
 
     void ReportChildAlreadyBlocked();
     bool RequestRunToCompletion();
@@ -195,18 +195,18 @@ private:
     virtual bool RecvLoadURIExternal(const IPC::URI& uri);
 
     virtual bool RecvSyncMessage(const nsString& aMsg, const nsString& aJSON,
                                  InfallibleTArray<nsString>* aRetvals);
     virtual bool RecvAsyncMessage(const nsString& aMsg, const nsString& aJSON);
 
     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,
                                  const nsString& aSourceName,
                                  const nsString& aSourceLine,
                                  const PRUint32& aLineNumber,
                                  const PRUint32& aColNumber,
                                  const PRUint32& aFlags,
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -118,17 +118,17 @@ child:
 
     NotifyAlertsObserver(nsCString topic, nsString data);
 
     GeolocationUpdate(GeoPosition somewhere);
 
     // nsIPermissionManager messages
     AddPermission(Permission permission);
 
-    AccelerationChanged(double x, double y, double z);
+    DeviceMotionChanged(long type, double x, double y, double z);
 
     ScreenSizeChanged(gfxIntSize size);
 
     FlushMemory(nsString reason);
 
 parent:
     PNecko();
     PCrashReporter();
@@ -167,18 +167,18 @@ parent:
                           nsString name);
 
     PExternalHelperApp(URI uri, nsCString aMimeContentType,
                        nsCString aContentDisposition, bool aForceSave,
                        PRInt64 aContentLength, URI aReferrer);
     
     AddGeolocationListener();
     RemoveGeolocationListener();
-    AddAccelerometerListener();
-    RemoveAccelerometerListener();
+    AddDeviceMotionListener();
+    RemoveDeviceMotionListener();
 
     ConsoleMessage(nsString message);
     ScriptError(nsString message, nsString sourceName, nsString sourceLine,
                 PRUint32 lineNumber, PRUint32 colNumber, PRUint32 flags,
                 nsCString category); 
 
     // nsIPermissionManager messages
     sync ReadPermissions() returns (Permission[] permissions);
--- a/dom/system/Makefile.in
+++ b/dom/system/Makefile.in
@@ -57,32 +57,35 @@ ifneq (,$(filter cocoa,$(MOZ_WIDGET_TOOL
 DIRS = cocoa
 endif
 
 ifneq (,$(filter android,$(MOZ_WIDGET_TOOLKIT)))
 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))
 EXTRA_COMPONENTS = \
   NetworkGeolocationProvider.js \
   NetworkGeolocationProvider.manifest \
   GPSDGeolocationProvider.js \
   GPSDGeolocationProvider.manifest \
   $(NULL)
 endif
 
 EXPORTS     = \
-  nsAccelerometer.h \
+  nsDeviceMotion.h \
   $(NULL)
 
 include $(topsrcdir)/config/config.mk
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 EXPORT_LIBRARY = 1
--- a/dom/system/android/Makefile.in
+++ b/dom/system/android/Makefile.in
@@ -48,17 +48,17 @@ LIBRARY_NAME    = domsystemandroid_s
 LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 EXPORT_LIBRARY = 1
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 
 CPPSRCS     = \
-        nsAccelerometerSystem.cpp \
+        nsDeviceMotionSystem.cpp \
         AndroidLocationProvider.cpp \
         nsHapticFeedback.cpp \
         $(NULL)
 
 LOCAL_INCLUDES  += -I$(topsrcdir)/dom/src/geolocation \
                      $(NULL)
 
 include $(topsrcdir)/config/rules.mk
rename from dom/system/android/nsAccelerometerSystem.cpp
rename to dom/system/android/nsDeviceMotionSystem.cpp
--- a/dom/system/android/nsAccelerometerSystem.cpp
+++ b/dom/system/android/nsDeviceMotionSystem.cpp
@@ -31,43 +31,43 @@
  * 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 "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();
 }
rename from dom/system/android/nsAccelerometerSystem.h
rename to dom/system/android/nsDeviceMotionSystem.h
--- a/dom/system/android/nsAccelerometerSystem.h
+++ b/dom/system/android/nsDeviceMotionSystem.h
@@ -29,26 +29,26 @@
  * 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 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 */
 
--- a/dom/system/cocoa/Makefile.in
+++ b/dom/system/cocoa/Makefile.in
@@ -47,12 +47,12 @@ LIBRARY_NAME    = domsystemcocoa_s
 # we don't want the shared lib, but we want to force the creation of a static lib.
 LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 EXPORT_LIBRARY = 1
 
 include $(topsrcdir)/config/config.mk
 
 CMMSRCS     = \
-        nsAccelerometerSystem.mm \
+        nsDeviceMotionSystem.mm \
         $(NULL)
 
 include $(topsrcdir)/config/rules.mk
rename from dom/system/cocoa/nsAccelerometerSystem.h
rename to dom/system/cocoa/nsDeviceMotionSystem.h
--- a/dom/system/cocoa/nsAccelerometerSystem.h
+++ b/dom/system/cocoa/nsDeviceMotionSystem.h
@@ -29,29 +29,29 @@
  * 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 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();
 
   io_connect_t mSmsConnection;
   nsCOMPtr<nsITimer> mUpdateTimer;
   static void UpdateHandler(nsITimer *aTimer, void *aClosure);
 };
rename from dom/system/cocoa/nsAccelerometerSystem.mm
rename to dom/system/cocoa/nsDeviceMotionSystem.mm
--- a/dom/system/cocoa/nsAccelerometerSystem.mm
+++ b/dom/system/cocoa/nsDeviceMotionSystem.mm
@@ -29,32 +29,32 @@
  * 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 "nsAccelerometerSystem.h"
+#include "nsDeviceMotionSystem.h"
 #include "nsIServiceManager.h"
 #include "stdlib.h"
 
 #include <sys/sysctl.h>
 #include <sys/resource.h>
 #include <sys/vm.h>
 
 #define MODEL_NAME_LENGTH 64
 static char gModelName[MODEL_NAME_LENGTH];
 
-nsAccelerometerSystem::nsAccelerometerSystem()
+nsDeviceMotionSystem::nsDeviceMotionSystem()
 {
 }
 
-nsAccelerometerSystem::~nsAccelerometerSystem()
+nsDeviceMotionSystem::~nsDeviceMotionSystem()
 {
 }
 
 // Data format returned from IOConnectMethodStructureIStructureO.
 // I am not sure what the other bits in this structure are,
 // or if there are any, but this has to be 40 bytes long or
 // the call to read fails.
 //
@@ -67,19 +67,19 @@ typedef struct
   PRInt16 x;
   PRInt16 y;
   PRInt16 z;
   PRInt8  unknown[SMSDATA_PADDING_SIZE];
 } SmsData;
 #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;
   }
 
   size_t bufferLen = sizeof(SmsData);
 
   void * input = malloc(bufferLen);
@@ -138,20 +138,20 @@ nsAccelerometerSystem::UpdateHandler(nsI
     xf = (((float)data->x) / normalizeFactor) * -1;
     yf = ((float)data->y) / normalizeFactor;
     zf = ((float)data->z) / normalizeFactor;
   }
 
   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.
 
   mach_port_t port;
   kern_return_t result = ::IOMasterPort(MACH_PORT_NULL, &port);
   if (result != kIOReturnSuccess)
     return;
 
@@ -189,17 +189,17 @@ void nsAccelerometerSystem::Startup()
   mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
   if (mUpdateTimer)
     mUpdateTimer->InitWithFuncCallback(UpdateHandler,
                                        this,
                                        mUpdateInterval,
                                        nsITimer::TYPE_REPEATING_SLACK);
 }
 
-void nsAccelerometerSystem::Shutdown()
+void nsDeviceMotionSystem::Shutdown()
 {
   if (mSmsConnection)
     ::IOServiceClose(mSmsConnection);
 
   if (mUpdateTimer) {
     mUpdateTimer->Cancel();
     mUpdateTimer = nsnull;
   }
rename from dom/system/nsAccelerometer.cpp
rename to dom/system/nsDeviceMotion.cpp
--- a/dom/system/nsAccelerometer.cpp
+++ b/dom/system/nsDeviceMotion.cpp
@@ -29,259 +29,288 @@
  * 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 "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 nsAcceleration : public nsIAcceleration
+class nsDeviceMotionData : public nsIDeviceMotionData
 {
 public:
   NS_DECL_ISUPPORTS
-  NS_DECL_NSIACCELERATION
+  NS_DECL_NSIDEVICEMOTIONDATA
 
-  nsAcceleration(double alpha, double beta, double gamma);
+  nsDeviceMotionData(unsigned long type, double x, double y, double z);
 
 private:
-  ~nsAcceleration();
+  ~nsDeviceMotionData();
 
 protected:
-  /* additional members */
-  double mAlpha, mBeta, mGamma;
+  unsigned long mType;
+  double mX, mY, mZ;
 };
 
-/* Implementation file */
-NS_IMPL_ISUPPORTS1(nsAcceleration, nsIAcceleration)
-
-nsAcceleration::nsAcceleration(double alpha, double beta, double gamma)
-:mAlpha(alpha), mBeta(beta), mGamma(gamma)
+nsDeviceMotionData::nsDeviceMotionData(unsigned long type, double x, double y, double z)
+  : mType(type), mX(x), mY(y), mZ(z)
 {
 }
 
-nsAcceleration::~nsAcceleration()
+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 nsAcceleration::GetAlpha(double *aAlpha)
+NS_IMETHODIMP nsDeviceMotionData::GetType(PRUint32 *aType)
 {
-  NS_ENSURE_ARG_POINTER(aAlpha);
-  *aAlpha = mAlpha;
+  NS_ENSURE_ARG_POINTER(aType);
+  *aType = mType;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsAcceleration::GetBeta(double *aBeta)
+NS_IMETHODIMP nsDeviceMotionData::GetX(double *aX)
 {
-  NS_ENSURE_ARG_POINTER(aBeta);
-  *aBeta = mBeta;
+  NS_ENSURE_ARG_POINTER(aX);
+  *aX = mX;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsAcceleration::GetGamma(double *aGamma)
+NS_IMETHODIMP nsDeviceMotionData::GetY(double *aY)
 {
-  NS_ENSURE_ARG_POINTER(aGamma);
-  *aGamma = mGamma;
+  NS_ENSURE_ARG_POINTER(aY);
+  *aY = mY;
   return NS_OK;
 }
 
-NS_IMPL_ISUPPORTS2(nsAccelerometer, nsIAccelerometer, nsIAccelerometerUpdate)
+NS_IMETHODIMP nsDeviceMotionData::GetZ(double *aZ)
+{
+  NS_ENSURE_ARG_POINTER(aZ);
+  *aZ = mZ;
+  return NS_OK;
+}
 
-nsAccelerometer::nsAccelerometer()
-: mLastAlpha(-200), /* initialize to values that can't be possible */
-  mLastBeta(-200),
-  mLastGamma(-200),
-  mStarted(PR_FALSE),
-  mNewListener(PR_FALSE),
+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("accelerometer.update.interval", &value);
+    nsresult rv = prefSrv->GetIntPref("device.motion.update.interval", &value);
     if (NS_SUCCEEDED(rv))
       mUpdateInterval = value;
 
     PRBool bvalue;
-    rv = prefSrv->GetBoolPref("accelerometer.enabled", &bvalue);
+    rv = prefSrv->GetBoolPref("device.motion.enabled", &bvalue);
     if (NS_SUCCEEDED(rv) && bvalue == PR_FALSE)
       mEnabled = PR_FALSE;
   }
 }
 
-nsAccelerometer::~nsAccelerometer()
+nsDeviceMotion::~nsDeviceMotion()
 {
   if (mTimeoutTimer)
     mTimeoutTimer->Cancel();
 }
 
 void
-nsAccelerometer::StartDisconnectTimer()
+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
-nsAccelerometer::TimeoutHandler(nsITimer *aTimer, void *aClosure)
+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.
-  nsAccelerometer *self = reinterpret_cast<nsAccelerometer *>(aClosure);
+  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 nsAccelerometer::AddListener(nsIAccelerationListener *aListener)
+NS_IMETHODIMP nsDeviceMotion::AddListener(nsIDeviceMotionListener *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)
+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 nsAccelerometer::AddWindowListener(nsIDOMWindow *aWindow)
+NS_IMETHODIMP nsDeviceMotion::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)
+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
-nsAccelerometer::AccelerationChanged(double alpha, double beta, double gamma)
+nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
 {
   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);
+    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));
 
-    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);
-      }
+      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);
+}
+
rename from dom/system/nsAccelerometer.h
rename to dom/system/nsDeviceMotion.h
--- a/dom/system/nsAccelerometer.h
+++ b/dom/system/nsDeviceMotion.h
@@ -29,61 +29,69 @@
  * 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 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
-
-  nsAccelerometer();
+  NS_DECL_NSIDEVICEMOTION
+  NS_DECL_NSIDEVICEMOTIONUPDATE
 
-  virtual ~nsAccelerometer();
+  nsDeviceMotion();
 
-  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;
 
   virtual void Startup()  = 0;
   virtual void Shutdown() = 0;
 };
 
 #endif
--- a/dom/system/unix/Makefile.in
+++ b/dom/system/unix/Makefile.in
@@ -47,17 +47,17 @@ LIBRARY_NAME    = domsystemunix_s
 # we don't want the shared lib, but we want to force the creation of a static lib.
 LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 EXPORT_LIBRARY = 1
 
 include $(topsrcdir)/config/config.mk
 
 CPPSRCS     = \
-        nsAccelerometerSystem.cpp \
+        nsDeviceMotionSystem.cpp \
         $(NULL)
 
 ifdef MOZ_MAEMO_LIBLOCATION
         CPPSRCS         += MaemoLocationProvider.cpp
         LOCAL_INCLUDES  += $(MOZ_PLATFORM_MAEMO_CFLAGS) \
                            -I$(topsrcdir)/dom/src/geolocation \
                            $(NULL)
 endif
rename from dom/system/unix/nsAccelerometerSystem.cpp
rename to dom/system/unix/nsDeviceMotionSystem.cpp
--- a/dom/system/unix/nsAccelerometerSystem.cpp
+++ b/dom/system/unix/nsDeviceMotionSystem.cpp
@@ -31,26 +31,26 @@
  * 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 <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",
    eAppleSensor},
   // Thinkpad
   {"/sys/devices/platform/hdaps/position",
    "/sys/devices/platform/hdaps/calibrate",
    eIBMSensor},
@@ -59,31 +59,31 @@ static const Accelerometer gAcceleromete
    NULL,
    eMaemoSensor},
   // HP Pavilion dv7
   {"/sys/devices/platform/lis3lv02d/position",
    "/sys/devices/platform/lis3lv02d/calibrate",
    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;
   }
 
   float xf, yf, zf;
 
   switch (self->mType) {
@@ -182,30 +182,30 @@ nsAccelerometerSystem::UpdateHandler(nsI
       break;
     }
 
     case eNoSensor:
     default:
       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;
         return;
       }
     }
 
     break;
@@ -217,17 +217,17 @@ void nsAccelerometerSystem::Startup()
   mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
   if (mUpdateTimer)
     mUpdateTimer->InitWithFuncCallback(UpdateHandler,
                                        this,
                                        mUpdateInterval,
                                        nsITimer::TYPE_REPEATING_SLACK);
 }
 
-void nsAccelerometerSystem::Shutdown()
+void nsDeviceMotionSystem::Shutdown()
 {
   if (mPositionFile) {
     fclose(mPositionFile);
     mPositionFile = nsnull;
   }
 
   // Fun fact: writing to the calibrate file causes the
   // driver to re-calibrate the accelerometer
rename from dom/system/unix/nsAccelerometerSystem.h
rename to dom/system/unix/nsDeviceMotionSystem.h
--- a/dom/system/unix/nsAccelerometerSystem.h
+++ b/dom/system/unix/nsDeviceMotionSystem.h
@@ -30,41 +30,41 @@
  * 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 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,
   eIBMSensor,
   eMaemoSensor,
   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);
 };
 
 #endif
--- a/dom/system/windows/Makefile.in
+++ b/dom/system/windows/Makefile.in
@@ -47,12 +47,12 @@ LIBRARY_NAME    = domsystemwindows_s
 # we don't want the shared lib, but we want to force the creation of a static lib.
 LIBXUL_LIBRARY   = 1
 FORCE_STATIC_LIB = 1
 EXPORT_LIBRARY = 1
 
 include $(topsrcdir)/config/config.mk
 
 CPPSRCS     = \
-        nsAccelerometerSystem.cpp \
+        nsDeviceMotionSystem.cpp \
         $(NULL)
 
 include $(topsrcdir)/config/rules.mk
rename from dom/system/windows/nsAccelerometerSystem.cpp
rename to dom/system/windows/nsDeviceMotionSystem.cpp
--- a/dom/system/windows/nsAccelerometerSystem.cpp
+++ b/dom/system/windows/nsDeviceMotionSystem.cpp
@@ -30,38 +30,38 @@
  * 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 "nsAccelerometerSystem.h"
+#include "nsDeviceMotionSystem.h"
 #include "nsIServiceManager.h"
 #include "windows.h"
 
 ////////////////////////////
 // ThinkPad
 ////////////////////////////
 
 typedef struct {
   int status; // Current internal state
   unsigned short x; // raw value
   unsigned short y; // raw value
   unsigned short xx; // avg. of 40ms
   unsigned short yy; // avg. of 40ms
   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
 {
 public:
   ThinkPadSensor();
   ~ThinkPadSensor();
   PRBool Startup();
   void Shutdown();
@@ -80,67 +80,67 @@ ThinkPadSensor::~ThinkPadSensor()
 
 PRBool
 ThinkPadSensor::Startup()
 {
   mLibrary = LoadLibraryW(L"sensor.dll");
   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;
   }
   return PR_TRUE;
 }
 
 void
 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.
   // Balance point (526, 528) and 90 degree tilt (144) determined experimentally.
   *x = ((double)(accelData.y - 526)) / 144;
   *y = ((double)(accelData.x - 528)) / 144;
   *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?");
 
   PRBool started = PR_FALSE;
 
   mSensor = new ThinkPadSensor();
   if (mSensor)
     started = mSensor->Startup();
@@ -151,17 +151,17 @@ void nsAccelerometerSystem::Startup()
   mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1");
   if (mUpdateTimer)
     mUpdateTimer->InitWithFuncCallback(UpdateHandler,
                                        this,
                                        mUpdateInterval,
                                        nsITimer::TYPE_REPEATING_SLACK);
 }
 
-void nsAccelerometerSystem::Shutdown()
+void nsDeviceMotionSystem::Shutdown()
 {
   if (mUpdateTimer) {
     mUpdateTimer->Cancel();
     mUpdateTimer = nsnull;
   }
 
   if (mSensor)
     mSensor->Shutdown();
rename from dom/system/windows/nsAccelerometerSystem.h
rename to dom/system/windows/nsDeviceMotionSystem.h
--- a/dom/system/windows/nsAccelerometerSystem.h
+++ b/dom/system/windows/nsDeviceMotionSystem.h
@@ -29,35 +29,35 @@
  * 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 nsAccelerometerSystem_h
-#define nsAccelerometerSystem_h
+#ifndef nsDeviceMotionSystem_h
+#define nsDeviceMotionSystem_h
 
-#include "nsAccelerometer.h"
+#include "nsDeviceMotion.h"
 #include "nsAutoPtr.h"
 
 class Sensor
 {
  public:
   virtual PRBool Startup() = 0;
   virtual void Shutdown()  = 0;
   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();
 
   nsCOMPtr<nsITimer> mUpdateTimer;
   static void UpdateHandler(nsITimer *aTimer, void *aClosure);
 
   nsAutoPtr<Sensor> mSensor;
--- a/embedding/android/GeckoAppShell.java
+++ b/embedding/android/GeckoAppShell.java
@@ -574,28 +574,39 @@ public class GeckoAppShell
 
     // Signal the Java thread that it's time to wake up
     public static void acknowledgeEventSync() {
         CountDownLatch tmp = sGeckoPendingAcks;
         if (tmp != null)
             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 (gAccelerometerSensor == null || gOrientationSensor == null) {
+            gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
+            gOrientationSensor   = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
+        }
+
         if (enable) {
-            Sensor accelSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
-            if (accelSensor == null)
-                return;
-
-            sm.registerListener(GeckoApp.surfaceView, accelSensor, SensorManager.SENSOR_DELAY_GAME);
+            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);
         }
     }
 
     public static void enableLocation(final boolean enable) {
      
         getMainHandler().post(new Runnable() { 
                 public void run() {
                     GeckoSurfaceView view = GeckoApp.surfaceView;
--- a/embedding/android/GeckoEvent.java
+++ b/embedding/android/GeckoEvent.java
@@ -54,28 +54,29 @@ import android.util.Log;
  * Fields have different meanings depending on the event type.
  */
 
 public class GeckoEvent {
     public static final int INVALID = -1;
     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;
     public static final int IME_SET_TEXT = 2;
     public static final int IME_GET_TEXT = 3;
     public static final int IME_DELETE_TEXT = 4;
     public static final int IME_SET_SELECTION = 5;
     public static final int IME_GET_SELECTION = 6;
@@ -91,16 +92,17 @@ public class GeckoEvent {
     public static final int IME_RANGE_FORECOLOR = 2;
     public static final int IME_RANGE_BACKCOLOR = 4;
 
     public int mType;
     public int mAction;
     public long mTime;
     public Point mP0, mP1;
     public Rect mRect;
+    public double mX, mY, mZ;
     public double mAlpha, mBeta, mGamma;
 
     public int mMetaState, mFlags;
     public int mKeyCode, mUnicodeChar;
     public int mOffset, mCount;
     public String mCharacters;
     public int mRangeType, mRangeStyles;
     public int mRangeForeColor, mRangeBackColor;
@@ -135,28 +137,30 @@ public class GeckoEvent {
         mMetaState = m.getMetaState();
         mP0 = new Point((int)m.getX(0), (int)m.getY(0));
         mCount = m.getPointerCount();
         if (mCount > 1)
             mP1 = new Point((int)m.getX(1), (int)m.getY(1));
     }
 
     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) {
         mType = LOCATION_EVENT;
         mLocation = l;
         mAddress  = a;
     }
 
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -284,17 +284,17 @@ static void Shutdown();
 #include "nsIXMLContentBuilder.h"
 #endif
 
 #include "nsGeolocation.h"
 #if defined(XP_UNIX)    || \
     defined(_WINDOWS)   || \
     defined(machintosh) || \
     defined(android)
-#include "nsAccelerometerSystem.h"
+#include "nsDeviceMotionSystem.h"
 #endif
 #include "nsCSPService.h"
 
 // Transformiix
 /* 5d5d92cd-6bf8-11d9-bf4a-000a95dc234c */
 #define TRANSFORMIIX_NODESET_CID \
 { 0x5d5d92cd, 0x6bf8, 0x11d9, { 0xbf, 0x4a, 0x0, 0x0a, 0x95, 0xdc, 0x23, 0x4c } }
 
@@ -317,17 +317,17 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR
                                          nsDOMStorageManager::GetInstance)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsChannelPolicy)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(IndexedDatabaseManager,
                                          IndexedDatabaseManager::FactoryCreate)
 #if defined(XP_UNIX)    || \
     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)
 #if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHapticFeedback)
 #endif
 
 //-----------------------------------------------------------------------------
@@ -867,17 +867,17 @@ NS_DEFINE_NAMED_CID(NS_SECURITYNAMESET_C
 NS_DEFINE_NAMED_CID(THIRDPARTYUTIL_CID);
 NS_DEFINE_NAMED_CID(NS_WORKERFACTORY_CID);
 NS_DEFINE_NAMED_CID(NS_STRUCTUREDCLONECONTAINER_CID);
 
 #if defined(XP_UNIX)    || \
     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);
 #endif
 
 static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
   XPCONNECT_CIDENTRIES
 #ifdef DEBUG
@@ -1008,17 +1008,17 @@ static const mozilla::Module::CIDEntry k
   { &kNS_PRINCIPAL_CID, false, NULL, nsPrincipalConstructor },
   { &kNS_SYSTEMPRINCIPAL_CID, false, NULL, nsSystemPrincipalConstructor },
   { &kNS_NULLPRINCIPAL_CID, false, NULL, nsNullPrincipalConstructor },
   { &kNS_SECURITYNAMESET_CID, false, NULL, nsSecurityNameSetConstructor },
 #if defined(XP_UNIX)    || \
     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 },
 #endif
   { &kTHIRDPARTYUTIL_CID, false, NULL, ThirdPartyUtilConstructor },
   { &kNS_WORKERFACTORY_CID, false, NULL, nsWorkerFactoryConstructor },
   { &kNS_STRUCTUREDCLONECONTAINER_CID, false, NULL, nsStructuredCloneContainerConstructor },
   { NULL }
@@ -1145,17 +1145,17 @@ static const mozilla::Module::ContractID
   { NS_PRINCIPAL_CONTRACTID, &kNS_PRINCIPAL_CID },
   { NS_SYSTEMPRINCIPAL_CONTRACTID, &kNS_SYSTEMPRINCIPAL_CID },
   { NS_NULLPRINCIPAL_CONTRACTID, &kNS_NULLPRINCIPAL_CID },
   { NS_SECURITYNAMESET_CONTRACTID, &kNS_SECURITYNAMESET_CID },
 #if defined(XP_UNIX)    || \
     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 },
 #endif
   { THIRDPARTYUTIL_CONTRACTID, &kTHIRDPARTYUTIL_CID },
   { NS_WORKERFACTORY_CONTRACTID, &kNS_WORKERFACTORY_CID },
   { NS_STRUCTUREDCLONECONTAINER_CONTRACTID, &kNS_STRUCTUREDCLONECONTAINER_CID },
   { NULL }
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -3199,17 +3199,17 @@ pref("gfx.direct2d.force-enabled", false
 pref("layers.prefer-opengl", false);
 pref("layers.prefer-d3d9", false);
 #endif
 
 // Enable/Disable the geolocation API for content
 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);
 // Toggle which thread the HTML5 parser uses for stream parsing
 pref("html5.offmainthread", true);
 // Time in milliseconds between the time a network buffer is seen and the 
 // timer firing when the timer hasn't fired previously in this parse in the 
 // off-the-main-thread HTML5 parser.
--- a/widget/src/android/AndroidBridge.cpp
+++ b/widget/src/android/AndroidBridge.cpp
@@ -110,17 +110,17 @@ AndroidBridge::Init(JNIEnv *jEnv,
 
     mGeckoAppShellClass = (jclass) jEnv->NewGlobalRef(jGeckoAppShellClass);
 
     jNotifyIME = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIME", "(II)V");
     jNotifyIMEEnabled = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIMEEnabled", "(ILjava/lang/String;Ljava/lang/String;Z)V");
     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");
     jNotifyAppShellReady = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onAppShellReady", "()V");
     jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V");
     jGetHandlersForMimeType = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getHandlersForMimeType", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;");
     jGetHandlersForURL = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getHandlersForURL", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;");
     jOpenUriExternal = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "openUriExternal", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z");
@@ -298,20 +298,20 @@ AndroidBridge::NotifyIMEChange(const PRU
 void
 AndroidBridge::AcknowledgeEventSync()
 {
     ALOG_BRIDGE("AndroidBridge::AcknowledgeEventSync");
     mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jAcknowledgeEventSync);
 }
 
 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
 AndroidBridge::EnableLocation(bool aEnable)
 {
     ALOG_BRIDGE("AndroidBridge::EnableLocation");
     mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable);
 }
--- a/widget/src/android/AndroidBridge.h
+++ b/widget/src/android/AndroidBridge.h
@@ -125,17 +125,17 @@ public:
 
     static void NotifyIMEEnabled(int aState, const nsAString& aTypeHint,
                                  const nsAString& aActionHint);
 
     static void NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen, int aStart, int aEnd, int aNewEnd);
 
     void AcknowledgeEventSync();
 
-    void EnableAccelerometer(bool aEnable);
+    void EnableDeviceMotion(bool aEnable);
 
     void EnableLocation(bool aEnable);
 
     void ReturnIMEQueryResult(const PRUnichar *aResult, PRUint32 aLen, int aSelStart, int aSelLen);
 
     void NotifyAppShellReady();
 
     void NotifyXreExit();
@@ -278,17 +278,17 @@ protected:
     bool mOpenedBitmapLibrary;
     bool mHasNativeBitmapAccess;
 
     // other things
     jmethodID jNotifyIME;
     jmethodID jNotifyIMEEnabled;
     jmethodID jNotifyIMEChange;
     jmethodID jAcknowledgeEventSync;
-    jmethodID jEnableAccelerometer;
+    jmethodID jEnableDeviceMotion;
     jmethodID jEnableLocation;
     jmethodID jReturnIMEQueryResult;
     jmethodID jNotifyAppShellReady;
     jmethodID jNotifyXreExit;
     jmethodID jScheduleRestart;
     jmethodID jGetOutstandingDrawEvents;
     jmethodID jGetHandlersForMimeType;
     jmethodID jGetHandlersForURL;
--- a/widget/src/android/AndroidJavaWrappers.cpp
+++ b/widget/src/android/AndroidJavaWrappers.cpp
@@ -44,16 +44,19 @@ jclass AndroidGeckoEvent::jGeckoEventCla
 jfieldID AndroidGeckoEvent::jActionField = 0;
 jfieldID AndroidGeckoEvent::jTypeField = 0;
 jfieldID AndroidGeckoEvent::jTimeField = 0;
 jfieldID AndroidGeckoEvent::jP0Field = 0;
 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;
 
 jfieldID AndroidGeckoEvent::jCharactersField = 0;
 jfieldID AndroidGeckoEvent::jKeyCodeField = 0;
 jfieldID AndroidGeckoEvent::jMetaStateField = 0;
 jfieldID AndroidGeckoEvent::jFlagsField = 0;
 jfieldID AndroidGeckoEvent::jUnicodeCharField = 0;
@@ -142,16 +145,19 @@ AndroidGeckoEvent::InitGeckoEventClass(J
     jActionField = getField("mAction", "I");
     jTypeField = getField("mType", "I");
     jTimeField = getField("mTime", "J");
     jP0Field = getField("mP0", "Landroid/graphics/Point;");
     jP1Field = getField("mP1", "Landroid/graphics/Point;");
     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;");
     jKeyCodeField = getField("mKeyCode", "I");
     jMetaStateField = getField("mMetaState", "I");
     jFlagsField = getField("mFlags", "I");
     jUnicodeCharField = getField("mUnicodeChar", "I");
     jOffsetField = getField("mOffset", "I");
@@ -397,22 +403,28 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jo
                     jenv->GetIntField(jobj, jRangeBackColorField);
             }
             break;
 
         case DRAW:
             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);
 
             mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location);
             if (address)
                 mGeoAddress = AndroidAddress::CreateGeoPositionAddress(jenv, address);
             break;
--- a/widget/src/android/AndroidJavaWrappers.h
+++ b/widget/src/android/AndroidJavaWrappers.h
@@ -394,16 +394,19 @@ public:
     int Action() { return mAction; }
     int Type() { return mType; }
     int64_t Time() { return mTime; }
     const nsIntPoint& P0() { return mP0; }
     const nsIntPoint& P1() { return mP1; }
     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; }
     int MetaState() { return mMetaState; }
     int Flags() { return mFlags; }
     int UnicodeChar() { return mUnicodeChar; }
     int Offset() { return mOffset; }
     int Count() { return mCount; }
@@ -422,16 +425,17 @@ protected:
     nsIntPoint mP1;
     nsIntRect mRect;
     int mFlags, mMetaState;
     int mKeyCode, mUnicodeChar;
     int mOffset, mCount;
     int mRangeType, mRangeStyles;
     int mRangeForeColor, mRangeBackColor;
     double mAlpha, mBeta, mGamma;
+    double mX, mY, mZ;
     nsString mCharacters;
     nsRefPtr<nsGeoPosition> mGeoPosition;
     nsRefPtr<nsGeoPositionAddress> mGeoAddress;
 
     void ReadP0Field(JNIEnv *jenv);
     void ReadP1Field(JNIEnv *jenv);
     void ReadRectField(JNIEnv *jenv);
     void ReadCharactersField(JNIEnv *jenv);
@@ -440,16 +444,19 @@ protected:
     static jfieldID jActionField;
     static jfieldID jTypeField;
     static jfieldID jTimeField;
     static jfieldID jP0Field;
     static jfieldID jP1Field;
     static jfieldID jAlphaField;
     static jfieldID jBetaField;
     static jfieldID jGammaField;
+    static jfieldID jXField;
+    static jfieldID jYField;
+    static jfieldID jZField;
     static jfieldID jRectField;
     static jfieldID jNativeWindowField;
 
     static jfieldID jCharactersField;
     static jfieldID jKeyCodeField;
     static jfieldID jMetaStateField;
     static jfieldID jFlagsField;
     static jfieldID jOffsetField;
@@ -462,28 +469,29 @@ protected:
     static jfieldID jLocationField;
     static jfieldID jAddressField;
 
 public:
     enum {
         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
     };
 
     enum {
         IME_COMPOSITION_END = 0,
         IME_COMPOSITION_BEGIN = 1,
         IME_SET_TEXT = 2,
         IME_GET_TEXT = 3,
--- a/widget/src/android/nsAppShell.cpp
+++ b/widget/src/android/nsAppShell.cpp
@@ -45,17 +45,17 @@
 #include "nsIGeolocationProvider.h"
 
 #include "mozilla/Services.h"
 #include "mozilla/unused.h"
 #include "mozilla/Preferences.h"
 #include "prenv.h"
 
 #include "AndroidBridge.h"
-#include "nsAccelerometerSystem.h"
+#include "nsDeviceMotionSystem.h"
 #include <android/log.h>
 #include <pthread.h>
 #include <wchar.h>
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG
 #include "prlog.h"
 #endif
@@ -67,17 +67,17 @@
 #endif
 
 using namespace mozilla;
 
 #ifdef PR_LOGGING
 PRLogModuleInfo *gWidgetLog = nsnull;
 #endif
 
-nsAccelerometerSystem *gAccel = nsnull;
+nsDeviceMotionSystem *gDeviceMotionSystem = nsnull;
 nsIGeolocationUpdate *gLocationCallback = nsnull;
 
 nsAppShell *nsAppShell::gAppShell = nsnull;
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver)
 
 nsAppShell::nsAppShell()
     : mQueueLock("nsAppShell.mQueueLock"),
@@ -287,18 +287,28 @@ nsAppShell::ProcessNextNativeEvent(PRBoo
 
     EVLOG("nsAppShell: event %p %d [ndraws %d]", (void*)curEvent.get(), curEvent->Type(), mNumDraws);
 
     switch (curEvent->Type()) {
     case AndroidGeckoEvent::NATIVE_POKE:
         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: {
         if (!gLocationCallback)
             break;
 
         nsGeoPosition* p = curEvent->GeoPosition();
         nsGeoPositionAddress* a = curEvent->GeoAddress();
--- a/xpcom/system/Makefile.in
+++ b/xpcom/system/Makefile.in
@@ -48,17 +48,17 @@ XPIDL_MODULE    = xpcom_system
 XPIDLSRCS = \
         nsIXULAppInfo.idl \
         nsIXULRuntime.idl \
         nsIGConfService.idl \
         nsIGnomeVFSService.idl \
         nsIBlocklistService.idl \
         nsIGIOService.idl \
         nsIGSettingsService.idl \
-        nsIAccelerometer.idl \
+        nsIDeviceMotion.idl \
         nsIGeolocationProvider.idl \
         nsIHapticFeedback.idl \
         $(NULL)
 
 ifdef MOZ_CRASHREPORTER
 XPIDLSRCS += nsICrashReporter.idl
 endif
 
rename from xpcom/system/nsIAccelerometer.idl
rename to xpcom/system/nsIDeviceMotion.idl
--- a/xpcom/system/nsIAccelerometer.idl
+++ b/xpcom/system/nsIDeviceMotion.idl
@@ -33,42 +33,47 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 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);
 
 };
 
 /* 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);
 };