Bug 1289208 - Remove gamepad events from GeckoEvent; r=snorp

Remove the now-obsolete gamepad events from GeckoEvent, along with a few
other used fields in GeckoEvent.
This commit is contained in:
Jim Chen 2016-08-04 09:16:05 -04:00
Родитель 8a82ef17c1
Коммит 15acbc5fab
4 изменённых файлов: 2 добавлений и 274 удалений

Просмотреть файл

@ -69,8 +69,6 @@ public class GeckoEvent {
NATIVE_GESTURE_EVENT(31),
CALL_OBSERVER(33),
REMOVE_OBSERVER(34),
GAMEPAD_ADDREMOVE(45),
GAMEPAD_DATA(46),
LONG_PRESS(47);
public final int value;
@ -84,12 +82,6 @@ public class GeckoEvent {
public static final int ACTION_MAGNIFY = 12;
public static final int ACTION_MAGNIFY_END = 13;
public static final int ACTION_GAMEPAD_ADDED = 1;
public static final int ACTION_GAMEPAD_REMOVED = 2;
public static final int ACTION_GAMEPAD_BUTTON = 1;
public static final int ACTION_GAMEPAD_AXES = 2;
private final int mType;
private int mAction;
private long mTime;
@ -100,78 +92,18 @@ public class GeckoEvent {
private float[] mPressures;
private int[] mToolTypes;
private Point[] mPointRadii;
private Rect mRect;
private double mX;
private double mY;
private double mZ;
private double mW;
private int mMetaState;
private int mFlags;
private int mCount;
private String mCharacters;
private String mCharactersExtra;
private String mData;
private int mWidth;
private int mHeight;
private int mID;
private int mGamepadButton;
private boolean mGamepadButtonPressed;
private float mGamepadButtonValue;
private float[] mGamepadValues;
private GeckoEvent(NativeGeckoEvent event) {
mType = event.value;
}
/**
* This method is a replacement for the the KeyEvent.isGamepadButton method to be
* compatible with Build.VERSION.SDK_INT < 12. This is an implementation of the
* same method isGamepadButton available after SDK 12.
* @param keyCode int with the key code (Android key constant from KeyEvent).
* @return True if the keycode is a gamepad button, such as {@link #KEYCODE_BUTTON_A}.
*/
private static boolean isGamepadButton(int keyCode) {
switch (keyCode) {
case KeyEvent.KEYCODE_BUTTON_A:
case KeyEvent.KEYCODE_BUTTON_B:
case KeyEvent.KEYCODE_BUTTON_C:
case KeyEvent.KEYCODE_BUTTON_X:
case KeyEvent.KEYCODE_BUTTON_Y:
case KeyEvent.KEYCODE_BUTTON_Z:
case KeyEvent.KEYCODE_BUTTON_L1:
case KeyEvent.KEYCODE_BUTTON_R1:
case KeyEvent.KEYCODE_BUTTON_L2:
case KeyEvent.KEYCODE_BUTTON_R2:
case KeyEvent.KEYCODE_BUTTON_THUMBL:
case KeyEvent.KEYCODE_BUTTON_THUMBR:
case KeyEvent.KEYCODE_BUTTON_START:
case KeyEvent.KEYCODE_BUTTON_SELECT:
case KeyEvent.KEYCODE_BUTTON_MODE:
case KeyEvent.KEYCODE_BUTTON_1:
case KeyEvent.KEYCODE_BUTTON_2:
case KeyEvent.KEYCODE_BUTTON_3:
case KeyEvent.KEYCODE_BUTTON_4:
case KeyEvent.KEYCODE_BUTTON_5:
case KeyEvent.KEYCODE_BUTTON_6:
case KeyEvent.KEYCODE_BUTTON_7:
case KeyEvent.KEYCODE_BUTTON_8:
case KeyEvent.KEYCODE_BUTTON_9:
case KeyEvent.KEYCODE_BUTTON_10:
case KeyEvent.KEYCODE_BUTTON_11:
case KeyEvent.KEYCODE_BUTTON_12:
case KeyEvent.KEYCODE_BUTTON_13:
case KeyEvent.KEYCODE_BUTTON_14:
case KeyEvent.KEYCODE_BUTTON_15:
case KeyEvent.KEYCODE_BUTTON_16:
return true;
default:
return false;
}
}
public static GeckoEvent createNativeGestureEvent(int action, PointF pt, double size) {
try {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.NATIVE_GESTURE_EVENT);
@ -338,45 +270,4 @@ public class GeckoEvent {
event.mCharacters = observerKey;
return event;
}
public static GeckoEvent createGamepadAddRemoveEvent(int id, boolean added) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.GAMEPAD_ADDREMOVE);
event.mID = id;
event.mAction = added ? ACTION_GAMEPAD_ADDED : ACTION_GAMEPAD_REMOVED;
return event;
}
private static int boolArrayToBitfield(boolean[] array) {
int bits = 0;
for (int i = 0; i < array.length; i++) {
if (array[i]) {
bits |= 1 << i;
}
}
return bits;
}
public static GeckoEvent createGamepadButtonEvent(int id,
int which,
boolean pressed,
float value) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.GAMEPAD_DATA);
event.mID = id;
event.mAction = ACTION_GAMEPAD_BUTTON;
event.mGamepadButton = which;
event.mGamepadButtonPressed = pressed;
event.mGamepadButtonValue = value;
return event;
}
public static GeckoEvent createGamepadAxisEvent(int id, boolean[] valid,
float[] values) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.GAMEPAD_DATA);
event.mID = id;
event.mAction = ACTION_GAMEPAD_AXES;
event.mFlags = boolArrayToBitfield(valid);
event.mCount = values.length;
event.mGamepadValues = values;
return event;
}
}

