Home | History | Annotate | Download | only in gtk
      1 /*
      2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
      3  * Copyright (C) 2006 Michael Emmel mike.emmel (at) gmail.com
      4  * Copyright (C) 2007 Holger Hans Peter Freyther
      5  * Copyright (C) 2008 Collabora, Ltd.  All rights reserved.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include "config.h"
     31 #include "PlatformKeyboardEvent.h"
     32 
     33 #include "GtkVersioning.h"
     34 #include "NotImplemented.h"
     35 #include "TextEncoding.h"
     36 #include "WindowsKeyboardCodes.h"
     37 
     38 #include <gdk/gdk.h>
     39 #include <gdk/gdkkeysyms.h>
     40 
     41 namespace WebCore {
     42 
     43 // FIXME: This is incomplete.  We should change this to mirror
     44 // more like what Firefox does, and generate these switch statements
     45 // at build time.
     46 String PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(unsigned keyCode)
     47 {
     48     switch (keyCode) {
     49         case GDK_Menu:
     50         case GDK_Alt_L:
     51         case GDK_Alt_R:
     52             return "Alt";
     53         case GDK_Clear:
     54             return "Clear";
     55         case GDK_Down:
     56             return "Down";
     57             // "End"
     58         case GDK_End:
     59             return "End";
     60             // "Enter"
     61         case GDK_ISO_Enter:
     62         case GDK_KP_Enter:
     63         case GDK_Return:
     64             return "Enter";
     65         case GDK_Execute:
     66             return "Execute";
     67         case GDK_F1:
     68             return "F1";
     69         case GDK_F2:
     70             return "F2";
     71         case GDK_F3:
     72             return "F3";
     73         case GDK_F4:
     74             return "F4";
     75         case GDK_F5:
     76             return "F5";
     77         case GDK_F6:
     78             return "F6";
     79         case GDK_F7:
     80             return "F7";
     81         case GDK_F8:
     82             return "F8";
     83         case GDK_F9:
     84             return "F9";
     85         case GDK_F10:
     86             return "F10";
     87         case GDK_F11:
     88             return "F11";
     89         case GDK_F12:
     90             return "F12";
     91         case GDK_F13:
     92             return "F13";
     93         case GDK_F14:
     94             return "F14";
     95         case GDK_F15:
     96             return "F15";
     97         case GDK_F16:
     98             return "F16";
     99         case GDK_F17:
    100             return "F17";
    101         case GDK_F18:
    102             return "F18";
    103         case GDK_F19:
    104             return "F19";
    105         case GDK_F20:
    106             return "F20";
    107         case GDK_F21:
    108             return "F21";
    109         case GDK_F22:
    110             return "F22";
    111         case GDK_F23:
    112             return "F23";
    113         case GDK_F24:
    114             return "F24";
    115         case GDK_Help:
    116             return "Help";
    117         case GDK_Home:
    118             return "Home";
    119         case GDK_Insert:
    120             return "Insert";
    121         case GDK_Left:
    122             return "Left";
    123         case GDK_Page_Down:
    124             return "PageDown";
    125         case GDK_Page_Up:
    126             return "PageUp";
    127         case GDK_Pause:
    128             return "Pause";
    129         case GDK_3270_PrintScreen:
    130         case GDK_Print:
    131             return "PrintScreen";
    132         case GDK_Right:
    133             return "Right";
    134         case GDK_Select:
    135             return "Select";
    136         case GDK_Up:
    137             return "Up";
    138             // Standard says that DEL becomes U+007F.
    139         case GDK_Delete:
    140             return "U+007F";
    141         case GDK_BackSpace:
    142             return "U+0008";
    143         case GDK_ISO_Left_Tab:
    144         case GDK_3270_BackTab:
    145         case GDK_Tab:
    146             return "U+0009";
    147         default:
    148             return String::format("U+%04X", gdk_keyval_to_unicode(gdk_keyval_to_upper(keyCode)));
    149     }
    150 }
    151 
    152 int PlatformKeyboardEvent::windowsKeyCodeForGdkKeyCode(unsigned keycode)
    153 {
    154     switch (keycode) {
    155         case GDK_KP_0:
    156             return VK_NUMPAD0;// (60) Numeric keypad 0 key
    157         case GDK_KP_1:
    158             return VK_NUMPAD1;// (61) Numeric keypad 1 key
    159         case GDK_KP_2:
    160             return  VK_NUMPAD2; // (62) Numeric keypad 2 key
    161         case GDK_KP_3:
    162             return VK_NUMPAD3; // (63) Numeric keypad 3 key
    163         case GDK_KP_4:
    164             return VK_NUMPAD4; // (64) Numeric keypad 4 key
    165         case GDK_KP_5:
    166             return VK_NUMPAD5; //(65) Numeric keypad 5 key
    167         case GDK_KP_6:
    168             return VK_NUMPAD6; // (66) Numeric keypad 6 key
    169         case GDK_KP_7:
    170             return VK_NUMPAD7; // (67) Numeric keypad 7 key
    171         case GDK_KP_8:
    172             return VK_NUMPAD8; // (68) Numeric keypad 8 key
    173         case GDK_KP_9:
    174             return VK_NUMPAD9; // (69) Numeric keypad 9 key
    175         case GDK_KP_Multiply:
    176             return VK_MULTIPLY; // (6A) Multiply key
    177         case GDK_KP_Add:
    178             return VK_ADD; // (6B) Add key
    179         case GDK_KP_Subtract:
    180             return VK_SUBTRACT; // (6D) Subtract key
    181         case GDK_KP_Decimal:
    182             return VK_DECIMAL; // (6E) Decimal key
    183         case GDK_KP_Divide:
    184             return VK_DIVIDE; // (6F) Divide key
    185 
    186         case GDK_KP_Page_Up:
    187             return VK_PRIOR; // (21) PAGE UP key
    188         case GDK_KP_Page_Down:
    189             return VK_NEXT; // (22) PAGE DOWN key
    190         case GDK_KP_End:
    191             return VK_END; // (23) END key
    192         case GDK_KP_Home:
    193             return VK_HOME; // (24) HOME key
    194         case GDK_KP_Left:
    195             return VK_LEFT; // (25) LEFT ARROW key
    196         case GDK_KP_Up:
    197             return VK_UP; // (26) UP ARROW key
    198         case GDK_KP_Right:
    199             return VK_RIGHT; // (27) RIGHT ARROW key
    200         case GDK_KP_Down:
    201             return VK_DOWN; // (28) DOWN ARROW key
    202 
    203         case GDK_BackSpace:
    204             return VK_BACK; // (08) BACKSPACE key
    205         case GDK_ISO_Left_Tab:
    206         case GDK_3270_BackTab:
    207         case GDK_Tab:
    208             return VK_TAB; // (09) TAB key
    209         case GDK_Clear:
    210             return VK_CLEAR; // (0C) CLEAR key
    211         case GDK_ISO_Enter:
    212         case GDK_KP_Enter:
    213         case GDK_Return:
    214             return VK_RETURN; //(0D) Return key
    215         case GDK_Shift_L:
    216         case GDK_Shift_R:
    217             return VK_SHIFT; // (10) SHIFT key
    218         case GDK_Control_L:
    219         case GDK_Control_R:
    220             return VK_CONTROL; // (11) CTRL key
    221         case GDK_Menu:
    222             return VK_APPS;  // (5D) Applications key (Natural keyboard)
    223         case GDK_Alt_L:
    224         case GDK_Alt_R:
    225             return VK_MENU; // (12) ALT key
    226 
    227         case GDK_Pause:
    228             return VK_PAUSE; // (13) PAUSE key
    229         case GDK_Caps_Lock:
    230             return VK_CAPITAL; // (14) CAPS LOCK key
    231         case GDK_Kana_Lock:
    232         case GDK_Kana_Shift:
    233             return VK_KANA; // (15) Input Method Editor (IME) Kana mode
    234         case GDK_Hangul:
    235             return VK_HANGUL; // VK_HANGUL (15) IME Hangul mode
    236             // VK_JUNJA (17) IME Junja mode
    237             // VK_FINAL (18) IME final mode
    238         case GDK_Hangul_Hanja:
    239             return VK_HANJA; // (19) IME Hanja mode
    240         case GDK_Kanji:
    241             return VK_KANJI; // (19) IME Kanji mode
    242         case GDK_Escape:
    243             return VK_ESCAPE; // (1B) ESC key
    244             // VK_CONVERT (1C) IME convert
    245             // VK_NONCONVERT (1D) IME nonconvert
    246             // VK_ACCEPT (1E) IME accept
    247             // VK_MODECHANGE (1F) IME mode change request
    248         case GDK_space:
    249             return VK_SPACE; // (20) SPACEBAR
    250         case GDK_Page_Up:
    251             return VK_PRIOR; // (21) PAGE UP key
    252         case GDK_Page_Down:
    253             return VK_NEXT; // (22) PAGE DOWN key
    254         case GDK_End:
    255             return VK_END; // (23) END key
    256         case GDK_Home:
    257             return VK_HOME; // (24) HOME key
    258         case GDK_Left:
    259             return VK_LEFT; // (25) LEFT ARROW key
    260         case GDK_Up:
    261             return VK_UP; // (26) UP ARROW key
    262         case GDK_Right:
    263             return VK_RIGHT; // (27) RIGHT ARROW key
    264         case GDK_Down:
    265             return VK_DOWN; // (28) DOWN ARROW key
    266         case GDK_Select:
    267             return VK_SELECT; // (29) SELECT key
    268         case GDK_Print:
    269             return VK_SNAPSHOT; // (2C) PRINT SCREEN key
    270         case GDK_Execute:
    271             return VK_EXECUTE;// (2B) EXECUTE key
    272         case GDK_Insert:
    273         case GDK_KP_Insert:
    274             return VK_INSERT; // (2D) INS key
    275         case GDK_Delete:
    276         case GDK_KP_Delete:
    277             return VK_DELETE; // (2E) DEL key
    278         case GDK_Help:
    279             return VK_HELP; // (2F) HELP key
    280         case GDK_0:
    281         case GDK_parenright:
    282             return VK_0;    //  (30) 0) key
    283         case GDK_1:
    284         case GDK_exclam:
    285             return VK_1; //  (31) 1 ! key
    286         case GDK_2:
    287         case GDK_at:
    288             return VK_2; //  (32) 2 & key
    289         case GDK_3:
    290         case GDK_numbersign:
    291             return VK_3; //case '3': case '#';
    292         case GDK_4:
    293         case GDK_dollar: //  (34) 4 key '$';
    294             return VK_4;
    295         case GDK_5:
    296         case GDK_percent:
    297             return VK_5; //  (35) 5 key  '%'
    298         case GDK_6:
    299         case GDK_asciicircum:
    300             return VK_6; //  (36) 6 key  '^'
    301         case GDK_7:
    302         case GDK_ampersand:
    303             return VK_7; //  (37) 7 key  case '&'
    304         case GDK_8:
    305         case GDK_asterisk:
    306             return VK_8; //  (38) 8 key  '*'
    307         case GDK_9:
    308         case GDK_parenleft:
    309             return VK_9; //  (39) 9 key '('
    310         case GDK_a:
    311         case GDK_A:
    312             return VK_A; //  (41) A key case 'a': case 'A': return 0x41;
    313         case GDK_b:
    314         case GDK_B:
    315             return VK_B; //  (42) B key case 'b': case 'B': return 0x42;
    316         case GDK_c:
    317         case GDK_C:
    318             return VK_C; //  (43) C key case 'c': case 'C': return 0x43;
    319         case GDK_d:
    320         case GDK_D:
    321             return VK_D; //  (44) D key case 'd': case 'D': return 0x44;
    322         case GDK_e:
    323         case GDK_E:
    324             return VK_E; //  (45) E key case 'e': case 'E': return 0x45;
    325         case GDK_f:
    326         case GDK_F:
    327             return VK_F; //  (46) F key case 'f': case 'F': return 0x46;
    328         case GDK_g:
    329         case GDK_G:
    330             return VK_G; //  (47) G key case 'g': case 'G': return 0x47;
    331         case GDK_h:
    332         case GDK_H:
    333             return VK_H; //  (48) H key case 'h': case 'H': return 0x48;
    334         case GDK_i:
    335         case GDK_I:
    336             return VK_I; //  (49) I key case 'i': case 'I': return 0x49;
    337         case GDK_j:
    338         case GDK_J:
    339             return VK_J; //  (4A) J key case 'j': case 'J': return 0x4A;
    340         case GDK_k:
    341         case GDK_K:
    342             return VK_K; //  (4B) K key case 'k': case 'K': return 0x4B;
    343         case GDK_l:
    344         case GDK_L:
    345             return VK_L; //  (4C) L key case 'l': case 'L': return 0x4C;
    346         case GDK_m:
    347         case GDK_M:
    348             return VK_M; //  (4D) M key case 'm': case 'M': return 0x4D;
    349         case GDK_n:
    350         case GDK_N:
    351             return VK_N; //  (4E) N key case 'n': case 'N': return 0x4E;
    352         case GDK_o:
    353         case GDK_O:
    354             return VK_O; //  (4F) O key case 'o': case 'O': return 0x4F;
    355         case GDK_p:
    356         case GDK_P:
    357             return VK_P; //  (50) P key case 'p': case 'P': return 0x50;
    358         case GDK_q:
    359         case GDK_Q:
    360             return VK_Q; //  (51) Q key case 'q': case 'Q': return 0x51;
    361         case GDK_r:
    362         case GDK_R:
    363             return VK_R; //  (52) R key case 'r': case 'R': return 0x52;
    364         case GDK_s:
    365         case GDK_S:
    366             return VK_S; //  (53) S key case 's': case 'S': return 0x53;
    367         case GDK_t:
    368         case GDK_T:
    369             return VK_T; //  (54) T key case 't': case 'T': return 0x54;
    370         case GDK_u:
    371         case GDK_U:
    372             return VK_U; //  (55) U key case 'u': case 'U': return 0x55;
    373         case GDK_v:
    374         case GDK_V:
    375             return VK_V; //  (56) V key case 'v': case 'V': return 0x56;
    376         case GDK_w:
    377         case GDK_W:
    378             return VK_W; //  (57) W key case 'w': case 'W': return 0x57;
    379         case GDK_x:
    380         case GDK_X:
    381             return VK_X; //  (58) X key case 'x': case 'X': return 0x58;
    382         case GDK_y:
    383         case GDK_Y:
    384             return VK_Y; //  (59) Y key case 'y': case 'Y': return 0x59;
    385         case GDK_z:
    386         case GDK_Z:
    387             return VK_Z; //  (5A) Z key case 'z': case 'Z': return 0x5A;
    388         case GDK_Meta_L:
    389             return VK_LWIN; // (5B) Left Windows key (Microsoft Natural keyboard)
    390         case GDK_Meta_R:
    391             return VK_RWIN; // (5C) Right Windows key (Natural keyboard)
    392             // VK_SLEEP (5F) Computer Sleep key
    393             // VK_SEPARATOR (6C) Separator key
    394             // VK_SUBTRACT (6D) Subtract key
    395             // VK_DECIMAL (6E) Decimal key
    396             // VK_DIVIDE (6F) Divide key
    397             // handled by key code above
    398 
    399         case GDK_Num_Lock:
    400             return VK_NUMLOCK; // (90) NUM LOCK key
    401 
    402         case GDK_Scroll_Lock:
    403             return VK_SCROLL; // (91) SCROLL LOCK key
    404 
    405             // VK_LSHIFT (A0) Left SHIFT key
    406             // VK_RSHIFT (A1) Right SHIFT key
    407             // VK_LCONTROL (A2) Left CONTROL key
    408             // VK_RCONTROL (A3) Right CONTROL key
    409             // VK_LMENU (A4) Left MENU key
    410             // VK_RMENU (A5) Right MENU key
    411             // VK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
    412             // VK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
    413             // VK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
    414             // VK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
    415             // VK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
    416             // VK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
    417             // VK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
    418             // VK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
    419             // VK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
    420             // VK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
    421             // VK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
    422             // VK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
    423             // VK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
    424             // VK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
    425             // VK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
    426             // VK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
    427             // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
    428             // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
    429 
    430             // VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
    431         case GDK_semicolon:
    432         case GDK_colon:
    433             return VK_OEM_1; //case ';': case ':': return 0xBA;
    434             // VK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
    435         case GDK_plus:
    436         case GDK_equal:
    437             return VK_OEM_PLUS; //case '=': case '+': return 0xBB;
    438             // VK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
    439         case GDK_comma:
    440         case GDK_less:
    441             return VK_OEM_COMMA; //case ',': case '<': return 0xBC;
    442             // VK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
    443         case GDK_minus:
    444         case GDK_underscore:
    445             return VK_OEM_MINUS; //case '-': case '_': return 0xBD;
    446             // VK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
    447         case GDK_period:
    448         case GDK_greater:
    449             return VK_OEM_PERIOD; //case '.': case '>': return 0xBE;
    450             // VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
    451         case GDK_slash:
    452         case GDK_question:
    453             return VK_OEM_2; //case '/': case '?': return 0xBF;
    454             // VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
    455         case GDK_asciitilde:
    456         case GDK_quoteleft:
    457             return VK_OEM_3; //case '`': case '~': return 0xC0;
    458             // VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
    459         case GDK_bracketleft:
    460         case GDK_braceleft:
    461             return VK_OEM_4; //case '[': case '{': return 0xDB;
    462             // VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
    463         case GDK_backslash:
    464         case GDK_bar:
    465             return VK_OEM_5; //case '\\': case '|': return 0xDC;
    466             // VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
    467         case GDK_bracketright:
    468         case GDK_braceright:
    469             return VK_OEM_6; // case ']': case '}': return 0xDD;
    470             // VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
    471         case GDK_quoteright:
    472         case GDK_quotedbl:
    473             return VK_OEM_7; // case '\'': case '"': return 0xDE;
    474             // VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
    475             // VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
    476             // VK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
    477             // VK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
    478             // VK_ATTN (F6) Attn key
    479             // VK_CRSEL (F7) CrSel key
    480             // VK_EXSEL (F8) ExSel key
    481             // VK_EREOF (F9) Erase EOF key
    482             // VK_PLAY (FA) Play key
    483             // VK_ZOOM (FB) Zoom key
    484             // VK_NONAME (FC) Reserved for future use
    485             // VK_PA1 (FD) PA1 key
    486             // VK_OEM_CLEAR (FE) Clear key
    487         case GDK_F1:
    488         case GDK_F2:
    489         case GDK_F3:
    490         case GDK_F4:
    491         case GDK_F5:
    492         case GDK_F6:
    493         case GDK_F7:
    494         case GDK_F8:
    495         case GDK_F9:
    496         case GDK_F10:
    497         case GDK_F11:
    498         case GDK_F12:
    499         case GDK_F13:
    500         case GDK_F14:
    501         case GDK_F15:
    502         case GDK_F16:
    503         case GDK_F17:
    504         case GDK_F18:
    505         case GDK_F19:
    506         case GDK_F20:
    507         case GDK_F21:
    508         case GDK_F22:
    509         case GDK_F23:
    510         case GDK_F24:
    511             return VK_F1 + (keycode - GDK_F1);
    512 
    513         default:
    514             return 0;
    515     }
    516 
    517 }
    518 
    519 String PlatformKeyboardEvent::singleCharacterString(unsigned val)
    520 {
    521     switch (val) {
    522         case GDK_ISO_Enter:
    523         case GDK_KP_Enter:
    524         case GDK_Return:
    525             return String("\r");
    526         case GDK_BackSpace:
    527             return String("\x8");
    528         case GDK_Tab:
    529             return String("\t");
    530         default:
    531             gunichar c = gdk_keyval_to_unicode(val);
    532             glong nwc;
    533             gunichar2* uchar16 = g_ucs4_to_utf16(&c, 1, 0, &nwc, 0);
    534 
    535             String retVal;
    536             if (uchar16)
    537                 retVal = String((UChar*)uchar16, nwc);
    538             else
    539                 retVal = String();
    540 
    541             g_free(uchar16);
    542 
    543             return retVal;
    544     }
    545 }
    546 
    547 // Keep this in sync with the other platform event constructors
    548 // TODO: m_gdkEventKey should be refcounted
    549 PlatformKeyboardEvent::PlatformKeyboardEvent(GdkEventKey* event)
    550     : m_type((event->type == GDK_KEY_RELEASE) ? KeyUp : KeyDown)
    551     , m_text(singleCharacterString(event->keyval))
    552     , m_unmodifiedText(singleCharacterString(event->keyval))
    553     , m_keyIdentifier(keyIdentifierForGdkKeyCode(event->keyval))
    554     , m_autoRepeat(false)
    555     , m_windowsVirtualKeyCode(windowsKeyCodeForGdkKeyCode(event->keyval))
    556     , m_nativeVirtualKeyCode(event->keyval)
    557     , m_isKeypad(event->keyval >= GDK_KP_Space && event->keyval <= GDK_KP_9)
    558     , m_shiftKey((event->state & GDK_SHIFT_MASK) || (event->keyval == GDK_3270_BackTab))
    559     , m_ctrlKey(event->state & GDK_CONTROL_MASK)
    560     , m_altKey(event->state & GDK_MOD1_MASK)
    561     , m_metaKey(event->state & GDK_META_MASK)
    562     , m_gdkEventKey(event)
    563 {
    564 }
    565 
    566 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool backwardCompatibilityMode)
    567 {
    568     // Can only change type from KeyDown to RawKeyDown or Char, as we lack information for other conversions.
    569     ASSERT(m_type == KeyDown);
    570     m_type = type;
    571 
    572     if (backwardCompatibilityMode)
    573         return;
    574 
    575     if (type == RawKeyDown) {
    576         m_text = String();
    577         m_unmodifiedText = String();
    578     } else {
    579         m_keyIdentifier = String();
    580         m_windowsVirtualKeyCode = 0;
    581     }
    582 }
    583 
    584 bool PlatformKeyboardEvent::currentCapsLockState()
    585 {
    586     return gdk_keymap_get_caps_lock_state(gdk_keymap_get_default());
    587 }
    588 
    589 void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)
    590 {
    591     GdkModifierType state;
    592     gtk_get_current_event_state(&state);
    593 
    594     shiftKey = state & GDK_SHIFT_MASK;
    595     ctrlKey = state & GDK_CONTROL_MASK;
    596     altKey = state & GDK_MOD1_MASK;
    597     metaKey = state & GDK_META_MASK;
    598 }
    599 
    600 GdkEventKey* PlatformKeyboardEvent::gdkEventKey() const
    601 {
    602     return m_gdkEventKey;
    603 }
    604 
    605 }
    606