Bug 1205649 - [1.1] Use relative orientation for DOM DeviceOrientation events by default. r=vlad

This commit is contained in:
Eugen Sawin 2015-12-17 21:49:44 +01:00
parent 064f36b25d
commit 3448500e15
3 changed files with 23 additions and 8 deletions

View File

@ -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

View File

@ -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<DeviceOrientationEvent> event =
DeviceOrientationEvent::Constructor(aTarget,

View File

@ -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,