Просмотреть файл

@ -26,26 +26,13 @@ jfieldID AndroidGeckoEvent::jToolTypes = 0;
jfieldID AndroidGeckoEvent::jPointRadii = 0;
jfieldID AndroidGeckoEvent::jOrientations = 0;
jfieldID AndroidGeckoEvent::jXField = 0;
jfieldID AndroidGeckoEvent::jYField = 0;
jfieldID AndroidGeckoEvent::jZField = 0;
jfieldID AndroidGeckoEvent::jWField = 0;
jfieldID AndroidGeckoEvent::jDistanceField = 0;
jfieldID AndroidGeckoEvent::jRectField = 0;
jfieldID AndroidGeckoEvent::jCharactersField = 0;
jfieldID AndroidGeckoEvent::jCharactersExtraField = 0;
jfieldID AndroidGeckoEvent::jDataField = 0;
jfieldID AndroidGeckoEvent::jMetaStateField = 0;
jfieldID AndroidGeckoEvent::jFlagsField = 0;
jfieldID AndroidGeckoEvent::jCountField = 0;
jfieldID AndroidGeckoEvent::jPointerIndexField = 0;
jfieldID AndroidGeckoEvent::jWidthField = 0;
jfieldID AndroidGeckoEvent::jHeightField = 0;
jfieldID AndroidGeckoEvent::jIDField = 0;
jfieldID AndroidGeckoEvent::jGamepadButtonField = 0;
jfieldID AndroidGeckoEvent::jGamepadButtonPressedField = 0;
jfieldID AndroidGeckoEvent::jGamepadButtonValueField = 0;
jfieldID AndroidGeckoEvent::jGamepadValuesField = 0;
jclass AndroidPoint::jPointClass = 0;
jfieldID AndroidPoint::jXField = 0;
@ -94,25 +81,13 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
jToolTypes = geckoEvent.getField("mToolTypes", "[I");
jPointRadii = geckoEvent.getField("mPointRadii", "[Landroid/graphics/Point;");
jXField = geckoEvent.getField("mX", "D");
jYField = geckoEvent.getField("mY", "D");
jZField = geckoEvent.getField("mZ", "D");
jWField = geckoEvent.getField("mW", "D");
jRectField = geckoEvent.getField("mRect", "Landroid/graphics/Rect;");
jCharactersField = geckoEvent.getField("mCharacters", "Ljava/lang/String;");
jCharactersExtraField = geckoEvent.getField("mCharactersExtra", "Ljava/lang/String;");
jDataField = geckoEvent.getField("mData", "Ljava/lang/String;");
jMetaStateField = geckoEvent.getField("mMetaState", "I");
jFlagsField = geckoEvent.getField("mFlags", "I");
jCountField = geckoEvent.getField("mCount", "I");
jPointerIndexField = geckoEvent.getField("mPointerIndex", "I");
jWidthField = geckoEvent.getField("mWidth", "I");
jHeightField = geckoEvent.getField("mHeight", "I");
jIDField = geckoEvent.getField("mID", "I");
jGamepadButtonField = geckoEvent.getField("mGamepadButton", "I");
jGamepadButtonPressedField = geckoEvent.getField("mGamepadButtonPressed", "Z");
jGamepadButtonValueField = geckoEvent.getField("mGamepadButtonValue", "F");
jGamepadValuesField = geckoEvent.getField("mGamepadValues", "[F");
}
void
@ -208,20 +183,6 @@ AndroidGeckoEvent::ReadStringArray(nsTArray<nsString> &array,
}
}
void
AndroidGeckoEvent::ReadRectField(JNIEnv *jenv)
{
AndroidRect r(jenv, jenv->GetObjectField(wrappedObject(), jRectField));
if (!r.isNull()) {
mRect.SetRect(r.Left(),
r.Top(),
r.Width(),
r.Height());
} else {
mRect.SetEmpty();
}
}
void
AndroidGeckoEvent::ReadStringFromJString(nsString &aString, JNIEnv *jenv,
jstring s)
@ -257,12 +218,6 @@ AndroidGeckoEvent::ReadDataField(JNIEnv *jenv)
ReadStringFromJString(mData, jenv, s);
}
void
AndroidGeckoEvent::UnionRect(nsIntRect const& aRect)
{
mRect = aRect.Union(mRect);
}
void
AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
{
@ -320,26 +275,6 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
break;
}
case GAMEPAD_ADDREMOVE: {
mID = jenv->GetIntField(jobj, jIDField);
break;
}
case GAMEPAD_DATA: {
mID = jenv->GetIntField(jobj, jIDField);
if (mAction == ACTION_GAMEPAD_BUTTON) {
mGamepadButton = jenv->GetIntField(jobj, jGamepadButtonField);
mGamepadButtonPressed = jenv->GetBooleanField(jobj, jGamepadButtonPressedField);
mGamepadButtonValue = jenv->GetFloatField(jobj, jGamepadButtonValueField);
} else if (mAction == ACTION_GAMEPAD_AXES) {
// Flags is a bitfield of valid entries in gamepadvalues
mFlags = jenv->GetIntField(jobj, jFlagsField);
mCount = jenv->GetIntField(jobj, jCountField);
ReadFloatArray(mGamepadValues, jenv, jGamepadValuesField, mCount);
}
break;
}
default:
break;
}

