Bug 742036 - Part 1: Convert Android keycodes to DOM/NS_VK keycodes. r=masayuki a=blocking-fennec

--HG--
extra : rebase_source : 8c8e8fbf4dd6bd0bfc67e621a1f24788d93ec5b1
This commit is contained in:
Chris Peterson 2012-04-18 10:15:15 -07:00
Родитель 4c0d3ee791
Коммит 2d52c71db6
2 изменённых файлов: 223 добавлений и 154 удалений

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

@ -360,15 +360,137 @@ public:
KEYCODE_MEDIA_REWIND = 89,
KEYCODE_MEDIA_FAST_FORWARD = 90,
KEYCODE_MUTE = 91,
KEYCODE_PAGE_UP = 92,
KEYCODE_PAGE_DOWN = 93,
KEYCODE_PICTSYMBOLS = 94,
KEYCODE_SWITCH_CHARSET = 95,
KEYCODE_BUTTON_A = 96,
KEYCODE_BUTTON_B = 97,
KEYCODE_BUTTON_C = 98,
KEYCODE_BUTTON_X = 99,
KEYCODE_BUTTON_Y = 100,
KEYCODE_BUTTON_Z = 101,
KEYCODE_BUTTON_L1 = 102,
KEYCODE_BUTTON_R1 = 103,
KEYCODE_BUTTON_L2 = 104,
KEYCODE_BUTTON_R2 = 105,
KEYCODE_BUTTON_THUMBL = 106,
KEYCODE_BUTTON_THUMBR = 107,
KEYCODE_BUTTON_START = 108,
KEYCODE_BUTTON_SELECT = 109,
KEYCODE_BUTTON_MODE = 110,
KEYCODE_ESCAPE = 111,
KEYCODE_FORWARD_DEL = 112,
KEYCODE_CTRL_LEFT = 113,
KEYCODE_CTRL_RIGHT = 114,
KEYCODE_CAPS_LOCK = 115,
KEYCODE_SCROLL_LOCK = 116,
KEYCODE_META_LEFT = 117,
KEYCODE_META_RIGHT = 118,
KEYCODE_FUNCTION = 119,
KEYCODE_SYSRQ = 120,
KEYCODE_BREAK = 121,
KEYCODE_MOVE_HOME = 122,
KEYCODE_MOVE_END = 123,
KEYCODE_INSERT = 124,
KEYCODE_FORWARD = 125,
KEYCODE_MEDIA_PLAY = 126,
KEYCODE_MEDIA_PAUSE = 127,
KEYCODE_MEDIA_CLOSE = 128,
KEYCODE_MEDIA_EJECT = 129,
KEYCODE_MEDIA_RECORD = 130,
KEYCODE_F1 = 131,
KEYCODE_F2 = 132,
KEYCODE_F3 = 133,
KEYCODE_F4 = 134,
KEYCODE_F5 = 135,
KEYCODE_F6 = 136,
KEYCODE_F7 = 137,
KEYCODE_F8 = 138,
KEYCODE_F9 = 139,
KEYCODE_F10 = 140,
KEYCODE_F11 = 141,
KEYCODE_F12 = 142,
KEYCODE_NUM_LOCK = 143,
KEYCODE_NUMPAD_0 = 144,
KEYCODE_NUMPAD_1 = 145,
KEYCODE_NUMPAD_2 = 146,
KEYCODE_NUMPAD_3 = 147,
KEYCODE_NUMPAD_4 = 148,
KEYCODE_NUMPAD_5 = 149,
KEYCODE_NUMPAD_6 = 150,
KEYCODE_NUMPAD_7 = 151,
KEYCODE_NUMPAD_8 = 152,
KEYCODE_NUMPAD_9 = 153,
KEYCODE_NUMPAD_DIVIDE = 154,
KEYCODE_NUMPAD_MULTIPLY = 155,
KEYCODE_NUMPAD_SUBTRACT = 156,
KEYCODE_NUMPAD_ADD = 157,
KEYCODE_NUMPAD_DOT = 158,
KEYCODE_NUMPAD_COMMA = 159,
KEYCODE_NUMPAD_ENTER = 160,
KEYCODE_NUMPAD_EQUALS = 161,
KEYCODE_NUMPAD_LEFT_PAREN = 162,
KEYCODE_NUMPAD_RIGHT_PAREN = 163,
KEYCODE_VOLUME_MUTE = 164,
KEYCODE_INFO = 165,
KEYCODE_CHANNEL_UP = 166,
KEYCODE_CHANNEL_DOWN = 167,
KEYCODE_ZOOM_IN = 168,
KEYCODE_ZOOM_OUT = 169,
KEYCODE_TV = 170,
KEYCODE_WINDOW = 171,
KEYCODE_GUIDE = 172,
KEYCODE_DVR = 173,
KEYCODE_BOOKMARK = 174,
KEYCODE_CAPTIONS = 175,
KEYCODE_SETTINGS = 176,
KEYCODE_TV_POWER = 177,
KEYCODE_TV_INPUT = 178,
KEYCODE_STB_POWER = 179,
KEYCODE_STB_INPUT = 180,
KEYCODE_AVR_POWER = 181,
KEYCODE_AVR_INPUT = 182,
KEYCODE_PROG_RED = 183,
KEYCODE_PROG_GREEN = 184,
KEYCODE_PROG_YELLOW = 185,
KEYCODE_PROG_BLUE = 186,
KEYCODE_APP_SWITCH = 187,
KEYCODE_BUTTON_1 = 188,
KEYCODE_BUTTON_2 = 189,
KEYCODE_BUTTON_3 = 190,
KEYCODE_BUTTON_4 = 191,
KEYCODE_BUTTON_5 = 192,
KEYCODE_BUTTON_6 = 193,
KEYCODE_BUTTON_7 = 194,
KEYCODE_BUTTON_8 = 195,
KEYCODE_BUTTON_9 = 196,
KEYCODE_BUTTON_10 = 197,
KEYCODE_BUTTON_11 = 198,
KEYCODE_BUTTON_12 = 199,
KEYCODE_BUTTON_13 = 200,
KEYCODE_BUTTON_14 = 201,
KEYCODE_BUTTON_15 = 202,
KEYCODE_BUTTON_16 = 203,
KEYCODE_LANGUAGE_SWITCH = 204,
KEYCODE_MANNER_MODE = 205,
KEYCODE_3D_MODE = 206,
KEYCODE_CONTACTS = 207,
KEYCODE_CALENDAR = 208,
KEYCODE_MUSIC = 209,
KEYCODE_CALCULATOR = 210,
ACTION_DOWN = 0,
ACTION_UP = 1,
ACTION_MULTIPLE = 2,
META_ALT_ON = 0x00000002,
META_ALT_LEFT_ON = 0x00000010,
META_ALT_RIGHT_ON = 0x00000020,
META_ALT_MASK = META_ALT_RIGHT_ON | META_ALT_LEFT_ON | META_ALT_ON,
META_SHIFT_ON = 0x00000001,
META_SHIFT_LEFT_ON = 0x00000040,
META_SHIFT_RIGHT_ON = 0x00000080,
META_SHIFT_MASK = META_SHIFT_RIGHT_ON | META_SHIFT_LEFT_ON | META_SHIFT_ON,
META_SYM_ON = 0x00000004,
FLAG_WOKE_HERE = 0x00000001,
FLAG_SOFT_KEYBOARD = 0x00000002,
@ -471,6 +593,8 @@ public:
nsAString& CharactersExtra() { return mCharactersExtra; }
int KeyCode() { return mKeyCode; }
int MetaState() { return mMetaState; }
bool IsAltPressed() const { return (mMetaState & AndroidKeyEvent::META_ALT_MASK) != 0; }
bool IsShiftPressed() const { return (mMetaState & AndroidKeyEvent::META_SHIFT_MASK) != 0; }
int Flags() { return mFlags; }
int UnicodeChar() { return mUnicodeChar; }
int Offset() { return mOffset; }

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

