mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 13:07:52 +00:00
Bug 792645 - Unify duplicated codes between mobile/android/base/GeckoEvent.java and embedding/android/GeckoEvent.java. r=cpeterson
This commit is contained in:
parent
5b69de0f54
commit
be77bde346
@ -51,6 +51,17 @@ public class GeckoEvent {
|
||||
public static final int PROXIMITY_EVENT = 23;
|
||||
public static final int SCREENORIENTATION_CHANGED = 26;
|
||||
|
||||
/**
|
||||
* These DOM_KEY_LOCATION constants mirror the DOM KeyboardEvent's constants.
|
||||
* @see https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent#Key_location_constants
|
||||
*/
|
||||
private static final int DOM_KEY_LOCATION_STANDARD = 0;
|
||||
private static final int DOM_KEY_LOCATION_LEFT = 1;
|
||||
private static final int DOM_KEY_LOCATION_RIGHT = 2;
|
||||
private static final int DOM_KEY_LOCATION_NUMPAD = 3;
|
||||
private static final int DOM_KEY_LOCATION_MOBILE = 4;
|
||||
private static final int DOM_KEY_LOCATION_JOYSTICK = 5;
|
||||
|
||||
public static final int IME_COMPOSITION_END = 0;
|
||||
public static final int IME_COMPOSITION_BEGIN = 1;
|
||||
public static final int IME_SET_TEXT = 2;
|
||||
@ -93,6 +104,7 @@ public class GeckoEvent {
|
||||
public int mRangeForeColor, mRangeBackColor;
|
||||
public Location mLocation;
|
||||
public Address mAddress;
|
||||
public int mDomKeyLocation;
|
||||
|
||||
public double mBandwidth;
|
||||
public boolean mCanBeMetered;
|
||||
@ -121,8 +133,76 @@ public class GeckoEvent {
|
||||
mUnicodeChar = k.getUnicodeChar();
|
||||
mRepeatCount = k.getRepeatCount();
|
||||
mCharacters = k.getCharacters();
|
||||
mDomKeyLocation = isJoystickButton(mKeyCode) ? DOM_KEY_LOCATION_JOYSTICK : DOM_KEY_LOCATION_MOBILE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tests if a key is one of the described in:
|
||||
* https://bugzilla.mozilla.org/show_bug.cgi?id=756504#c0
|
||||
* @param keyCode int with the key code (Android key constant from KeyEvent)
|
||||
* @return true if the key is one of the listed above, false otherwise.
|
||||
*/
|
||||
private static boolean isJoystickButton(int keyCode) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
return true;
|
||||
default:
|
||||
if (Build.VERSION.SDK_INT >= 12) {
|
||||
return KeyEvent.isGamepadButton(keyCode);
|
||||
}
|
||||
return GeckoEvent.isGamepadButton(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is a replacement for the the KeyEvent.isGamepadButton method to be
|
||||
* compatible with Build.VERSION.SDK_INT < 12. This is an implementantion 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 GeckoEvent(MotionEvent m) {
|
||||
mType = MOTION_EVENT;
|
||||
mAction = m.getAction();
|
||||
|
Loading…
x
Reference in New Issue
Block a user