Просмотреть файл

@ -457,10 +457,6 @@ public:
const nsTArray<float>& Orientations() { return mOrientations; }
const nsTArray<nsIntPoint>& PointRadii() { return mPointRadii; }
double X() { return mX; }
double Y() { return mY; }
double Z() { return mZ; }
double W() { return mW; }
const nsIntRect& Rect() { return mRect; }
nsString& Characters() { return mCharacters; }
nsString& CharactersExtra() { return mCharactersExtra; }
nsString& Data() { return mData; }
@ -470,22 +466,13 @@ public:
bool IsShiftPressed() const { return (mMetaState & AMETA_SHIFT_MASK) != 0; }
bool IsCtrlPressed() const { return (mMetaState & AMETA_CTRL_MASK) != 0; }
bool IsMetaPressed() const { return (mMetaState & AMETA_META_MASK) != 0; }
int Flags() { return mFlags; }
int Count() { return mCount; }
int PointerIndex() { return mPointerIndex; }
int Width() { return mWidth; }
int Height() { return mHeight; }
int ID() { return mID; }
int GamepadButton() { return mGamepadButton; }
bool GamepadButtonPressed() { return mGamepadButtonPressed; }
float GamepadButtonValue() { return mGamepadButtonValue; }
const nsTArray<float>& GamepadValues() { return mGamepadValues; }
int RequestId() { return mCount; } // for convenience
bool CanCoalesceWith(AndroidGeckoEvent* ae);
WidgetTouchEvent MakeTouchEvent(nsIWidget* widget);
MultiTouchInput MakeMultiTouchInput(nsIWidget* widget);
WidgetMouseEvent MakeMouseEvent(nsIWidget* widget);
void UnionRect(nsIntRect const& aRect);
nsIObserver *Observer() { return mObserver; }
mozilla::layers::ScrollableLayerGuid ApzGuid();
uint64_t ApzInputBlockId();
@ -501,18 +488,11 @@ protected:
nsTArray<float> mOrientations;
nsTArray<float> mPressures;
nsTArray<int> mToolTypes;
nsIntRect mRect;
int mFlags, mMetaState;
int mMetaState;
int mCount;
double mX, mY, mZ, mW;
double mX;
int mPointerIndex;
nsString mCharacters, mCharactersExtra, mData;
int mWidth, mHeight;
int mID;
int mGamepadButton;
bool mGamepadButtonPressed;
float mGamepadButtonValue;
nsTArray<float> mGamepadValues;
nsCOMPtr<nsIObserver> mObserver;
MultiTouchInput mApzInput;
mozilla::layers::ScrollableLayerGuid mApzGuid;
@ -534,7 +514,6 @@ protected:
void ReadStringArray(nsTArray<nsString> &aStrings,
JNIEnv *jenv,
jfieldID field);
void ReadRectField(JNIEnv *jenv);
void ReadCharactersField(JNIEnv *jenv);
void ReadCharactersExtraField(JNIEnv *jenv);
void ReadDataField(JNIEnv *jenv);
@ -551,29 +530,14 @@ protected:
static jfieldID jToolTypes;
static jfieldID jPointRadii;
static jfieldID jXField;
static jfieldID jYField;
static jfieldID jZField;
static jfieldID jWField;
static jfieldID jDistanceField;
static jfieldID jRectField;
static jfieldID jCharactersField;
static jfieldID jCharactersExtraField;
static jfieldID jDataField;
static jfieldID jMetaStateField;
static jfieldID jFlagsField;
static jfieldID jCountField;
static jfieldID jPointerIndexField;
static jfieldID jWidthField;
static jfieldID jHeightField;
static jfieldID jIDField;
static jfieldID jGamepadButtonField;
static jfieldID jGamepadButtonPressedField;
static jfieldID jGamepadButtonValueField;
static jfieldID jGamepadValuesField;
public:
enum {
MOTION_EVENT = 2,
@ -584,21 +548,9 @@ public:
CALL_OBSERVER = 33,
REMOVE_OBSERVER = 34,
ADD_OBSERVER = 38,
GAMEPAD_ADDREMOVE = 45,
GAMEPAD_DATA = 46,
LONG_PRESS = 47,
dummy_java_enum_list_end
};
enum {
ACTION_GAMEPAD_ADDED = 1,
ACTION_GAMEPAD_REMOVED = 2
};
enum {
ACTION_GAMEPAD_BUTTON = 1,
ACTION_GAMEPAD_AXES = 2
};
};
class nsJNIString : public nsString

Просмотреть файл

@ -42,11 +42,6 @@
#include <pthread.h>
#include <wchar.h>
#ifdef MOZ_GAMEPAD
#include "mozilla/dom/GamepadPlatformService.h"
#include "mozilla/dom/Gamepad.h"
#endif
#include "GeckoProfiler.h"
#ifdef MOZ_ANDROID_HISTORY
#include "nsNetUtil.h"
@ -72,7 +67,6 @@
#endif
using namespace mozilla;
typedef mozilla::dom::GamepadPlatformService GamepadPlatformService;
nsIGeolocationUpdate *gLocationCallback = nullptr;
@ -694,50 +688,6 @@ nsAppShell::LegacyGeckoEvent::Run()
nsAppShell::Get()->AddObserver(curEvent->Characters(), curEvent->Observer());
break;
case AndroidGeckoEvent::GAMEPAD_ADDREMOVE: {
#ifdef MOZ_GAMEPAD
RefPtr<GamepadPlatformService> service;
service = GamepadPlatformService::GetParentService();
if (!service) {
break;
}
if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_ADDED) {
int svc_id = service->AddGamepad("android",
dom::GamepadMappingType::Standard,
dom::kStandardGamepadButtons,
dom::kStandardGamepadAxes);
java::AndroidGamepadManager::OnGamepadAdded(curEvent->ID(), svc_id);
} else if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_REMOVED) {
service->RemoveGamepad(curEvent->ID());
}
#endif
break;
}
case AndroidGeckoEvent::GAMEPAD_DATA: {
#ifdef MOZ_GAMEPAD
int id = curEvent->ID();
RefPtr<GamepadPlatformService> service;
service = GamepadPlatformService::GetParentService();
if (!service) {
break;
}
if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_BUTTON) {
service->NewButtonEvent(id, curEvent->GamepadButton(),
curEvent->GamepadButtonPressed(),
curEvent->GamepadButtonValue());
} else if (curEvent->Action() == AndroidGeckoEvent::ACTION_GAMEPAD_AXES) {
int valid = curEvent->Flags();
const nsTArray<float>& values = curEvent->GamepadValues();
for (unsigned i = 0; i < values.Length(); i++) {
if (valid & (1<<i)) {
service->NewAxisMoveEvent(id, i, values[i]);
}
}
}
#endif
break;
}
case AndroidGeckoEvent::NOOP:
break;