Bug 734324 - implement device motion - rotation rate and acceleration. r=jdm
This commit is contained in:
@@ -252,8 +252,10 @@ nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
|
|||||||
|
|
||||||
if (domdoc) {
|
if (domdoc) {
|
||||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(windowListeners[i]);
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(windowListeners[i]);
|
||||||
if (type == nsIDeviceMotionData::TYPE_ACCELERATION)
|
if (type == nsIDeviceMotionData::TYPE_ACCELERATION ||
|
||||||
FireDOMMotionEvent(domdoc, target, x, y, z);
|
type == nsIDeviceMotionData::TYPE_LINEAR_ACCELERATION ||
|
||||||
|
type == nsIDeviceMotionData::TYPE_GYROSCOPE )
|
||||||
|
FireDOMMotionEvent(domdoc, target, type, x, y, z);
|
||||||
else if (type == nsIDeviceMotionData::TYPE_ORIENTATION)
|
else if (type == nsIDeviceMotionData::TYPE_ORIENTATION)
|
||||||
FireDOMOrientationEvent(domdoc, target, x, y, z);
|
FireDOMOrientationEvent(domdoc, target, x, y, z);
|
||||||
}
|
}
|
||||||
@@ -355,6 +357,7 @@ nsDeviceMotion::FireDOMOrientationEvent(nsIDOMDocument *domdoc,
|
|||||||
void
|
void
|
||||||
nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
|
nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
|
||||||
nsIDOMEventTarget *target,
|
nsIDOMEventTarget *target,
|
||||||
|
PRUint32 type,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
double z) {
|
double z) {
|
||||||
@@ -368,15 +371,29 @@ nsDeviceMotion::FireDOMMotionEvent(nsIDOMDocument *domdoc,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently acceleration as determined includes gravity.
|
nsRefPtr<nsDOMDeviceAcceleration> acceleration;
|
||||||
nsRefPtr<nsDOMDeviceAcceleration> acceleration = new nsDOMDeviceAcceleration(x, y, z);
|
nsRefPtr<nsDOMDeviceAcceleration> accelerationIncluduingGravity;
|
||||||
|
nsRefPtr<nsDOMDeviceRotationRate> 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"),
|
me->InitDeviceMotionEvent(NS_LITERAL_STRING("devicemotion"),
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
nsnull,
|
|
||||||
acceleration,
|
acceleration,
|
||||||
nsnull,
|
accelerationIncluduingGravity,
|
||||||
|
rotationRate,
|
||||||
DEFAULT_SENSOR_POLL);
|
DEFAULT_SENSOR_POLL);
|
||||||
|
|
||||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ private:
|
|||||||
|
|
||||||
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
||||||
class nsIDOMEventTarget *target,
|
class nsIDOMEventTarget *target,
|
||||||
|
PRUint32 type,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
double z);
|
double z);
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ enum SensorType {
|
|||||||
SENSOR_ORIENTATION,
|
SENSOR_ORIENTATION,
|
||||||
SENSOR_ACCELERATION,
|
SENSOR_ACCELERATION,
|
||||||
SENSOR_PROXIMITY,
|
SENSOR_PROXIMITY,
|
||||||
|
SENSOR_LINEAR_ACCELERATION,
|
||||||
|
SENSOR_GYROSCOPE,
|
||||||
NUM_SENSOR_TYPE
|
NUM_SENSOR_TYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,12 @@ public class GeckoAppShell
|
|||||||
/* Default value of how fast we should hint the Android sensors. */
|
/* Default value of how fast we should hint the Android sensors. */
|
||||||
private static int sDefaultSensorHint = 100;
|
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 */
|
/* The Android-side API: API methods that Android calls */
|
||||||
|
|
||||||
// Initialization methods
|
// Initialization methods
|
||||||
@@ -536,31 +542,6 @@ public class GeckoAppShell
|
|||||||
tmp.countDown();
|
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) {
|
public static void enableLocation(final boolean enable) {
|
||||||
getMainHandler().post(new Runnable() {
|
getMainHandler().post(new Runnable() {
|
||||||
public void run() {
|
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) {
|
public static void enableSensor(int aSensortype) {
|
||||||
SensorManager sm = (SensorManager)
|
SensorManager sm = (SensorManager)
|
||||||
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
||||||
|
|
||||||
switch(aSensortype) {
|
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)
|
if(gProximitySensor == null)
|
||||||
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||||
sm.registerListener(GeckoApp.mAppContext, gProximitySensor,
|
if (gProximitySensor != null)
|
||||||
sDefaultSensorHint);
|
sm.registerListener(GeckoApp.mAppContext, gProximitySensor, sDefaultSensorHint);
|
||||||
break;
|
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)
|
SensorManager sm = (SensorManager)
|
||||||
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
GeckoApp.mAppContext.getSystemService(Context.SENSOR_SERVICE);
|
||||||
|
|
||||||
switch(aSensortype) {
|
switch (aSensortype) {
|
||||||
case SENSOR_PROXIMITY:
|
case GeckoHalDefines.SENSOR_ORIENTATION:
|
||||||
sm.unregisterListener(GeckoApp.mAppContext, gProximitySensor);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import android.util.DisplayMetrics;
|
|||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.text.format.Time;
|
import android.text.format.Time;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import java.lang.Math;
|
||||||
import java.lang.System;
|
import java.lang.System;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -68,8 +69,8 @@ public class GeckoEvent {
|
|||||||
private static final int NATIVE_POKE = 0;
|
private static final int NATIVE_POKE = 0;
|
||||||
private static final int KEY_EVENT = 1;
|
private static final int KEY_EVENT = 1;
|
||||||
private static final int MOTION_EVENT = 2;
|
private static final int MOTION_EVENT = 2;
|
||||||
private static final int ORIENTATION_EVENT = 3;
|
private static final int SENSOR_EVENT = 3;
|
||||||
private static final int ACCELERATION_EVENT = 4;
|
private static final int UNUSED1_EVENT = 4;
|
||||||
private static final int LOCATION_EVENT = 5;
|
private static final int LOCATION_EVENT = 5;
|
||||||
private static final int IME_EVENT = 6;
|
private static final int IME_EVENT = 6;
|
||||||
private static final int DRAW = 7;
|
private static final int DRAW = 7;
|
||||||
@@ -121,7 +122,6 @@ public class GeckoEvent {
|
|||||||
public Point[] mPointRadii;
|
public Point[] mPointRadii;
|
||||||
public Rect mRect;
|
public Rect mRect;
|
||||||
public double mX, mY, mZ;
|
public double mX, mY, mZ;
|
||||||
public double mAlpha, mBeta, mGamma;
|
|
||||||
public double mDistance;
|
public double mDistance;
|
||||||
|
|
||||||
public int mMetaState, mFlags;
|
public int mMetaState, mFlags;
|
||||||
@@ -280,25 +280,46 @@ public class GeckoEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GeckoEvent createSensorEvent(SensorEvent s) {
|
public static GeckoEvent createSensorEvent(SensorEvent s) {
|
||||||
GeckoEvent event = null;
|
|
||||||
int sensor_type = s.sensor.getType();
|
int sensor_type = s.sensor.getType();
|
||||||
|
GeckoEvent event = null;
|
||||||
|
|
||||||
switch(sensor_type) {
|
switch(sensor_type) {
|
||||||
|
|
||||||
case Sensor.TYPE_ACCELEROMETER:
|
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.mX = s.values[0];
|
||||||
event.mY = s.values[1];
|
event.mY = s.values[1];
|
||||||
event.mZ = s.values[2];
|
event.mZ = s.values[2];
|
||||||
break;
|
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:
|
case Sensor.TYPE_ORIENTATION:
|
||||||
event = new GeckoEvent(ORIENTATION_EVENT);
|
event = new GeckoEvent(SENSOR_EVENT);
|
||||||
event.mAlpha = s.values[0];
|
event.mFlags = GeckoHalDefines.SENSOR_ORIENTATION;
|
||||||
event.mBeta = s.values[1];
|
event.mX = s.values[0];
|
||||||
event.mGamma = s.values[2];
|
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;
|
break;
|
||||||
|
|
||||||
case Sensor.TYPE_PROXIMITY:
|
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 = new GeckoEvent(PROXIMITY_EVENT);
|
||||||
event.mDistance = s.values[0];
|
event.mDistance = s.values[0];
|
||||||
break;
|
break;
|
||||||
|
|||||||
49
mobile/android/base/GeckoHalDefines.java
Normal file
49
mobile/android/base/GeckoHalDefines.java
Normal file
@@ -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;
|
||||||
|
};
|
||||||
@@ -87,6 +87,7 @@ FENNEC_JAVA_FILES = \
|
|||||||
GeckoEvent.java \
|
GeckoEvent.java \
|
||||||
GeckoEventListener.java \
|
GeckoEventListener.java \
|
||||||
GeckoEventResponder.java \
|
GeckoEventResponder.java \
|
||||||
|
GeckoHalDefines.java \
|
||||||
GeckoInputConnection.java \
|
GeckoInputConnection.java \
|
||||||
GeckoMessageReceiver.java \
|
GeckoMessageReceiver.java \
|
||||||
GeckoPreferences.java \
|
GeckoPreferences.java \
|
||||||
|
|||||||
@@ -111,14 +111,9 @@ AndroidBridge::Init(JNIEnv *jEnv,
|
|||||||
jNotifyScreenShot = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyScreenShot", "(Ljava/nio/ByteBuffer;III)V");
|
jNotifyScreenShot = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyScreenShot", "(Ljava/nio/ByteBuffer;III)V");
|
||||||
jAcknowledgeEventSync = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "acknowledgeEventSync", "()V");
|
jAcknowledgeEventSync = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "acknowledgeEventSync", "()V");
|
||||||
|
|
||||||
jEnableDeviceMotion = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableDeviceMotion", "(Z)V");
|
|
||||||
jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V");
|
jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V");
|
||||||
jEnableSensor =
|
jEnableSensor = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableSensor", "(I)V");
|
||||||
(jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass,
|
jDisableSensor = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "disableSensor", "(I)V");
|
||||||
"enableSensor", "(I)V");
|
|
||||||
jDisableSensor =
|
|
||||||
(jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass,
|
|
||||||
"disableSensor", "(I)V");
|
|
||||||
jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V");
|
jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V");
|
||||||
jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V");
|
jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V");
|
||||||
jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V");
|
jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V");
|
||||||
@@ -311,13 +306,23 @@ AndroidBridge::EnableDeviceMotion(bool aEnable)
|
|||||||
{
|
{
|
||||||
ALOG_BRIDGE("AndroidBridge::EnableDeviceMotion");
|
ALOG_BRIDGE("AndroidBridge::EnableDeviceMotion");
|
||||||
|
|
||||||
JNIEnv *env = GetJNIEnv();
|
// bug 734855 - we probably can make this finer grain based on
|
||||||
if (!env)
|
// the DOM APIs that are being invoked.
|
||||||
return;
|
if (aEnable) {
|
||||||
|
EnableSensor(hal::SENSOR_ORIENTATION);
|
||||||
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableDeviceMotion, aEnable);
|
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
|
void
|
||||||
AndroidBridge::EnableLocation(bool aEnable)
|
AndroidBridge::EnableLocation(bool aEnable)
|
||||||
{
|
{
|
||||||
@@ -326,22 +331,30 @@ AndroidBridge::EnableLocation(bool aEnable)
|
|||||||
JNIEnv *env = GetJNIEnv();
|
JNIEnv *env = GetJNIEnv();
|
||||||
if (!env)
|
if (!env)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
AutoLocalJNIFrame jniFrame(env, 1);
|
||||||
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable);
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AndroidBridge::EnableSensor(int aSensorType) {
|
AndroidBridge::EnableSensor(int aSensorType) {
|
||||||
ALOG_BRIDGE("AndroidBridge::EnableSensor");
|
ALOG_BRIDGE("AndroidBridge::EnableSensor");
|
||||||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor,
|
JNIEnv *env = GetJNIEnv();
|
||||||
aSensorType);
|
if (!env)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AutoLocalJNIFrame jniFrame(env, 1);
|
||||||
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor, aSensorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AndroidBridge::DisableSensor(int aSensorType) {
|
AndroidBridge::DisableSensor(int aSensorType) {
|
||||||
ALOG_BRIDGE("AndroidBridge::DisableSensor");
|
ALOG_BRIDGE("AndroidBridge::DisableSensor");
|
||||||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor,
|
JNIEnv *env = GetJNIEnv();
|
||||||
aSensorType);
|
if (!env)
|
||||||
|
return;
|
||||||
|
AutoLocalJNIFrame jniFrame(env, 1);
|
||||||
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor, aSensorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -424,7 +424,6 @@ protected:
|
|||||||
jmethodID jNotifyIMEChange;
|
jmethodID jNotifyIMEChange;
|
||||||
jmethodID jNotifyScreenShot;
|
jmethodID jNotifyScreenShot;
|
||||||
jmethodID jAcknowledgeEventSync;
|
jmethodID jAcknowledgeEventSync;
|
||||||
jmethodID jEnableDeviceMotion;
|
|
||||||
jmethodID jEnableLocation;
|
jmethodID jEnableLocation;
|
||||||
jmethodID jEnableSensor;
|
jmethodID jEnableSensor;
|
||||||
jmethodID jDisableSensor;
|
jmethodID jDisableSensor;
|
||||||
|
|||||||
@@ -49,9 +49,6 @@ jfieldID AndroidGeckoEvent::jPointIndicies = 0;
|
|||||||
jfieldID AndroidGeckoEvent::jPressures = 0;
|
jfieldID AndroidGeckoEvent::jPressures = 0;
|
||||||
jfieldID AndroidGeckoEvent::jPointRadii = 0;
|
jfieldID AndroidGeckoEvent::jPointRadii = 0;
|
||||||
jfieldID AndroidGeckoEvent::jOrientations = 0;
|
jfieldID AndroidGeckoEvent::jOrientations = 0;
|
||||||
jfieldID AndroidGeckoEvent::jAlphaField = 0;
|
|
||||||
jfieldID AndroidGeckoEvent::jBetaField = 0;
|
|
||||||
jfieldID AndroidGeckoEvent::jGammaField = 0;
|
|
||||||
jfieldID AndroidGeckoEvent::jXField = 0;
|
jfieldID AndroidGeckoEvent::jXField = 0;
|
||||||
jfieldID AndroidGeckoEvent::jYField = 0;
|
jfieldID AndroidGeckoEvent::jYField = 0;
|
||||||
jfieldID AndroidGeckoEvent::jZField = 0;
|
jfieldID AndroidGeckoEvent::jZField = 0;
|
||||||
@@ -148,9 +145,6 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
|
|||||||
jOrientations = getField("mOrientations", "[F");
|
jOrientations = getField("mOrientations", "[F");
|
||||||
jPressures = getField("mPressures", "[F");
|
jPressures = getField("mPressures", "[F");
|
||||||
jPointRadii = getField("mPointRadii", "[Landroid/graphics/Point;");
|
jPointRadii = getField("mPointRadii", "[Landroid/graphics/Point;");
|
||||||
jAlphaField = getField("mAlpha", "D");
|
|
||||||
jBetaField = getField("mBeta", "D");
|
|
||||||
jGammaField = getField("mGamma", "D");
|
|
||||||
jXField = getField("mX", "D");
|
jXField = getField("mX", "D");
|
||||||
jYField = getField("mY", "D");
|
jYField = getField("mY", "D");
|
||||||
jZField = getField("mZ", "D");
|
jZField = getField("mZ", "D");
|
||||||
@@ -427,17 +421,12 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
|
|||||||
ReadRectField(jenv);
|
ReadRectField(jenv);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ORIENTATION_EVENT:
|
case SENSOR_EVENT:
|
||||||
mAlpha = jenv->GetDoubleField(jobj, jAlphaField);
|
mX = jenv->GetDoubleField(jobj, jXField);
|
||||||
mBeta = jenv->GetDoubleField(jobj, jBetaField);
|
mY = jenv->GetDoubleField(jobj, jYField);
|
||||||
mGamma = jenv->GetDoubleField(jobj, jGammaField);
|
mZ = jenv->GetDoubleField(jobj, jZField);
|
||||||
break;
|
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
||||||
|
break;
|
||||||
case ACCELERATION_EVENT:
|
|
||||||
mX = jenv->GetDoubleField(jobj, jXField);
|
|
||||||
mY = jenv->GetDoubleField(jobj, jYField);
|
|
||||||
mZ = jenv->GetDoubleField(jobj, jZField);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LOCATION_EVENT: {
|
case LOCATION_EVENT: {
|
||||||
jobject location = jenv->GetObjectField(jobj, jLocationField);
|
jobject location = jenv->GetObjectField(jobj, jLocationField);
|
||||||
|
|||||||
@@ -420,9 +420,6 @@ public:
|
|||||||
nsTArray<float> Pressures() { return mPressures; }
|
nsTArray<float> Pressures() { return mPressures; }
|
||||||
nsTArray<float> Orientations() { return mOrientations; }
|
nsTArray<float> Orientations() { return mOrientations; }
|
||||||
nsTArray<nsIntPoint> PointRadii() { return mPointRadii; }
|
nsTArray<nsIntPoint> PointRadii() { return mPointRadii; }
|
||||||
double Alpha() { return mAlpha; }
|
|
||||||
double Beta() { return mBeta; }
|
|
||||||
double Gamma() { return mGamma; }
|
|
||||||
double X() { return mX; }
|
double X() { return mX; }
|
||||||
double Y() { return mY; }
|
double Y() { return mY; }
|
||||||
double Z() { return mZ; }
|
double Z() { return mZ; }
|
||||||
@@ -460,7 +457,6 @@ protected:
|
|||||||
int mOffset, mCount;
|
int mOffset, mCount;
|
||||||
int mRangeType, mRangeStyles;
|
int mRangeType, mRangeStyles;
|
||||||
int mRangeForeColor, mRangeBackColor;
|
int mRangeForeColor, mRangeBackColor;
|
||||||
double mAlpha, mBeta, mGamma;
|
|
||||||
double mX, mY, mZ;
|
double mX, mY, mZ;
|
||||||
double mDistance;
|
double mDistance;
|
||||||
int mPointerIndex;
|
int mPointerIndex;
|
||||||
@@ -494,9 +490,6 @@ protected:
|
|||||||
static jfieldID jOrientations;
|
static jfieldID jOrientations;
|
||||||
static jfieldID jPressures;
|
static jfieldID jPressures;
|
||||||
static jfieldID jPointRadii;
|
static jfieldID jPointRadii;
|
||||||
static jfieldID jAlphaField;
|
|
||||||
static jfieldID jBetaField;
|
|
||||||
static jfieldID jGammaField;
|
|
||||||
static jfieldID jXField;
|
static jfieldID jXField;
|
||||||
static jfieldID jYField;
|
static jfieldID jYField;
|
||||||
static jfieldID jZField;
|
static jfieldID jZField;
|
||||||
@@ -527,8 +520,8 @@ public:
|
|||||||
NATIVE_POKE = 0,
|
NATIVE_POKE = 0,
|
||||||
KEY_EVENT = 1,
|
KEY_EVENT = 1,
|
||||||
MOTION_EVENT = 2,
|
MOTION_EVENT = 2,
|
||||||
ORIENTATION_EVENT = 3,
|
SENSOR_EVENT = 3,
|
||||||
ACCELERATION_EVENT = 4,
|
UNUSED1_EVENT = 4,
|
||||||
LOCATION_EVENT = 5,
|
LOCATION_EVENT = 5,
|
||||||
IME_EVENT = 6,
|
IME_EVENT = 6,
|
||||||
DRAW = 7,
|
DRAW = 7,
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ nsAppShell::nsAppShell()
|
|||||||
mQueueCond(mCondLock, "nsAppShell.mQueueCond"),
|
mQueueCond(mCondLock, "nsAppShell.mQueueCond"),
|
||||||
mNumDraws(0),
|
mNumDraws(0),
|
||||||
mNumViewports(0),
|
mNumViewports(0),
|
||||||
mPendingOrientationEvents(false)
|
mPendingSensorEvents(false)
|
||||||
{
|
{
|
||||||
gAppShell = this;
|
gAppShell = this;
|
||||||
}
|
}
|
||||||
@@ -336,20 +336,41 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
|
|||||||
gDeviceMotionSystem->NeedsCalibration();
|
gDeviceMotionSystem->NeedsCalibration();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AndroidGeckoEvent::ACCELERATION_EVENT:
|
case AndroidGeckoEvent::SENSOR_EVENT:
|
||||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
|
mPendingSensorEvents = false;
|
||||||
-curEvent->X(),
|
switch (curEvent->Flags()) {
|
||||||
curEvent->Y(),
|
case hal::SENSOR_ORIENTATION:
|
||||||
curEvent->Z());
|
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
|
||||||
break;
|
curEvent->X(),
|
||||||
|
-curEvent->Y(),
|
||||||
|
-curEvent->Z());
|
||||||
|
break;
|
||||||
|
|
||||||
case AndroidGeckoEvent::ORIENTATION_EVENT:
|
case hal::SENSOR_ACCELERATION:
|
||||||
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ORIENTATION,
|
gDeviceMotionSystem->DeviceMotionChanged(nsIDeviceMotionData::TYPE_ACCELERATION,
|
||||||
curEvent->Alpha(),
|
-curEvent->X(),
|
||||||
-curEvent->Beta(),
|
curEvent->Y(),
|
||||||
-curEvent->Gamma());
|
curEvent->Z());
|
||||||
mPendingOrientationEvents = false;
|
break;
|
||||||
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: {
|
case AndroidGeckoEvent::LOCATION_EVENT: {
|
||||||
if (!gLocationCallback)
|
if (!gLocationCallback)
|
||||||
@@ -603,10 +624,10 @@ nsAppShell::PostEvent(AndroidGeckoEvent *ae)
|
|||||||
delete event;
|
delete event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ae->Type() == AndroidGeckoEvent::ORIENTATION_EVENT) {
|
} else if (ae->Type() == AndroidGeckoEvent::SENSOR_EVENT) {
|
||||||
if (!mPendingOrientationEvents)
|
if (!mPendingSensorEvents)
|
||||||
mEventQueue.AppendElement(ae);
|
mEventQueue.AppendElement(ae);
|
||||||
mPendingOrientationEvents = true;
|
mPendingSensorEvents = true;
|
||||||
} else {
|
} else {
|
||||||
mEventQueue.AppendElement(ae);
|
mEventQueue.AppendElement(ae);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ protected:
|
|||||||
mozilla::AndroidGeckoEvent *PeekNextEvent();
|
mozilla::AndroidGeckoEvent *PeekNextEvent();
|
||||||
|
|
||||||
nsCOMPtr<nsIAndroidBrowserApp> mBrowserApp;
|
nsCOMPtr<nsIAndroidBrowserApp> mBrowserApp;
|
||||||
bool mPendingOrientationEvents;
|
bool mPendingSensorEvents;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsAppShell_h__
|
#endif // nsAppShell_h__
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ interface nsIDeviceMotionData : nsISupports
|
|||||||
{
|
{
|
||||||
const unsigned long TYPE_ACCELERATION = 0;
|
const unsigned long TYPE_ACCELERATION = 0;
|
||||||
const unsigned long TYPE_ORIENTATION = 1;
|
const unsigned long TYPE_ORIENTATION = 1;
|
||||||
|
const unsigned long TYPE_LINEAR_ACCELERATION = 2;
|
||||||
|
const unsigned long TYPE_GYROSCOPE = 3;
|
||||||
|
|
||||||
readonly attribute unsigned long type;
|
readonly attribute unsigned long type;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user