@ -1609,163 +1609,108 @@ nsWindow::DispatchMotionEvent(nsInputEvent &event, AndroidGeckoEvent *ae,
DispatchEvent(&event);
}
static unsigned int ConvertAndroidKeyCodeToDOMKeyCode(int androidKeyCode)
{
// Special-case alphanumeric keycodes because they are most common.
if (androidKeyCode >= AndroidKeyEvent::KEYCODE_A &&
androidKeyCode <= AndroidKeyEvent::KEYCODE_Z) {
return androidKeyCode - AndroidKeyEvent::KEYCODE_A + NS_VK_A;
}
if (androidKeyCode >= AndroidKeyEvent::KEYCODE_0 &&
androidKeyCode <= AndroidKeyEvent::KEYCODE_9) {
return androidKeyCode - AndroidKeyEvent::KEYCODE_0 + NS_VK_0;
}
switch (androidKeyCode) {
// KEYCODE_UNKNOWN (0) ... KEYCODE_POUND (18)
case AndroidKeyEvent::KEYCODE_DPAD_UP: return NS_VK_UP;
case AndroidKeyEvent::KEYCODE_DPAD_DOWN: return NS_VK_DOWN;
case AndroidKeyEvent::KEYCODE_DPAD_LEFT: return NS_VK_LEFT;
case AndroidKeyEvent::KEYCODE_DPAD_RIGHT: return NS_VK_RIGHT;
case AndroidKeyEvent::KEYCODE_DPAD_CENTER: return NS_VK_RETURN;
// KEYCODE_VOLUME_UP (24) ... KEYCODE_Z (54)
case AndroidKeyEvent::KEYCODE_COMMA: return NS_VK_COMMA;
case AndroidKeyEvent::KEYCODE_PERIOD: return NS_VK_PERIOD;
case AndroidKeyEvent::KEYCODE_ALT_LEFT: return NS_VK_ALT;
case AndroidKeyEvent::KEYCODE_ALT_RIGHT: return NS_VK_ALT;
case AndroidKeyEvent::KEYCODE_SHIFT_LEFT: return NS_VK_SHIFT;
case AndroidKeyEvent::KEYCODE_SHIFT_RIGHT: return NS_VK_SHIFT;
case AndroidKeyEvent::KEYCODE_TAB: return NS_VK_TAB;
case AndroidKeyEvent::KEYCODE_SPACE: return NS_VK_SPACE;
// KEYCODE_SYM (63) ... KEYCODE_ENVELOPE (65)
case AndroidKeyEvent::KEYCODE_ENTER: return NS_VK_RETURN;
case AndroidKeyEvent::KEYCODE_DEL: return NS_VK_BACK; // Backspace
case AndroidKeyEvent::KEYCODE_GRAVE: return NS_VK_BACK_QUOTE;
// KEYCODE_MINUS (69)
case AndroidKeyEvent::KEYCODE_EQUALS: return NS_VK_EQUALS;
case AndroidKeyEvent::KEYCODE_LEFT_BRACKET: return NS_VK_OPEN_BRACKET;
case AndroidKeyEvent::KEYCODE_RIGHT_BRACKET: return NS_VK_CLOSE_BRACKET;
case AndroidKeyEvent::KEYCODE_BACKSLASH: return NS_VK_BACK_SLASH;
case AndroidKeyEvent::KEYCODE_SEMICOLON: return NS_VK_SEMICOLON;
// KEYCODE_APOSTROPHE (75)
case AndroidKeyEvent::KEYCODE_SLASH: return NS_VK_SLASH;
// KEYCODE_AT (77) ... KEYCODE_MUTE (91)
case AndroidKeyEvent::KEYCODE_PAGE_UP: return NS_VK_PAGE_UP;
case AndroidKeyEvent::KEYCODE_PAGE_DOWN: return NS_VK_PAGE_DOWN;
// KEYCODE_PICTSYMBOLS (94) ... KEYCODE_BUTTON_MODE (110)
case AndroidKeyEvent::KEYCODE_ESCAPE: return NS_VK_ESCAPE;
case AndroidKeyEvent::KEYCODE_FORWARD_DEL: return NS_VK_DELETE;
case AndroidKeyEvent::KEYCODE_CTRL_LEFT: return NS_VK_CONTROL;
case AndroidKeyEvent::KEYCODE_CTRL_RIGHT: return NS_VK_CONTROL;
case AndroidKeyEvent::KEYCODE_CAPS_LOCK: return NS_VK_CAPS_LOCK;
case AndroidKeyEvent::KEYCODE_SCROLL_LOCK: return NS_VK_SCROLL_LOCK;
// KEYCODE_META_LEFT (117) ... KEYCODE_FUNCTION (119)
case AndroidKeyEvent::KEYCODE_SYSRQ: return NS_VK_PRINTSCREEN;
case AndroidKeyEvent::KEYCODE_BREAK: return NS_VK_PAUSE;
case AndroidKeyEvent::KEYCODE_MOVE_HOME: return NS_VK_HOME;
case AndroidKeyEvent::KEYCODE_MOVE_END: return NS_VK_END;
case AndroidKeyEvent::KEYCODE_INSERT: return NS_VK_INSERT;
// KEYCODE_FORWARD (125) ... KEYCODE_MEDIA_RECORD (130)
case AndroidKeyEvent::KEYCODE_F1: return NS_VK_F1;
case AndroidKeyEvent::KEYCODE_F2: return NS_VK_F2;
case AndroidKeyEvent::KEYCODE_F3: return NS_VK_F3;
case AndroidKeyEvent::KEYCODE_F4: return NS_VK_F4;
case AndroidKeyEvent::KEYCODE_F5: return NS_VK_F5;
case AndroidKeyEvent::KEYCODE_F6: return NS_VK_F6;
case AndroidKeyEvent::KEYCODE_F7: return NS_VK_F7;
case AndroidKeyEvent::KEYCODE_F8: return NS_VK_F8;
case AndroidKeyEvent::KEYCODE_F9: return NS_VK_F9;
case AndroidKeyEvent::KEYCODE_F10: return NS_VK_F10;
case AndroidKeyEvent::KEYCODE_F11: return NS_VK_F11;
case AndroidKeyEvent::KEYCODE_F12: return NS_VK_F12;
case AndroidKeyEvent::KEYCODE_NUM_LOCK: return NS_VK_NUM_LOCK;
case AndroidKeyEvent::KEYCODE_NUMPAD_0: return NS_VK_NUMPAD0;
case AndroidKeyEvent::KEYCODE_NUMPAD_1: return NS_VK_NUMPAD1;
case AndroidKeyEvent::KEYCODE_NUMPAD_2: return NS_VK_NUMPAD2;
case AndroidKeyEvent::KEYCODE_NUMPAD_3: return NS_VK_NUMPAD3;
case AndroidKeyEvent::KEYCODE_NUMPAD_4: return NS_VK_NUMPAD4;
case AndroidKeyEvent::KEYCODE_NUMPAD_5: return NS_VK_NUMPAD5;
case AndroidKeyEvent::KEYCODE_NUMPAD_6: return NS_VK_NUMPAD6;
case AndroidKeyEvent::KEYCODE_NUMPAD_7: return NS_VK_NUMPAD7;
case AndroidKeyEvent::KEYCODE_NUMPAD_8: return NS_VK_NUMPAD8;
case AndroidKeyEvent::KEYCODE_NUMPAD_9: return NS_VK_NUMPAD9;
case AndroidKeyEvent::KEYCODE_NUMPAD_DIVIDE: return NS_VK_DIVIDE;
case AndroidKeyEvent::KEYCODE_NUMPAD_MULTIPLY: return NS_VK_MULTIPLY;
case AndroidKeyEvent::KEYCODE_NUMPAD_SUBTRACT: return NS_VK_SUBTRACT;
case AndroidKeyEvent::KEYCODE_NUMPAD_ADD: return NS_VK_ADD;
case AndroidKeyEvent::KEYCODE_NUMPAD_DOT: return NS_VK_DECIMAL;
case AndroidKeyEvent::KEYCODE_NUMPAD_COMMA: return NS_VK_SEPARATOR;
case AndroidKeyEvent::KEYCODE_NUMPAD_ENTER: return NS_VK_RETURN;
case AndroidKeyEvent::KEYCODE_NUMPAD_EQUALS: return NS_VK_EQUALS;
// KEYCODE_NUMPAD_LEFT_PAREN (162) ... KEYCODE_CALCULATOR (210)
default:
ALOG("ConvertAndroidKeyCodeToDOMKeyCode: "
"No DOM keycode for Android keycode %d", androidKeyCode);
return 0;
}
}
void
nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key)
{
switch (key.KeyCode()) {
case AndroidKeyEvent::KEYCODE_UNKNOWN:
case AndroidKeyEvent::KEYCODE_HOME:
break;
case AndroidKeyEvent::KEYCODE_BACK:
event.keyCode = NS_VK_ESCAPE;
break;
case AndroidKeyEvent::KEYCODE_CALL:
case AndroidKeyEvent::KEYCODE_ENDCALL:
break;
case AndroidKeyEvent::KEYCODE_0:
case AndroidKeyEvent::KEYCODE_1:
case AndroidKeyEvent::KEYCODE_2:
case AndroidKeyEvent::KEYCODE_3:
case AndroidKeyEvent::KEYCODE_4:
case AndroidKeyEvent::KEYCODE_5:
case AndroidKeyEvent::KEYCODE_6:
case AndroidKeyEvent::KEYCODE_7:
case AndroidKeyEvent::KEYCODE_8:
case AndroidKeyEvent::KEYCODE_9:
event.keyCode = key.KeyCode() - AndroidKeyEvent::KEYCODE_0 + NS_VK_0;
break;
case AndroidKeyEvent::KEYCODE_STAR:
event.keyCode = NS_VK_MULTIPLY;
break;
case AndroidKeyEvent::KEYCODE_POUND:
break;
case AndroidKeyEvent::KEYCODE_DPAD_UP:
event.keyCode = NS_VK_UP;
break;
case AndroidKeyEvent::KEYCODE_DPAD_DOWN:
event.keyCode = NS_VK_DOWN;
break;
case AndroidKeyEvent::KEYCODE_SOFT_LEFT:
case AndroidKeyEvent::KEYCODE_DPAD_LEFT:
event.keyCode = NS_VK_LEFT;
break;
case AndroidKeyEvent::KEYCODE_SOFT_RIGHT:
case AndroidKeyEvent::KEYCODE_DPAD_RIGHT:
event.keyCode = NS_VK_RIGHT;
break;
case AndroidKeyEvent::KEYCODE_VOLUME_UP:
case AndroidKeyEvent::KEYCODE_VOLUME_DOWN:
case AndroidKeyEvent::KEYCODE_POWER:
case AndroidKeyEvent::KEYCODE_CAMERA:
case AndroidKeyEvent::KEYCODE_CLEAR:
break;
case AndroidKeyEvent::KEYCODE_A:
case AndroidKeyEvent::KEYCODE_B:
case AndroidKeyEvent::KEYCODE_C:
case AndroidKeyEvent::KEYCODE_D:
case AndroidKeyEvent::KEYCODE_E:
case AndroidKeyEvent::KEYCODE_F:
case AndroidKeyEvent::KEYCODE_G:
case AndroidKeyEvent::KEYCODE_H:
case AndroidKeyEvent::KEYCODE_I:
case AndroidKeyEvent::KEYCODE_J:
case AndroidKeyEvent::KEYCODE_K:
case AndroidKeyEvent::KEYCODE_L:
case AndroidKeyEvent::KEYCODE_M:
case AndroidKeyEvent::KEYCODE_N:
case AndroidKeyEvent::KEYCODE_O:
case AndroidKeyEvent::KEYCODE_P:
case AndroidKeyEvent::KEYCODE_Q:
case AndroidKeyEvent::KEYCODE_R:
case AndroidKeyEvent::KEYCODE_S:
case AndroidKeyEvent::KEYCODE_T:
case AndroidKeyEvent::KEYCODE_U:
case AndroidKeyEvent::KEYCODE_V:
case AndroidKeyEvent::KEYCODE_W:
case AndroidKeyEvent::KEYCODE_X:
case AndroidKeyEvent::KEYCODE_Y:
case AndroidKeyEvent::KEYCODE_Z:
event.keyCode = key.KeyCode() - AndroidKeyEvent::KEYCODE_A + NS_VK_A;
break;
case AndroidKeyEvent::KEYCODE_COMMA:
event.keyCode = NS_VK_COMMA;
break;
case AndroidKeyEvent::KEYCODE_PERIOD:
event.keyCode = NS_VK_PERIOD;
break;
case AndroidKeyEvent::KEYCODE_ALT_LEFT:
case AndroidKeyEvent::KEYCODE_ALT_RIGHT:
case AndroidKeyEvent::KEYCODE_SHIFT_LEFT:
case AndroidKeyEvent::KEYCODE_SHIFT_RIGHT:
break;
case AndroidKeyEvent::KEYCODE_TAB:
event.keyCode = NS_VK_TAB;
break;
case AndroidKeyEvent::KEYCODE_SPACE:
event.keyCode = NS_VK_SPACE;
break;
case AndroidKeyEvent::KEYCODE_SYM:
case AndroidKeyEvent::KEYCODE_EXPLORER:
case AndroidKeyEvent::KEYCODE_ENVELOPE:
break;
case AndroidKeyEvent::KEYCODE_DPAD_CENTER:
event.keyCode = NS_VK_ENTER;
break;
case AndroidKeyEvent::KEYCODE_ENTER:
event.keyCode = NS_VK_RETURN;
break;
case AndroidKeyEvent::KEYCODE_DEL:
event.keyCode = NS_VK_BACK;
break;
case AndroidKeyEvent::KEYCODE_GRAVE:
break;
case AndroidKeyEvent::KEYCODE_MINUS:
event.keyCode = NS_VK_SUBTRACT;
break;
case AndroidKeyEvent::KEYCODE_EQUALS:
event.keyCode = NS_VK_EQUALS;
break;
case AndroidKeyEvent::KEYCODE_LEFT_BRACKET:
event.keyCode = NS_VK_OPEN_BRACKET;
break;
case AndroidKeyEvent::KEYCODE_RIGHT_BRACKET:
event.keyCode = NS_VK_CLOSE_BRACKET;
break;
case AndroidKeyEvent::KEYCODE_BACKSLASH:
event.keyCode = NS_VK_BACK_SLASH;
break;
case AndroidKeyEvent::KEYCODE_SEMICOLON:
event.keyCode = NS_VK_SEMICOLON;
break;
case AndroidKeyEvent::KEYCODE_APOSTROPHE:
event.keyCode = NS_VK_QUOTE;
break;
case AndroidKeyEvent::KEYCODE_SLASH:
event.keyCode = NS_VK_SLASH;
break;
case AndroidKeyEvent::KEYCODE_AT:
case AndroidKeyEvent::KEYCODE_NUM:
case AndroidKeyEvent::KEYCODE_HEADSETHOOK:
case AndroidKeyEvent::KEYCODE_FOCUS:
break;
case AndroidKeyEvent::KEYCODE_PLUS:
event.keyCode = NS_VK_ADD;
break;
case AndroidKeyEvent::KEYCODE_MENU:
case AndroidKeyEvent::KEYCODE_NOTIFICATION:
case AndroidKeyEvent::KEYCODE_SEARCH:
case AndroidKeyEvent::KEYCODE_MEDIA_PLAY_PAUSE:
case AndroidKeyEvent::KEYCODE_MEDIA_STOP:
case AndroidKeyEvent::KEYCODE_MEDIA_NEXT:
case AndroidKeyEvent::KEYCODE_MEDIA_PREVIOUS:
case AndroidKeyEvent::KEYCODE_MEDIA_REWIND:
case AndroidKeyEvent::KEYCODE_MEDIA_FAST_FORWARD:
case AndroidKeyEvent::KEYCODE_MUTE:
break;
default:
ALOG("Unknown key code!");
break;
}
event.keyCode = ConvertAndroidKeyCodeToDOMKeyCode(key.KeyCode());
// Android gives us \n, so filter out some control characters.
if (event.message == NS_KEY_PRESS &&