michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include "mozilla/ArrayUtils.h" michael@0: #include "mozilla/TextEvents.h" michael@0: michael@0: #include "nsWindow.h" michael@0: #include "nsQtKeyUtils.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::widget; michael@0: michael@0: struct nsKeyConverter michael@0: { michael@0: int vkCode; // Platform independent key code michael@0: int keysym; // Qt key code michael@0: }; michael@0: michael@0: static struct nsKeyConverter nsKeycodes[] = michael@0: { michael@0: // { NS_VK_CANCEL, Qt::Key_Cancel }, michael@0: { NS_VK_BACK, Qt::Key_Backspace }, michael@0: { NS_VK_TAB, Qt::Key_Tab }, michael@0: { NS_VK_TAB, Qt::Key_Backtab }, michael@0: // { NS_VK_CLEAR, Qt::Key_Clear }, michael@0: { NS_VK_RETURN, Qt::Key_Return }, michael@0: { NS_VK_RETURN, Qt::Key_Enter }, michael@0: { NS_VK_SHIFT, Qt::Key_Shift }, michael@0: { NS_VK_CONTROL, Qt::Key_Control }, michael@0: { NS_VK_ALT, Qt::Key_Alt }, michael@0: { NS_VK_PAUSE, Qt::Key_Pause }, michael@0: { NS_VK_CAPS_LOCK, Qt::Key_CapsLock }, michael@0: { NS_VK_ESCAPE, Qt::Key_Escape }, michael@0: { NS_VK_SPACE, Qt::Key_Space }, michael@0: { NS_VK_PAGE_UP, Qt::Key_PageUp }, michael@0: { NS_VK_PAGE_DOWN, Qt::Key_PageDown }, michael@0: { NS_VK_END, Qt::Key_End }, michael@0: { NS_VK_HOME, Qt::Key_Home }, michael@0: { NS_VK_LEFT, Qt::Key_Left }, michael@0: { NS_VK_UP, Qt::Key_Up }, michael@0: { NS_VK_RIGHT, Qt::Key_Right }, michael@0: { NS_VK_DOWN, Qt::Key_Down }, michael@0: { NS_VK_PRINTSCREEN, Qt::Key_Print }, michael@0: { NS_VK_INSERT, Qt::Key_Insert }, michael@0: { NS_VK_DELETE, Qt::Key_Delete }, michael@0: { NS_VK_HELP, Qt::Key_Help }, michael@0: michael@0: { NS_VK_0, Qt::Key_0 }, michael@0: { NS_VK_1, Qt::Key_1 }, michael@0: { NS_VK_2, Qt::Key_2 }, michael@0: { NS_VK_3, Qt::Key_3 }, michael@0: { NS_VK_4, Qt::Key_4 }, michael@0: { NS_VK_5, Qt::Key_5 }, michael@0: { NS_VK_6, Qt::Key_6 }, michael@0: { NS_VK_7, Qt::Key_7 }, michael@0: { NS_VK_8, Qt::Key_8 }, michael@0: { NS_VK_9, Qt::Key_9 }, michael@0: michael@0: { NS_VK_SEMICOLON, Qt::Key_Semicolon }, michael@0: { NS_VK_EQUALS, Qt::Key_Equal }, michael@0: michael@0: { NS_VK_A, Qt::Key_A }, michael@0: { NS_VK_B, Qt::Key_B }, michael@0: { NS_VK_C, Qt::Key_C }, michael@0: { NS_VK_D, Qt::Key_D }, michael@0: { NS_VK_E, Qt::Key_E }, michael@0: { NS_VK_F, Qt::Key_F }, michael@0: { NS_VK_G, Qt::Key_G }, michael@0: { NS_VK_H, Qt::Key_H }, michael@0: { NS_VK_I, Qt::Key_I }, michael@0: { NS_VK_J, Qt::Key_J }, michael@0: { NS_VK_K, Qt::Key_K }, michael@0: { NS_VK_L, Qt::Key_L }, michael@0: { NS_VK_M, Qt::Key_M }, michael@0: { NS_VK_N, Qt::Key_N }, michael@0: { NS_VK_O, Qt::Key_O }, michael@0: { NS_VK_P, Qt::Key_P }, michael@0: { NS_VK_Q, Qt::Key_Q }, michael@0: { NS_VK_R, Qt::Key_R }, michael@0: { NS_VK_S, Qt::Key_S }, michael@0: { NS_VK_T, Qt::Key_T }, michael@0: { NS_VK_U, Qt::Key_U }, michael@0: { NS_VK_V, Qt::Key_V }, michael@0: { NS_VK_W, Qt::Key_W }, michael@0: { NS_VK_X, Qt::Key_X }, michael@0: { NS_VK_Y, Qt::Key_Y }, michael@0: { NS_VK_Z, Qt::Key_Z }, michael@0: michael@0: { NS_VK_NUMPAD0, Qt::Key_0 }, michael@0: { NS_VK_NUMPAD1, Qt::Key_1 }, michael@0: { NS_VK_NUMPAD2, Qt::Key_2 }, michael@0: { NS_VK_NUMPAD3, Qt::Key_3 }, michael@0: { NS_VK_NUMPAD4, Qt::Key_4 }, michael@0: { NS_VK_NUMPAD5, Qt::Key_5 }, michael@0: { NS_VK_NUMPAD6, Qt::Key_6 }, michael@0: { NS_VK_NUMPAD7, Qt::Key_7 }, michael@0: { NS_VK_NUMPAD8, Qt::Key_8 }, michael@0: { NS_VK_NUMPAD9, Qt::Key_9 }, michael@0: { NS_VK_MULTIPLY, Qt::Key_Asterisk }, michael@0: { NS_VK_ADD, Qt::Key_Plus }, michael@0: // { NS_VK_SEPARATOR, Qt::Key_Separator }, michael@0: { NS_VK_SUBTRACT, Qt::Key_Minus }, michael@0: { NS_VK_DECIMAL, Qt::Key_Period }, michael@0: { NS_VK_DIVIDE, Qt::Key_Slash }, michael@0: { NS_VK_F1, Qt::Key_F1 }, michael@0: { NS_VK_F2, Qt::Key_F2 }, michael@0: { NS_VK_F3, Qt::Key_F3 }, michael@0: { NS_VK_F4, Qt::Key_F4 }, michael@0: { NS_VK_F5, Qt::Key_F5 }, michael@0: { NS_VK_F6, Qt::Key_F6 }, michael@0: { NS_VK_F7, Qt::Key_F7 }, michael@0: { NS_VK_F8, Qt::Key_F8 }, michael@0: { NS_VK_F9, Qt::Key_F9 }, michael@0: { NS_VK_F10, Qt::Key_F10 }, michael@0: { NS_VK_F11, Qt::Key_F11 }, michael@0: { NS_VK_F12, Qt::Key_F12 }, michael@0: { NS_VK_F13, Qt::Key_F13 }, michael@0: { NS_VK_F14, Qt::Key_F14 }, michael@0: { NS_VK_F15, Qt::Key_F15 }, michael@0: { NS_VK_F16, Qt::Key_F16 }, michael@0: { NS_VK_F17, Qt::Key_F17 }, michael@0: { NS_VK_F18, Qt::Key_F18 }, michael@0: { NS_VK_F19, Qt::Key_F19 }, michael@0: { NS_VK_F20, Qt::Key_F20 }, michael@0: { NS_VK_F21, Qt::Key_F21 }, michael@0: { NS_VK_F22, Qt::Key_F22 }, michael@0: { NS_VK_F23, Qt::Key_F23 }, michael@0: { NS_VK_F24, Qt::Key_F24 }, michael@0: michael@0: { NS_VK_NUM_LOCK, Qt::Key_NumLock }, michael@0: { NS_VK_SCROLL_LOCK, Qt::Key_ScrollLock }, michael@0: michael@0: { NS_VK_COMMA, Qt::Key_Comma }, michael@0: { NS_VK_PERIOD, Qt::Key_Period }, michael@0: { NS_VK_SLASH, Qt::Key_Slash }, michael@0: { NS_VK_BACK_QUOTE, Qt::Key_QuoteLeft }, michael@0: { NS_VK_OPEN_BRACKET, Qt::Key_ParenLeft }, michael@0: { NS_VK_CLOSE_BRACKET, Qt::Key_ParenRight }, michael@0: { NS_VK_QUOTE, Qt::Key_QuoteDbl }, michael@0: michael@0: { NS_VK_META, Qt::Key_Meta } michael@0: }; michael@0: michael@0: int michael@0: QtKeyCodeToDOMKeyCode(int aKeysym) michael@0: { michael@0: unsigned int i; michael@0: michael@0: // First, try to handle alphanumeric input, not listed in nsKeycodes: michael@0: // most likely, more letters will be getting typed in than things in michael@0: // the key list, so we will look through these first. michael@0: michael@0: // since X has different key symbols for upper and lowercase letters and michael@0: // mozilla does not, convert gdk's to mozilla's michael@0: if (aKeysym >= Qt::Key_A && aKeysym <= Qt::Key_Z) michael@0: return aKeysym - Qt::Key_A + NS_VK_A; michael@0: michael@0: // numbers michael@0: if (aKeysym >= Qt::Key_0 && aKeysym <= Qt::Key_9) michael@0: return aKeysym - Qt::Key_0 + NS_VK_0; michael@0: michael@0: // keypad numbers michael@0: // if (aKeysym >= Qt::Key_KP_0 && aKeysym <= Qt::Key_KP_9) michael@0: // return aKeysym - Qt::Key_KP_0 + NS_VK_NUMPAD0; michael@0: michael@0: // misc other things michael@0: for (i = 0; i < ArrayLength(nsKeycodes); i++) { michael@0: if (nsKeycodes[i].keysym == aKeysym) michael@0: return(nsKeycodes[i].vkCode); michael@0: } michael@0: michael@0: // function keys michael@0: if (aKeysym >= Qt::Key_F1 && aKeysym <= Qt::Key_F24) michael@0: return aKeysym - Qt::Key_F1 + NS_VK_F1; michael@0: michael@0: return((int)0); michael@0: } michael@0: michael@0: int michael@0: DOMKeyCodeToQtKeyCode(int aKeysym) michael@0: { michael@0: unsigned int i; michael@0: michael@0: // First, try to handle alphanumeric input, not listed in nsKeycodes: michael@0: // most likely, more letters will be getting typed in than things in michael@0: // the key list, so we will look through these first. michael@0: michael@0: if (aKeysym >= NS_VK_A && aKeysym <= NS_VK_Z) michael@0: // gdk and DOM both use the ASCII codes for these keys. michael@0: return aKeysym; michael@0: michael@0: // numbers michael@0: if (aKeysym >= NS_VK_0 && aKeysym <= NS_VK_9) michael@0: // gdk and DOM both use the ASCII codes for these keys. michael@0: return aKeysym - Qt::Key_0 + NS_VK_0; michael@0: michael@0: // keypad numbers michael@0: if (aKeysym >= NS_VK_NUMPAD0 && aKeysym <= NS_VK_NUMPAD9) { michael@0: NS_ERROR("keypad numbers conversion not implemented"); michael@0: //return aKeysym - NS_VK_NUMPAD0 + Qt::Key_KP_0; michael@0: return 0; michael@0: } michael@0: michael@0: // misc other things michael@0: for (i = 0; i < ArrayLength(nsKeycodes); ++i) { michael@0: if (nsKeycodes[i].vkCode == aKeysym) { michael@0: return nsKeycodes[i].keysym; michael@0: } michael@0: } michael@0: michael@0: // function keys michael@0: if (aKeysym >= NS_VK_F1 && aKeysym <= NS_VK_F9) michael@0: return aKeysym - NS_VK_F1 + Qt::Key_F1; michael@0: michael@0: return 0; michael@0: } michael@0: michael@0: KeyNameIndex michael@0: QtKeyCodeToDOMKeyNameIndex(int aKeysym) michael@0: { michael@0: switch (aKeysym) { michael@0: michael@0: #define NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex) \ michael@0: case aNativeKey: return aKeyNameIndex; michael@0: michael@0: #include "NativeKeyToDOMKeyName.h" michael@0: michael@0: #undef NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX michael@0: michael@0: case Qt::Key_Exclam: michael@0: case Qt::Key_QuoteDbl: michael@0: case Qt::Key_NumberSign: michael@0: case Qt::Key_Dollar: michael@0: case Qt::Key_Percent: michael@0: case Qt::Key_Ampersand: michael@0: case Qt::Key_Apostrophe: michael@0: case Qt::Key_ParenLeft: michael@0: case Qt::Key_ParenRight: michael@0: case Qt::Key_Asterisk: michael@0: case Qt::Key_Plus: michael@0: case Qt::Key_Comma: michael@0: case Qt::Key_Minus: michael@0: case Qt::Key_Period: michael@0: case Qt::Key_Slash: michael@0: case Qt::Key_0: michael@0: case Qt::Key_1: michael@0: case Qt::Key_2: michael@0: case Qt::Key_3: michael@0: case Qt::Key_4: michael@0: case Qt::Key_5: michael@0: case Qt::Key_6: michael@0: case Qt::Key_7: michael@0: case Qt::Key_8: michael@0: case Qt::Key_9: michael@0: case Qt::Key_Colon: michael@0: case Qt::Key_Semicolon: michael@0: case Qt::Key_Less: michael@0: case Qt::Key_Equal: michael@0: case Qt::Key_Greater: michael@0: case Qt::Key_Question: michael@0: case Qt::Key_At: michael@0: case Qt::Key_A: michael@0: case Qt::Key_B: michael@0: case Qt::Key_C: michael@0: case Qt::Key_D: michael@0: case Qt::Key_E: michael@0: case Qt::Key_F: michael@0: case Qt::Key_G: michael@0: case Qt::Key_H: michael@0: case Qt::Key_I: michael@0: case Qt::Key_J: michael@0: case Qt::Key_K: michael@0: case Qt::Key_L: michael@0: case Qt::Key_M: michael@0: case Qt::Key_N: michael@0: case Qt::Key_O: michael@0: case Qt::Key_P: michael@0: case Qt::Key_Q: michael@0: case Qt::Key_R: michael@0: case Qt::Key_S: michael@0: case Qt::Key_T: michael@0: case Qt::Key_U: michael@0: case Qt::Key_V: michael@0: case Qt::Key_W: michael@0: case Qt::Key_X: michael@0: case Qt::Key_Y: michael@0: case Qt::Key_Z: michael@0: case Qt::Key_BracketLeft: michael@0: case Qt::Key_Backslash: michael@0: case Qt::Key_BracketRight: michael@0: case Qt::Key_AsciiCircum: michael@0: case Qt::Key_Underscore: michael@0: case Qt::Key_QuoteLeft: michael@0: case Qt::Key_BraceLeft: michael@0: case Qt::Key_Bar: michael@0: case Qt::Key_BraceRight: michael@0: case Qt::Key_AsciiTilde: michael@0: case Qt::Key_exclamdown: michael@0: case Qt::Key_cent: michael@0: case Qt::Key_sterling: michael@0: case Qt::Key_currency: michael@0: case Qt::Key_yen: michael@0: case Qt::Key_brokenbar: michael@0: case Qt::Key_section: michael@0: case Qt::Key_diaeresis: michael@0: case Qt::Key_copyright: michael@0: case Qt::Key_ordfeminine: michael@0: case Qt::Key_guillemotleft: michael@0: case Qt::Key_notsign: michael@0: case Qt::Key_hyphen: michael@0: case Qt::Key_registered: michael@0: case Qt::Key_macron: michael@0: case Qt::Key_degree: michael@0: case Qt::Key_plusminus: michael@0: case Qt::Key_twosuperior: michael@0: case Qt::Key_threesuperior: michael@0: case Qt::Key_acute: michael@0: case Qt::Key_mu: michael@0: case Qt::Key_paragraph: michael@0: case Qt::Key_periodcentered: michael@0: case Qt::Key_cedilla: michael@0: case Qt::Key_onesuperior: michael@0: case Qt::Key_masculine: michael@0: case Qt::Key_guillemotright: michael@0: case Qt::Key_onequarter: michael@0: case Qt::Key_onehalf: michael@0: case Qt::Key_threequarters: michael@0: case Qt::Key_questiondown: michael@0: case Qt::Key_Agrave: michael@0: case Qt::Key_Aacute: michael@0: case Qt::Key_Acircumflex: michael@0: case Qt::Key_Atilde: michael@0: case Qt::Key_Adiaeresis: michael@0: case Qt::Key_Aring: michael@0: case Qt::Key_AE: michael@0: case Qt::Key_Ccedilla: michael@0: case Qt::Key_Egrave: michael@0: case Qt::Key_Eacute: michael@0: case Qt::Key_Ecircumflex: michael@0: case Qt::Key_Ediaeresis: michael@0: case Qt::Key_Igrave: michael@0: case Qt::Key_Iacute: michael@0: case Qt::Key_Icircumflex: michael@0: case Qt::Key_Idiaeresis: michael@0: case Qt::Key_ETH: michael@0: case Qt::Key_Ntilde: michael@0: case Qt::Key_Ograve: michael@0: case Qt::Key_Oacute: michael@0: case Qt::Key_Ocircumflex: michael@0: case Qt::Key_Otilde: michael@0: case Qt::Key_Odiaeresis: michael@0: case Qt::Key_multiply: michael@0: case Qt::Key_Ooblique: michael@0: case Qt::Key_Ugrave: michael@0: case Qt::Key_Uacute: michael@0: case Qt::Key_Ucircumflex: michael@0: case Qt::Key_Udiaeresis: michael@0: case Qt::Key_Yacute: michael@0: case Qt::Key_THORN: michael@0: case Qt::Key_ssharp: michael@0: case Qt::Key_division: michael@0: case Qt::Key_ydiaeresis: michael@0: return KEY_NAME_INDEX_PrintableKey; michael@0: michael@0: case Qt::Key_Backtab: michael@0: case Qt::Key_Direction_L: michael@0: case Qt::Key_Direction_R: michael@0: case Qt::Key_SingleCandidate: michael@0: case Qt::Key_Hiragana_Katakana: michael@0: case Qt::Key_Zenkaku_Hankaku: michael@0: case Qt::Key_Touroku: michael@0: case Qt::Key_Massyo: michael@0: case Qt::Key_Hangul: michael@0: case Qt::Key_Hangul_Start: michael@0: case Qt::Key_Hangul_End: michael@0: case Qt::Key_Hangul_Hanja: michael@0: case Qt::Key_Hangul_Jamo: michael@0: case Qt::Key_Hangul_Romaja: michael@0: case Qt::Key_Hangul_Jeonja: michael@0: case Qt::Key_Hangul_Banja: michael@0: case Qt::Key_Hangul_PreHanja: michael@0: case Qt::Key_Hangul_PostHanja: michael@0: case Qt::Key_Hangul_Special: michael@0: case Qt::Key_Dead_Belowdot: michael@0: case Qt::Key_Dead_Hook: michael@0: case Qt::Key_Dead_Horn: michael@0: case Qt::Key_TrebleUp: michael@0: case Qt::Key_TrebleDown: michael@0: case Qt::Key_Standby: michael@0: case Qt::Key_OpenUrl: michael@0: case Qt::Key_LaunchMedia: michael@0: case Qt::Key_KeyboardLightOnOff: michael@0: case Qt::Key_KeyboardBrightnessUp: michael@0: case Qt::Key_KeyboardBrightnessDown: michael@0: case Qt::Key_WakeUp: michael@0: case Qt::Key_ScreenSaver: michael@0: case Qt::Key_WWW: michael@0: case Qt::Key_Memo: michael@0: case Qt::Key_LightBulb: michael@0: case Qt::Key_Shop: michael@0: case Qt::Key_History: michael@0: case Qt::Key_AddFavorite: michael@0: case Qt::Key_HotLinks: michael@0: case Qt::Key_Finance: michael@0: case Qt::Key_Community: michael@0: case Qt::Key_BackForward: michael@0: case Qt::Key_ApplicationLeft: michael@0: case Qt::Key_ApplicationRight: michael@0: case Qt::Key_Book: michael@0: case Qt::Key_CD: michael@0: case Qt::Key_Calculator: michael@0: case Qt::Key_ToDoList: michael@0: case Qt::Key_ClearGrab: michael@0: case Qt::Key_Close: michael@0: case Qt::Key_Display: michael@0: case Qt::Key_DOS: michael@0: case Qt::Key_Documents: michael@0: case Qt::Key_Excel: michael@0: case Qt::Key_Explorer: michael@0: case Qt::Key_Game: michael@0: case Qt::Key_Go: michael@0: case Qt::Key_iTouch: michael@0: case Qt::Key_LogOff: michael@0: case Qt::Key_Market: michael@0: case Qt::Key_Meeting: michael@0: case Qt::Key_MenuKB: michael@0: case Qt::Key_MenuPB: michael@0: case Qt::Key_MySites: michael@0: case Qt::Key_News: michael@0: case Qt::Key_OfficeHome: michael@0: case Qt::Key_Option: michael@0: case Qt::Key_Phone: michael@0: case Qt::Key_Calendar: michael@0: case Qt::Key_Reply: michael@0: case Qt::Key_RotateWindows: michael@0: case Qt::Key_RotationPB: michael@0: case Qt::Key_RotationKB: michael@0: case Qt::Key_Save: michael@0: case Qt::Key_Send: michael@0: case Qt::Key_Spell: michael@0: case Qt::Key_SplitScreen: michael@0: case Qt::Key_Support: michael@0: case Qt::Key_TaskPane: michael@0: case Qt::Key_Terminal: michael@0: case Qt::Key_Tools: michael@0: case Qt::Key_Travel: michael@0: case Qt::Key_Video: michael@0: case Qt::Key_Word: michael@0: case Qt::Key_Xfer: michael@0: case Qt::Key_ZoomIn: michael@0: case Qt::Key_ZoomOut: michael@0: case Qt::Key_Away: michael@0: case Qt::Key_Messenger: michael@0: case Qt::Key_WebCam: michael@0: case Qt::Key_MailForward: michael@0: case Qt::Key_Pictures: michael@0: case Qt::Key_Music: michael@0: case Qt::Key_Battery: michael@0: case Qt::Key_Bluetooth: michael@0: case Qt::Key_WLAN: michael@0: case Qt::Key_UWB: michael@0: case Qt::Key_AudioRepeat: michael@0: case Qt::Key_AudioCycleTrack: michael@0: case Qt::Key_Time: michael@0: case Qt::Key_Hibernate: michael@0: case Qt::Key_View: michael@0: case Qt::Key_TopMenu: michael@0: case Qt::Key_PowerDown: michael@0: case Qt::Key_Suspend: michael@0: case Qt::Key_ContrastAdjust: michael@0: case Qt::Key_TouchpadToggle: michael@0: case Qt::Key_TouchpadOn: michael@0: case Qt::Key_TouchpadOff: michael@0: case Qt::Key_unknown: michael@0: case Qt::Key_Call: michael@0: case Qt::Key_CameraFocus: michael@0: case Qt::Key_Context1: michael@0: case Qt::Key_Context2: michael@0: case Qt::Key_Context3: michael@0: case Qt::Key_Context4: michael@0: case Qt::Key_Flip: michael@0: case Qt::Key_Hangup: michael@0: case Qt::Key_No: michael@0: case Qt::Key_Select: michael@0: case Qt::Key_Yes: michael@0: case Qt::Key_ToggleCallHangup: michael@0: case Qt::Key_VoiceDial: michael@0: case Qt::Key_LastNumberRedial: michael@0: case Qt::Key_Printer: michael@0: case Qt::Key_Sleep: michael@0: default: michael@0: return KEY_NAME_INDEX_Unidentified; michael@0: } michael@0: } michael@0: