mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 734324 - implement device motion - rotation rate and acceleration. r=jdm
This commit is contained in:
parent
cb5e3dd11b
commit
99adfcf041
@ -252,8 +252,10 @@ nsDeviceMotion::DeviceMotionChanged(PRUint32 type, double x, double y, double z)
|
||||
|
||||
if (domdoc) {
|
||||
nsCOMPtr<nsIDOMEventTarget> 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<nsDOMDeviceAcceleration> acceleration = new nsDOMDeviceAcceleration(x, y, z);
|
||||
nsRefPtr<nsDOMDeviceAcceleration> acceleration;
|
||||
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"),
|
||||
true,
|
||||
false,
|
||||
nsnull,
|
||||
acceleration,
|
||||
nsnull,
|
||||
accelerationIncluduingGravity,
|
||||
rotationRate,
|
||||
DEFAULT_SENSOR_POLL);
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||
|
@ -87,6 +87,7 @@ private:
|
||||
|
||||
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
|
||||
class nsIDOMEventTarget *target,
|
||||
PRUint32 type,
|
||||
double x,
|
||||
double y,
|
||||
double z);
|
||||
|
@ -54,6 +54,8 @@ enum SensorType {
|
||||
SENSOR_ORIENTATION,
|
||||
SENSOR_ACCELERATION,
|
||||
SENSOR_PROXIMITY,
|
||||
SENSOR_LINEAR_ACCELERATION,
|
||||
SENSOR_GYROSCOPE,
|
||||
NUM_SENSOR_TYPE
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
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 \
|
||||
GeckoEventListener.java \
|
||||
GeckoEventResponder.java \
|
||||
GeckoHalDefines.java \
|
||||
GeckoInputConnection.java \
|
||||
GeckoMessageReceiver.java \
|
||||
GeckoPreferences.java \
|
||||
|
@ -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
|
||||
|
@ -424,7 +424,6 @@ protected:
|
||||
jmethodID jNotifyIMEChange;
|
||||
jmethodID jNotifyScreenShot;
|
||||
jmethodID jAcknowledgeEventSync;
|
||||
jmethodID jEnableDeviceMotion;
|
||||
jmethodID jEnableLocation;
|
||||
jmethodID jEnableSensor;
|
||||
jmethodID jDisableSensor;
|
||||
|
@ -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);
|
||||
|
@ -420,9 +420,6 @@ public:
|
||||
nsTArray<float> Pressures() { return mPressures; }
|
||||
nsTArray<float> Orientations() { return mOrientations; }
|
||||
nsTArray<nsIntPoint> 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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ protected:
|
||||
mozilla::AndroidGeckoEvent *PeekNextEvent();
|
||||
|
||||
nsCOMPtr<nsIAndroidBrowserApp> mBrowserApp;
|
||||
bool mPendingOrientationEvents;
|
||||
bool mPendingSensorEvents;
|
||||
};
|
||||
|
||||
#endif // nsAppShell_h__
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user