Bug 888482 - Make new event to set layer client in Gecko; r=snorp

This commit is contained in:
Jim Chen 2014-09-30 18:20:58 -04:00
parent df46e75a9c
commit 3418bcd4be
4 changed files with 45 additions and 0 deletions

View File

@ -76,6 +76,7 @@ public class GeckoEvent {
KEY_EVENT(1),
MOTION_EVENT(2),
SENSOR_EVENT(3),
PROCESS_OBJECT(4),
LOCATION_EVENT(5),
IME_EVENT(6),
SIZE_CHANGED(8),
@ -183,6 +184,8 @@ public class GeckoEvent {
public static final int ACTION_GAMEPAD_BUTTON = 1;
public static final int ACTION_GAMEPAD_AXES = 2;
public static final int ACTION_OBJECT_LAYER_CLIENT = 1;
private final int mType;
private int mAction;
private boolean mAckNeeded;
@ -245,6 +248,8 @@ public class GeckoEvent {
private String[] mPrefNames;
private Object mObject;
private GeckoEvent(NativeGeckoEvent event) {
mType = event.value;
}
@ -597,6 +602,13 @@ public class GeckoEvent {
return event;
}
public static GeckoEvent createObjectEvent(final int action, final Object object) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.PROCESS_OBJECT);
event.mAction = action;
event.mObject = object;
return event;
}
public static GeckoEvent createLocationEvent(Location l) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOCATION_EVENT);
event.mLocation = l;

View File

@ -71,6 +71,7 @@ jfieldID AndroidGeckoEvent::jGamepadButtonPressedField = 0;
jfieldID AndroidGeckoEvent::jGamepadButtonValueField = 0;
jfieldID AndroidGeckoEvent::jGamepadValuesField = 0;
jfieldID AndroidGeckoEvent::jPrefNamesField = 0;
jfieldID AndroidGeckoEvent::jObjectField = 0;
jclass AndroidGeckoEvent::jDomKeyLocationClass = 0;
jfieldID AndroidGeckoEvent::jDomKeyLocationValueField = 0;
@ -183,6 +184,7 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
jGamepadButtonValueField = getField("mGamepadButtonValue", "F");
jGamepadValuesField = getField("mGamepadValues", "[F");
jPrefNamesField = getField("mPrefNames", "[Ljava/lang/String;");
jObjectField = getField("mObject", "Ljava/lang/Object;");
// Init GeckoEvent.DomKeyLocation enum
jDomKeyLocationClass = getClassGlobalRef("org/mozilla/gecko/GeckoEvent$DomKeyLocation");
@ -503,6 +505,13 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
break;
case PROCESS_OBJECT: {
const jobject obj = jenv->GetObjectField(jobj, jObjectField);
mObject.Init(obj, jenv);
jenv->DeleteLocalRef(obj);
break;
}
case LOCATION_EVENT: {
jobject location = jenv->GetObjectField(jobj, jLocationField);
mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location);

View File

@ -552,6 +552,7 @@ public:
float GamepadButtonValue() { return mGamepadButtonValue; }
const nsTArray<float>& GamepadValues() { return mGamepadValues; }
int RequestId() { return mCount; } // for convenience
const AutoGlobalWrappedJavaObject& Object() { return mObject; }
bool CanCoalesceWith(AndroidGeckoEvent* ae);
WidgetTouchEvent MakeTouchEvent(nsIWidget* widget);
MultiTouchInput MakeMultiTouchInput(nsIWidget* widget);
@ -601,6 +602,7 @@ protected:
nsTArray<nsString> mPrefNames;
MultiTouchInput mApzInput;
mozilla::layers::ScrollableLayerGuid mApzGuid;
AutoGlobalWrappedJavaObject mObject;
void ReadIntArray(nsTArray<int> &aVals,
JNIEnv *jenv,
@ -685,6 +687,8 @@ protected:
static jfieldID jGamepadButtonValueField;
static jfieldID jGamepadValuesField;
static jfieldID jObjectField;
static jclass jDomKeyLocationClass;
static jfieldID jDomKeyLocationValueField;
@ -694,6 +698,7 @@ public:
KEY_EVENT = 1,
MOTION_EVENT = 2,
SENSOR_EVENT = 3,
PROCESS_OBJECT = 4,
LOCATION_EVENT = 5,
IME_EVENT = 6,
SIZE_CHANGED = 8,
@ -766,6 +771,11 @@ public:
ACTION_GAMEPAD_BUTTON = 1,
ACTION_GAMEPAD_AXES = 2
};
enum {
ACTION_OBJECT_LAYER_CLIENT = 1,
dummy_object_enum_list_end
};
};
class nsJNIString : public nsString

View File

@ -312,6 +312,20 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
}
break;
case AndroidGeckoEvent::PROCESS_OBJECT: {
JNIEnv* const env = AndroidBridge::Bridge()->GetJNIEnv();
AutoLocalJNIFrame frame(env, 1);
switch (curEvent->Action()) {
case AndroidGeckoEvent::ACTION_OBJECT_LAYER_CLIENT:
// SetLayerClient expects a local reference
const jobject obj = env->NewLocalRef(curEvent->Object().wrappedObject());
AndroidBridge::Bridge()->SetLayerClient(env, obj);
break;
}
break;
}
case AndroidGeckoEvent::LOCATION_EVENT: {
if (!gLocationCallback)
break;