From 3448500e153514199116d99befbd09aea8b31723 Mon Sep 17 00:00:00 2001 From: Eugen Sawin Date: Thu, 17 Dec 2015 21:49:44 +0100 Subject: [PATCH] Bug 1205649 - [1.1] Use relative orientation for DOM DeviceOrientation events by default. r=vlad --- dom/events/EventListenerManager.cpp | 4 +++- dom/system/nsDeviceSensors.cpp | 20 ++++++++++++++++---- dom/system/nsDeviceSensors.h | 7 ++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 0a400e99221..0537e892a38 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -456,7 +456,9 @@ EventListenerManager::EnableDevice(EventMessage aEventMessage) switch (aEventMessage) { case eDeviceOrientation: #ifdef MOZ_WIDGET_ANDROID - window->EnableDeviceSensor(SENSOR_ROTATION_VECTOR); + // Falls back to SENSOR_ROTATION_VECTOR and SENSOR_ORIENTATION if + // unavailable on device. + window->EnableDeviceSensor(SENSOR_GAME_ROTATION_VECTOR); #else window->EnableDeviceSensor(SENSOR_ORIENTATION); #endif diff --git a/dom/system/nsDeviceSensors.cpp b/dom/system/nsDeviceSensors.cpp index 2093d7978cb..a54363b35c3 100644 --- a/dom/system/nsDeviceSensors.cpp +++ b/dom/system/nsDeviceSensors.cpp @@ -198,6 +198,12 @@ WindowCannotReceiveSensorEvent (nsPIDOMWindow* aWindow) // Holds the device orientation in Euler angle degrees (azimuth, pitch, roll). struct Orientation { + enum OrientationReference + { + kRelative = 0, + kAbsolute + }; + static Orientation RadToDeg(const Orientation& aOrient) { const static double kRadToDeg = 180.0 / M_PI; @@ -282,10 +288,15 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) type == nsIDeviceSensorData::TYPE_GYROSCOPE) { FireDOMMotionEvent(domDoc, target, type, x, y, z); } else if (type == nsIDeviceSensorData::TYPE_ORIENTATION) { - FireDOMOrientationEvent(target, x, y, z); + FireDOMOrientationEvent(target, x, y, z, Orientation::kAbsolute); } else if (type == nsIDeviceSensorData::TYPE_ROTATION_VECTOR) { const Orientation orient = RotationVectorToOrientation(x, y, z, w); - FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma); + FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma, + Orientation::kAbsolute); + } else if (type == nsIDeviceSensorData::TYPE_GAME_ROTATION_VECTOR) { + const Orientation orient = RotationVectorToOrientation(x, y, z, w); + FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma, + Orientation::kRelative); } else if (type == nsIDeviceSensorData::TYPE_PROXIMITY) { FireDOMProximityEvent(target, x, y, z); } else if (type == nsIDeviceSensorData::TYPE_LIGHT) { @@ -368,7 +379,8 @@ void nsDeviceSensors::FireDOMOrientationEvent(EventTarget* aTarget, double aAlpha, double aBeta, - double aGamma) + double aGamma, + bool aIsAbsolute) { DeviceOrientationEventInit init; init.mBubbles = true; @@ -376,7 +388,7 @@ nsDeviceSensors::FireDOMOrientationEvent(EventTarget* aTarget, init.mAlpha.SetValue(aAlpha); init.mBeta.SetValue(aBeta); init.mGamma.SetValue(aGamma); - init.mAbsolute = true; + init.mAbsolute = aIsAbsolute; RefPtr event = DeviceOrientationEvent::Constructor(aTarget, diff --git a/dom/system/nsDeviceSensors.h b/dom/system/nsDeviceSensors.h index 660658c3cd9..6f7df48d9a3 100644 --- a/dom/system/nsDeviceSensors.h +++ b/dom/system/nsDeviceSensors.h @@ -55,9 +55,10 @@ private: bool aNear); void FireDOMOrientationEvent(mozilla::dom::EventTarget* target, - double alpha, - double beta, - double gamma); + double aAlpha, + double aBeta, + double aGamma, + bool aIsAbsolute); void FireDOMMotionEvent(class nsIDOMDocument *domDoc, mozilla::dom::EventTarget* target,