diff --git a/dom/system/nsDeviceMotion.cpp b/dom/system/nsDeviceMotion.cpp index 616f9e2c8926..240c46422f40 100644 --- a/dom/system/nsDeviceMotion.cpp +++ b/dom/system/nsDeviceMotion.cpp @@ -252,8 +252,10 @@ nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z) if (domdoc) { nsCOMPtr target = do_QueryInterface(windowListeners[i]); - if (type == nsIDeviceMotionData::TYPE_ACCELERATION) - FireDOMMotionEvent(domdoc, target, x, y, z); + if (type == nsIDeviceMotionData::TYPE_ACCELERATION || + type == nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION || + type == nsIDeviceMotionData::TYPE_GYROSCOPE ) + FireDOMMotionEvent(domdoc, target, type, x, y, z); else if (type == nsIDeviceMotionData::TYPE_ORIENTATION) FireDOMOrientationEvent(domdoc, target, x, y, z); } @@ -355,6 +357,7 @@ nsDeviceMotion::FireDOMOrientationEvent(nsIDOMDocument *domdoc, void nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc, nsIDOMEventTarget *target, + PRUint32 type, double x, double y, double z) { @@ -368,15 +371,29 @@ nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc, return; } - // Currently acceleration as determined includes gravity. - nsRefPtr acceleration = new nsDOMDeviceAcceleration(x, y, z); + nsRefPtr acceleration; + nsRefPtr accelerationIncluduingGravity; + nsRefPtr rotationRate; + + switch (type) { + case nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION: + acceleration = new nsDOMDeviceAcceleration(x, y, z); + break; + case nsIDeviceMotionData::TYPE_ACCELERATION: + accelerationIncluduingGravity = new nsDOMDeviceAcceleration(x, y, z); + break; + case nsIDeviceMotionData::TYPE_GYROSCOPE: + rotationRate = new nsDOMDeviceRotationRate(x, y, z); + break; + } + me->InitDeviceMotionEvent(NS_LITERAL_STRING("devicemotion"), true, false, - nsnull, acceleration, - nsnull, + accelerationIncluduingGravity, + rotationRate, DEFAULT_SENSOR_POLL); nsCOMPtr privateEvent = do_QueryInterface(event); diff --git a/dom/system/nsDeviceMotion.h b/dom/system/nsDeviceMotion.h index 68e0c7087078..ba55f9f201b7 100644 --- a/dom/system/nsDeviceMotion.h +++ b/dom/system/nsDeviceMotion.h @@ -87,6 +87,7 @@ private: void FireDOMMotionEvent(class nsIDOMDocument *domDoc, class nsIDOMEventTarget *target, + PRUint32 type, double x, double y, double z); diff --git a/hal/HalSensor.h b/hal/HalSensor.h index de4d8edac458..521c061787a7 100644 --- a/hal/HalSensor.h +++ b/hal/HalSensor.h @@ -54,6 +54,8 @@ enum SensorType { SENSOR_ORIENTATION, SENSOR_ACCELERATION, SENSOR_PROXIMITY, + SENSOR_LINEAR_ACCELERATION, + SENSOR_GYROSCOPE, NUM_SENSOR_TYPE }; diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 065dc5e1c86b..0950eb664628 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -129,6 +129,12 @@ public class GeckoAppShell /* Default value of how fast we should hint the Android sensors. */ private static int sDefaultSensorHint = 100; + private static Sensor gAccelerometerSensor = null; + private static Sensor gLinearAccelerometerSensor = null; + private static Sensor gGyroscopeSensor = null; + private static Sensor gOrientationSensor = null; + private static Sensor gProximitySensor = null; + /* The Android-side API: API methods that Android calls */ // Initialization methods @@ -536,31 +542,6 @@ public class GeckoAppShell tmp.countDown(); } - static Sensor gAccelerometerSensor = null; - static Sensor gOrientationSensor = null; - - public static void enableDeviceMotion(boolean enable) { - LayerView v = GeckoApp.mAppContext.getLayerController().getView(); - SensorManager sm = (SensorManager) v.getContext().getSystemService(Context.SENSOR_SERVICE); - - if (gAccelerometerSensor == null || gOrientationSensor == null) { - gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); - gOrientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION); - } - - if (enable) { - if (gAccelerometerSensor != null) - sm.registerListener(GeckoApp.mAppContext, gAccelerometerSensor, sDefaultSensorHint); - if (gOrientationSensor != null) - sm.registerListener(GeckoApp.mAppContext, gOrientationSensor, sDefaultSensorHint); - } else { - if (gAccelerometerSensor != null) - sm.unregisterListener(GeckoApp.mAppContext, gAccelerometerSensor); - if (gOrientationSensor != null) - sm.unregisterListener(GeckoApp.mAppContext, gOrientationSensor); - } - } - public static void enableLocation(final boolean enable) { getMainHandler().post(new Runnable() { public void run() { @@ -588,26 +569,46 @@ public class GeckoAppShell }); } - /* - * Keep these values consistent with |SensorType| in Hal.h - */ - private static final int SENSOR_ORIENTATION = 1; - private static final int SENSOR_ACCELERATION = 2; - private static final int SENSOR_PROXIMITY = 3; - - private static Sensor gProximitySensor = null; - public static void enableSensor(int aSensortype) { SensorManager sm = (SensorManager) GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE); switch(aSensortype) { - case SENSOR_PROXIMITY: + case GeckoHalDefines.SENSOR_ORIENTATION: + if(gOrientationSensor == null) + gOrientationSensor = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION); + if (gOrientationSensor != null) + sm.registerListener(GeckoApp.mAppContext, gOrientationSensor, sDefaultSensorHint); + break; + + case GeckoHalDefines.SENSOR_ACCELERATION: + if(gAccelerometerSensor == null) + gAccelerometerSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); + if (gAccelerometerSensor != null) + sm.registerListener(GeckoApp.mAppContext, gAccelerometerSensor, sDefaultSensorHint); + break; + + case GeckoHalDefines.SENSOR_PROXIMITY: if(gProximitySensor == null) gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); - sm.registerListener(GeckoApp.mAppContext, gProximitySensor, - sDefaultSensorHint); + if (gProximitySensor != null) + sm.registerListener(GeckoApp.mAppContext, gProximitySensor, sDefaultSensorHint); break; + + case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION: + if(gLinearAccelerometerSensor == null) + gLinearAccelerometerSensor = sm.getDefaultSensor(10); + if (gLinearAccelerometerSensor != null) + sm.registerListener(GeckoApp.mAppContext, gLinearAccelerometerSensor, sDefaultSensorHint); + break; + + case GeckoHalDefines.SENSOR_GYROSCOPE: + if(gGyroscopeSensor == null) + gGyroscopeSensor = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE); + if (gGyroscopeSensor != null) + sm.registerListener(GeckoApp.mAppContext, gGyroscopeSensor, sDefaultSensorHint); + break; + } } @@ -615,9 +616,30 @@ public class GeckoAppShell SensorManager sm = (SensorManager) GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE); - switch(aSensortype) { - case SENSOR_PROXIMITY: - sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor); + switch (aSensortype) { + case GeckoHalDefines.SENSOR_ORIENTATION: + if (gOrientationSensor != null) + sm.unregisterListener(GeckoApp.mAppContext, gOrientationSensor); + break; + + case GeckoHalDefines.SENSOR_ACCELERATION: + if (gAccelerometerSensor != null) + sm.unregisterListener(GeckoApp.mAppContext, gAccelerometerSensor); + break; + + case GeckoHalDefines.SENSOR_PROXIMITY: + if (gProximitySensor != null) + sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor); + break; + + case GeckoHalDefines.SENSOR_LINEAR_ACCELERATION: + if (gLinearAccelerometerSensor != null) + sm.unregisterListener(GeckoApp.mAppContext, gLinearAccelerometerSensor); + break; + + case GeckoHalDefines.SENSOR_GYROSCOPE: + if (gGyroscopeSensor != null) + sm.unregisterListener(GeckoApp.mAppContext, gGyroscopeSensor); break; } } diff --git a/mobile/android/base/GeckoEvent.java b/mobile/android/base/GeckoEvent.java index 63b4244b966a..e3b4f80b986e 100644 --- a/mobile/android/base/GeckoEvent.java +++ b/mobile/android/base/GeckoEvent.java @@ -52,6 +52,7 @@ import android.util.DisplayMetrics; import android.graphics.PointF; import android.text.format.Time; import android.os.SystemClock; +import java.lang.Math; import java.lang.System; import android.util.Log; @@ -68,8 +69,8 @@ public class GeckoEvent { private static final int NATIVE_POKE = 0; private static final int KEY_EVENT = 1; private static final int MOTION_EVENT = 2; - private static final int ORIENTATION_EVENT = 3; - private static final int ACCELERATION_EVENT = 4; + private static final int SENSOR_EVENT = 3; + private static final int UNUSED1_EVENT = 4; private static final int LOCATION_EVENT = 5; private static final int IME_EVENT = 6; private static final int DRAW = 7; @@ -121,7 +122,6 @@ public class GeckoEvent { public Point[] mPointRadii; public Rect mRect; public double mX, mY, mZ; - public double mAlpha, mBeta, mGamma; public double mDistance; public int mMetaState, mFlags; @@ -280,25 +280,46 @@ public class GeckoEvent { } public static GeckoEvent createSensorEvent(SensorEvent s) { - GeckoEvent event = null; int sensor_type = s.sensor.getType(); - + GeckoEvent event = null; + switch(sensor_type) { + case Sensor.TYPE_ACCELEROMETER: - event = new GeckoEvent(ACCELERATION_EVENT); + event = new GeckoEvent(SENSOR_EVENT); + event.mFlags = GeckoHalDefines.SENSOR_ACCELERATION; event.mX = s.values[0]; event.mY = s.values[1]; event.mZ = s.values[2]; break; - + + case 10 /* Requires API Level 9, so just use the raw value - Sensor.TYPE_LINEAR_ACCELEROMETER*/ : + event = new GeckoEvent(SENSOR_EVENT); + event.mFlags = GeckoHalDefines.SENSOR_LINEAR_ACCELERATION; + event.mX = s.values[0]; + event.mY = s.values[1]; + event.mZ = s.values[2]; + break; + case Sensor.TYPE_ORIENTATION: - event = new GeckoEvent(ORIENTATION_EVENT); - event.mAlpha = s.values[0]; - event.mBeta = s.values[1]; - event.mGamma = s.values[2]; + event = new GeckoEvent(SENSOR_EVENT); + event.mFlags = GeckoHalDefines.SENSOR_ORIENTATION; + event.mX = s.values[0]; + event.mY = s.values[1]; + event.mZ = s.values[2]; + break; + + case Sensor.TYPE_GYROSCOPE: + event = new GeckoEvent(SENSOR_EVENT); + event.mFlags = GeckoHalDefines.SENSOR_GYROSCOPE; + event.mX = Math.toDegrees(s.values[0]); + event.mY = Math.toDegrees(s.values[1]); + event.mZ = Math.toDegrees(s.values[2]); break; case Sensor.TYPE_PROXIMITY: + // bug 734854 - maybe we can get rid of this event. is + // values[1] and values[2] valid? event = new GeckoEvent(PROXIMITY_EVENT); event.mDistance = s.values[0]; break; diff --git a/mobile/android/base/GeckoHalDefines.java b/mobile/android/base/GeckoHalDefines.java new file mode 100644 index 000000000000..ea6e02e06513 --- /dev/null +++ b/mobile/android/base/GeckoHalDefines.java @@ -0,0 +1,49 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- + * ***** 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 Android code. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2012 + * 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 ***** */ + +package org.mozilla.gecko; + +public class GeckoHalDefines +{ + /* + * Keep these values consistent with |SensorType| in Hal.h + */ + public static final int SENSOR_ORIENTATION = 0; + public static final int SENSOR_ACCELERATION = 1; + public static final int SENSOR_PROXIMITY = 2; + public static final int SENSOR_LINEAR_ACCELERATION = 3; + public static final int SENSOR_GYROSCOPE = 4; +}; diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index 7f56871d9683..79a358c5aa68 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -87,6 +87,7 @@ FENNEC_JAVA_FILES = \ GeckoEvent.java \ GeckoEventListener.java \ GeckoEventResponder.java \ + GeckoHalDefines.java \ GeckoInputConnection.java \ GeckoMessageReceiver.java \ GeckoPreferences.java \ diff --git a/widget/android/AndroidBridge.cpp b/widget/android/AndroidBridge.cpp index be5ec97216e9..30311c11ab17 100644 --- a/widget/android/AndroidBridge.cpp +++ b/widget/android/AndroidBridge.cpp @@ -111,14 +111,9 @@ AndroidBridge::Init(JNIEnv *jEnv, jNotifyScreenShot = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyScreenShot", "(Ljava/nio/ByteBuffer;III)V"); jAcknowledgeEventSync = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "acknowledgeEventSync", "()V"); - jEnableDeviceMotion = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableDeviceMotion", "(Z)V"); jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V"); - jEnableSensor = - (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, - "enableSensor", "(I)V"); - jDisableSensor = - (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, - "disableSensor", "(I)V"); + jEnableSensor = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableSensor", "(I)V"); + jDisableSensor = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "disableSensor", "(I)V"); jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V"); jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V"); jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V"); @@ -311,13 +306,23 @@ AndroidBridge::EnableDeviceMotion(bool aEnable) { ALOG_BRIDGE("AndroidBridge::EnableDeviceMotion"); - JNIEnv *env = GetJNIEnv(); - if (!env) - return; - - env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableDeviceMotion, aEnable); + // bug 734855 - we probably can make this finer grain based on + // the DOM APIs that are being invoked. + if (aEnable) { + EnableSensor(hal::SENSOR_ORIENTATION); + EnableSensor(hal::SENSOR_ACCELERATION); + EnableSensor(hal::SENSOR_LINEAR_ACCELERATION); + EnableSensor(hal::SENSOR_GYROSCOPE); + } + else { + DisableSensor(hal::SENSOR_ORIENTATION); + DisableSensor(hal::SENSOR_ACCELERATION); + DisableSensor(hal::SENSOR_LINEAR_ACCELERATION); + DisableSensor(hal::SENSOR_GYROSCOPE); + } } + void AndroidBridge::EnableLocation(bool aEnable) { @@ -326,22 +331,30 @@ AndroidBridge::EnableLocation(bool aEnable) JNIEnv *env = GetJNIEnv(); if (!env) return; - + + AutoLocalJNIFrame jniFrame(env, 1); env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable); } void AndroidBridge::EnableSensor(int aSensorType) { ALOG_BRIDGE("AndroidBridge::EnableSensor"); - mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor, - aSensorType); + JNIEnv *env = GetJNIEnv(); + if (!env) + return; + + AutoLocalJNIFrame jniFrame(env, 1); + env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor, aSensorType); } void AndroidBridge::DisableSensor(int aSensorType) { ALOG_BRIDGE("AndroidBridge::DisableSensor"); - mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor, - aSensorType); + JNIEnv *env = GetJNIEnv(); + if (!env) + return; + AutoLocalJNIFrame jniFrame(env, 1); + env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor, aSensorType); } void diff --git a/widget/android/AndroidBridge.h b/widget/android/AndroidBridge.h index 54c9e35b8667..391259fb56fe 100644 --- a/widget/android/AndroidBridge.h +++ b/widget/android/AndroidBridge.h @@ -424,7 +424,6 @@ protected: jmethodID jNotifyIMEChange; jmethodID jNotifyScreenShot; jmethodID jAcknowledgeEventSync; - jmethodID jEnableDeviceMotion; jmethodID jEnableLocation; jmethodID jEnableSensor; jmethodID jDisableSensor; diff --git a/widget/android/AndroidJavaWrappers.cpp b/widget/android/AndroidJavaWrappers.cpp index 6e352d2a4011..841547ed54d7 100644 --- a/widget/android/AndroidJavaWrappers.cpp +++ b/widget/android/AndroidJavaWrappers.cpp @@ -49,9 +49,6 @@ jfieldID AndroidGeckoEvent::jPointIndicies = 0; jfieldID AndroidGeckoEvent::jPressures = 0; jfieldID AndroidGeckoEvent::jPointRadii = 0; jfieldID AndroidGeckoEvent::jOrientations = 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; @@ -148,9 +145,6 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv) jOrientations = getField("mOrientations", "[F"); jPressures = getField("mPressures", "[F"); jPointRadii = getField("mPointRadii", "[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"); @@ -427,17 +421,12 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj) ReadRectField(jenv); break; - 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 SENSOR_EVENT: + mX = jenv->GetDoubleField(jobj, jXField); + mY = jenv->GetDoubleField(jobj, jYField); + mZ = jenv->GetDoubleField(jobj, jZField); + mFlags = jenv->GetIntField(jobj, jFlagsField); + break; case LOCATION_EVENT: { jobject location = jenv->GetObjectField(jobj, jLocationField); diff --git a/widget/android/AndroidJavaWrappers.h b/widget/android/AndroidJavaWrappers.h index 36283bf73861..af3de14482fb 100644 --- a/widget/android/AndroidJavaWrappers.h +++ b/widget/android/AndroidJavaWrappers.h @@ -420,9 +420,6 @@ public: nsTArray Pressures() { return mPressures; } nsTArray Orientations() { return mOrientations; } nsTArray PointRadii() { return mPointRadii; } - double Alpha() { return mAlpha; } - double Beta() { return mBeta; } - double Gamma() { return mGamma; } double X() { return mX; } double Y() { return mY; } double Z() { return mZ; } @@ -460,7 +457,6 @@ protected: int mOffset, mCount; int mRangeType, mRangeStyles; int mRangeForeColor, mRangeBackColor; - double mAlpha, mBeta, mGamma; double mX, mY, mZ; double mDistance; int mPointerIndex; @@ -494,9 +490,6 @@ protected: static jfieldID jOrientations; static jfieldID jPressures; static jfieldID jPointRadii; - static jfieldID jAlphaField; - static jfieldID jBetaField; - static jfieldID jGammaField; static jfieldID jXField; static jfieldID jYField; static jfieldID jZField; @@ -527,8 +520,8 @@ public: NATIVE_POKE = 0, KEY_EVENT = 1, MOTION_EVENT = 2, - ORIENTATION_EVENT = 3, - ACCELERATION_EVENT = 4, + SENSOR_EVENT = 3, + UNUSED1_EVENT = 4, LOCATION_EVENT = 5, IME_EVENT = 6, DRAW = 7, diff --git a/widget/android/nsAppShell.cpp b/widget/android/nsAppShell.cpp index ed34f9ac6cec..631dc52fdd4d 100644 --- a/widget/android/nsAppShell.cpp +++ b/widget/android/nsAppShell.cpp @@ -96,7 +96,7 @@ nsAppShell::nsAppShell() mQueueCond(mCondLock, "nsAppShell.mQueueCond"), mNumDraws(0), mNumViewports(0), - mPendingOrientationEvents(false) + mPendingSensorEvents(false) { gAppShell = this; } @@ -336,20 +336,41 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait) gDeviceMotionSystem->NeedsCalibration(); break; - case AndroidGeckoEvent::ACCELERATION_EVENT: - gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, - -curEvent->X(), - curEvent->Y(), - curEvent->Z()); - break; + case AndroidGeckoEvent::SENSOR_EVENT: + mPendingSensorEvents = false; + switch (curEvent->Flags()) { + case hal::SENSOR_ORIENTATION: + gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION, + curEvent->X(), + -curEvent->Y(), + -curEvent->Z()); + break; - case AndroidGeckoEvent::ORIENTATION_EVENT: - gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION, - curEvent->Alpha(), - -curEvent->Beta(), - -curEvent->Gamma()); - mPendingOrientationEvents = false; - break; + case hal::SENSOR_ACCELERATION: + gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION, + -curEvent->X(), + curEvent->Y(), + curEvent->Z()); + break; + + case hal::SENSOR_LINEAR_ACCELERATION: + gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION, + -curEvent->X(), + curEvent->Y(), + curEvent->Z()); + break; + + case hal::SENSOR_GYROSCOPE: + gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_GYROSCOPE, + -curEvent->X(), + curEvent->Y(), + curEvent->Z()); + break; + + default: + __android_log_print(ANDROID_LOG_ERROR, "Gecko", "### SENSOR_EVENT fired, but type wasn't known %d", curEvent->Flags()); + } + break; case AndroidGeckoEvent::LOCATION_EVENT: { if (!gLocationCallback) @@ -603,10 +624,10 @@ nsAppShell::PostEvent(AndroidGeckoEvent *ae) delete event; } } - } else if (ae->Type() == AndroidGeckoEvent::ORIENTATION_EVENT) { - if (!mPendingOrientationEvents) - mEventQueue.AppendElement(ae); - mPendingOrientationEvents = true; + } else if (ae->Type() == AndroidGeckoEvent::SENSOR_EVENT) { + if (!mPendingSensorEvents) + mEventQueue.AppendElement(ae); + mPendingSensorEvents = true; } else { mEventQueue.AppendElement(ae); } diff --git a/widget/android/nsAppShell.h b/widget/android/nsAppShell.h index ef43ae356e21..f86964dd8f59 100644 --- a/widget/android/nsAppShell.h +++ b/widget/android/nsAppShell.h @@ -110,7 +110,7 @@ protected: mozilla::AndroidGeckoEvent *PeekNextEvent(); nsCOMPtr mBrowserApp; - bool mPendingOrientationEvents; + bool mPendingSensorEvents; }; #endif // nsAppShell_h__ diff --git a/xpcom/system/nsIDeviceMotion.idl b/xpcom/system/nsIDeviceMotion.idl index b83c286be4ca..79313d898388 100644 --- a/xpcom/system/nsIDeviceMotion.idl +++ b/xpcom/system/nsIDeviceMotion.idl @@ -43,6 +43,8 @@ interface nsIDeviceMotionData : nsISupports { const unsigned long TYPE_ACCELERATION = 0; const unsigned long TYPE_ORIENTATION = 1; + const unsigned long TYPE_LINEAR_ACCELERATION = 2; + const unsigned long TYPE_GYROSCOPE = 3; readonly attribute unsigned long type;