src/video/nacl/SDL_naclevents.c
changeset 8833 ae720d61d14d
child 8846 e401b691077b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/nacl/SDL_naclevents.c	Fri Jun 06 15:45:59 2014 -0300
     1.3 @@ -0,0 +1,432 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 + 1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 + 2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 + 3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "../../SDL_internal.h"
    1.25 +
    1.26 +#include "SDL.h"
    1.27 +#include "../../events/SDL_sysevents.h"
    1.28 +#include "../../events/SDL_events_c.h"
    1.29 +#include "SDL_naclevents_c.h"
    1.30 +#include "SDL_naclvideo.h"
    1.31 +#include "ppapi_simple/ps_event.h"
    1.32 +
    1.33 +/* Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent */
    1.34 +
    1.35 +static SDL_Scancode NACL_Keycodes[] = {
    1.36 +    SDL_SCANCODE_UNKNOWN,               /* 0 */
    1.37 +    SDL_SCANCODE_UNKNOWN,               /* 1 */
    1.38 +    SDL_SCANCODE_UNKNOWN,               /* 2 */
    1.39 +    SDL_SCANCODE_CANCEL,                /* DOM_VK_CANCEL 3 */
    1.40 +    SDL_SCANCODE_UNKNOWN,               /* 4 */
    1.41 +    SDL_SCANCODE_UNKNOWN,               /* 5 */
    1.42 +    SDL_SCANCODE_HELP,                  /* DOM_VK_HELP 6 */
    1.43 +    SDL_SCANCODE_UNKNOWN,               /* 7 */
    1.44 +    SDL_SCANCODE_BACKSPACE,             /* DOM_VK_BACK_SPACE 8 */
    1.45 +    SDL_SCANCODE_TAB,                   /* DOM_VK_TAB 9 */
    1.46 +    SDL_SCANCODE_UNKNOWN,               /* 10 */
    1.47 +    SDL_SCANCODE_UNKNOWN,               /* 11 */
    1.48 +    SDL_SCANCODE_CLEAR,                 /* DOM_VK_CLEAR 12 */
    1.49 +    SDL_SCANCODE_RETURN,                /* DOM_VK_RETURN 13 */
    1.50 +    SDL_SCANCODE_RETURN,                /* DOM_VK_ENTER 14 */
    1.51 +    SDL_SCANCODE_UNKNOWN,               /* 15 */
    1.52 +    SDL_SCANCODE_LSHIFT,                /* DOM_VK_SHIFT 16 */
    1.53 +    SDL_SCANCODE_LCTRL,                 /* DOM_VK_CONTROL 17 */
    1.54 +    SDL_SCANCODE_LALT,                  /* DOM_VK_ALT 18 */
    1.55 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_PAUSE 19 */
    1.56 +    SDL_SCANCODE_CAPSLOCK,              /* DOM_VK_CAPS_LOCK 20 */
    1.57 +    SDL_SCANCODE_LANG1,                 /* DOM_VK_KANA  DOM_VK_HANGUL 21 */
    1.58 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_EISU 22 */
    1.59 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_JUNJA 23 */
    1.60 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_FINAL 24 */
    1.61 +    SDL_SCANCODE_LANG2,                 /* DOM_VK_HANJA  DOM_VK_KANJI 25 */
    1.62 +    SDL_SCANCODE_UNKNOWN,               /* 26 */
    1.63 +    SDL_SCANCODE_ESCAPE,                /* DOM_VK_ESCAPE 27 */
    1.64 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_CONVERT 28 */
    1.65 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_NONCONVERT 29 */
    1.66 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_ACCEPT 30 */
    1.67 +    SDL_SCANCODE_MODE,                  /* DOM_VK_MODECHANGE 31 */
    1.68 +    SDL_SCANCODE_SPACE,                 /* DOM_VK_SPACE 32 */
    1.69 +    SDL_SCANCODE_PAGEUP,                /* DOM_VK_PAGE_UP 33 */
    1.70 +    SDL_SCANCODE_PAGEDOWN,              /* DOM_VK_PAGE_DOWN 34 */
    1.71 +    SDL_SCANCODE_END,                   /* DOM_VK_END 35 */
    1.72 +    SDL_SCANCODE_HOME,                  /* DOM_VK_HOME 36 */
    1.73 +    SDL_SCANCODE_LEFT,                  /* DOM_VK_LEFT 37 */
    1.74 +    SDL_SCANCODE_UP,                    /* DOM_VK_UP 38 */
    1.75 +    SDL_SCANCODE_RIGHT,                 /* DOM_VK_RIGHT 39 */
    1.76 +    SDL_SCANCODE_DOWN,                  /* DOM_VK_DOWN 40 */
    1.77 +    SDL_SCANCODE_SELECT,                /* DOM_VK_SELECT 41 */
    1.78 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_PRINT 42 */
    1.79 +    SDL_SCANCODE_EXECUTE,               /* DOM_VK_EXECUTE 43 */
    1.80 +    SDL_SCANCODE_PRINTSCREEN,           /* DOM_VK_PRINTSCREEN 44 */
    1.81 +    SDL_SCANCODE_INSERT,                /* DOM_VK_INSERT 45 */
    1.82 +    SDL_SCANCODE_DELETE,                /* DOM_VK_DELETE 46 */
    1.83 +    SDL_SCANCODE_UNKNOWN,               /* 47 */
    1.84 +    SDL_SCANCODE_0,                     /* DOM_VK_0 48 */
    1.85 +    SDL_SCANCODE_1,                     /* DOM_VK_1 49 */
    1.86 +    SDL_SCANCODE_2,                     /* DOM_VK_2 50 */
    1.87 +    SDL_SCANCODE_3,                     /* DOM_VK_3 51 */
    1.88 +    SDL_SCANCODE_4,                     /* DOM_VK_4 52 */
    1.89 +    SDL_SCANCODE_5,                     /* DOM_VK_5 53 */
    1.90 +    SDL_SCANCODE_6,                     /* DOM_VK_6 54 */
    1.91 +    SDL_SCANCODE_7,                     /* DOM_VK_7 55 */
    1.92 +    SDL_SCANCODE_8,                     /* DOM_VK_8 56 */
    1.93 +    SDL_SCANCODE_9,                     /* DOM_VK_9 57 */
    1.94 +    SDL_SCANCODE_KP_COLON,              /* DOM_VK_COLON 58 */
    1.95 +    SDL_SCANCODE_SEMICOLON,             /* DOM_VK_SEMICOLON 59 */
    1.96 +    SDL_SCANCODE_KP_LESS,               /* DOM_VK_LESS_THAN 60 */
    1.97 +    SDL_SCANCODE_EQUALS,                /* DOM_VK_EQUALS 61 */
    1.98 +    SDL_SCANCODE_KP_GREATER,            /* DOM_VK_GREATER_THAN 62 */
    1.99 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_QUESTION_MARK 63 */
   1.100 +    SDL_SCANCODE_KP_AT,                 /* DOM_VK_AT 64 */
   1.101 +    SDL_SCANCODE_A,                     /* DOM_VK_A 65 */
   1.102 +    SDL_SCANCODE_B,                     /* DOM_VK_B 66 */
   1.103 +    SDL_SCANCODE_C,                     /* DOM_VK_C 67 */
   1.104 +    SDL_SCANCODE_D,                     /* DOM_VK_D 68 */
   1.105 +    SDL_SCANCODE_E,                     /* DOM_VK_E 69 */
   1.106 +    SDL_SCANCODE_F,                     /* DOM_VK_F 70 */
   1.107 +    SDL_SCANCODE_G,                     /* DOM_VK_G 71 */
   1.108 +    SDL_SCANCODE_H,                     /* DOM_VK_H 72 */
   1.109 +    SDL_SCANCODE_I,                     /* DOM_VK_I 73 */
   1.110 +    SDL_SCANCODE_J,                     /* DOM_VK_J 74 */
   1.111 +    SDL_SCANCODE_K,                     /* DOM_VK_K 75 */
   1.112 +    SDL_SCANCODE_L,                     /* DOM_VK_L 76 */
   1.113 +    SDL_SCANCODE_M,                     /* DOM_VK_M 77 */
   1.114 +    SDL_SCANCODE_N,                     /* DOM_VK_N 78 */
   1.115 +    SDL_SCANCODE_O,                     /* DOM_VK_O 79 */
   1.116 +    SDL_SCANCODE_P,                     /* DOM_VK_P 80 */
   1.117 +    SDL_SCANCODE_Q,                     /* DOM_VK_Q 81 */
   1.118 +    SDL_SCANCODE_R,                     /* DOM_VK_R 82 */
   1.119 +    SDL_SCANCODE_S,                     /* DOM_VK_S 83 */
   1.120 +    SDL_SCANCODE_T,                     /* DOM_VK_T 84 */
   1.121 +    SDL_SCANCODE_U,                     /* DOM_VK_U 85 */
   1.122 +    SDL_SCANCODE_V,                     /* DOM_VK_V 86 */
   1.123 +    SDL_SCANCODE_W,                     /* DOM_VK_W 87 */
   1.124 +    SDL_SCANCODE_X,                     /* DOM_VK_X 88 */
   1.125 +    SDL_SCANCODE_Y,                     /* DOM_VK_Y 89 */
   1.126 +    SDL_SCANCODE_Z,                     /* DOM_VK_Z 90 */
   1.127 +    SDL_SCANCODE_LGUI,                  /* DOM_VK_WIN 91 */
   1.128 +    SDL_SCANCODE_UNKNOWN,               /* 92 */
   1.129 +    SDL_SCANCODE_APPLICATION,           /* DOM_VK_CONTEXT_MENU 93 */
   1.130 +    SDL_SCANCODE_UNKNOWN,               /* 94 */
   1.131 +    SDL_SCANCODE_SLEEP,                 /* DOM_VK_SLEEP 95 */
   1.132 +    SDL_SCANCODE_KP_0,                  /* DOM_VK_NUMPAD0 96 */
   1.133 +    SDL_SCANCODE_KP_1,                  /* DOM_VK_NUMPAD1 97 */
   1.134 +    SDL_SCANCODE_KP_2,                  /* DOM_VK_NUMPAD2 98 */
   1.135 +    SDL_SCANCODE_KP_3,                  /* DOM_VK_NUMPAD3 99 */
   1.136 +    SDL_SCANCODE_KP_4,                  /* DOM_VK_NUMPAD4 100 */
   1.137 +    SDL_SCANCODE_KP_5,                  /* DOM_VK_NUMPAD5 101 */
   1.138 +    SDL_SCANCODE_KP_6,                  /* DOM_VK_NUMPAD6 102 */
   1.139 +    SDL_SCANCODE_KP_7,                  /* DOM_VK_NUMPAD7 103 */
   1.140 +    SDL_SCANCODE_KP_8,                  /* DOM_VK_NUMPAD8 104 */
   1.141 +    SDL_SCANCODE_KP_9,                  /* DOM_VK_NUMPAD9 105 */
   1.142 +    SDL_SCANCODE_KP_MULTIPLY,           /* DOM_VK_MULTIPLY 106 */
   1.143 +    SDL_SCANCODE_KP_PLUS,               /* DOM_VK_ADD 107 */
   1.144 +    SDL_SCANCODE_KP_COMMA,              /* DOM_VK_SEPARATOR 108 */
   1.145 +    SDL_SCANCODE_KP_MINUS,              /* DOM_VK_SUBTRACT 109 */
   1.146 +    SDL_SCANCODE_KP_PERIOD,             /* DOM_VK_DECIMAL 110 */
   1.147 +    SDL_SCANCODE_KP_DIVIDE,             /* DOM_VK_DIVIDE 111 */
   1.148 +    SDL_SCANCODE_F1,                    /* DOM_VK_F1 112 */
   1.149 +    SDL_SCANCODE_F2,                    /* DOM_VK_F2 113 */
   1.150 +    SDL_SCANCODE_F3,                    /* DOM_VK_F3 114 */
   1.151 +    SDL_SCANCODE_F4,                    /* DOM_VK_F4 115 */
   1.152 +    SDL_SCANCODE_F5,                    /* DOM_VK_F5 116 */
   1.153 +    SDL_SCANCODE_F6,                    /* DOM_VK_F6 117 */
   1.154 +    SDL_SCANCODE_F7,                    /* DOM_VK_F7 118 */
   1.155 +    SDL_SCANCODE_F8,                    /* DOM_VK_F8 119 */
   1.156 +    SDL_SCANCODE_F9,                    /* DOM_VK_F9 120 */
   1.157 +    SDL_SCANCODE_F10,                   /* DOM_VK_F10 121 */
   1.158 +    SDL_SCANCODE_F11,                   /* DOM_VK_F11 122 */
   1.159 +    SDL_SCANCODE_F12,                   /* DOM_VK_F12 123 */
   1.160 +    SDL_SCANCODE_F13,                   /* DOM_VK_F13 124 */
   1.161 +    SDL_SCANCODE_F14,                   /* DOM_VK_F14 125 */
   1.162 +    SDL_SCANCODE_F15,                   /* DOM_VK_F15 126 */
   1.163 +    SDL_SCANCODE_F16,                   /* DOM_VK_F16 127 */
   1.164 +    SDL_SCANCODE_F17,                   /* DOM_VK_F17 128 */
   1.165 +    SDL_SCANCODE_F18,                   /* DOM_VK_F18 129 */
   1.166 +    SDL_SCANCODE_F19,                   /* DOM_VK_F19 130 */
   1.167 +    SDL_SCANCODE_F20,                   /* DOM_VK_F20 131 */
   1.168 +    SDL_SCANCODE_F21,                   /* DOM_VK_F21 132 */
   1.169 +    SDL_SCANCODE_F22,                   /* DOM_VK_F22 133 */
   1.170 +    SDL_SCANCODE_F23,                   /* DOM_VK_F23 134 */
   1.171 +    SDL_SCANCODE_F24,                   /* DOM_VK_F24 135 */
   1.172 +    SDL_SCANCODE_UNKNOWN,               /* 136 */
   1.173 +    SDL_SCANCODE_UNKNOWN,               /* 137 */
   1.174 +    SDL_SCANCODE_UNKNOWN,               /* 138 */
   1.175 +    SDL_SCANCODE_UNKNOWN,               /* 139 */
   1.176 +    SDL_SCANCODE_UNKNOWN,               /* 140 */
   1.177 +    SDL_SCANCODE_UNKNOWN,               /* 141 */
   1.178 +    SDL_SCANCODE_UNKNOWN,               /* 142 */
   1.179 +    SDL_SCANCODE_UNKNOWN,               /* 143 */
   1.180 +    SDL_SCANCODE_NUMLOCKCLEAR,          /* DOM_VK_NUM_LOCK 144 */
   1.181 +    SDL_SCANCODE_SCROLLLOCK,            /* DOM_VK_SCROLL_LOCK 145 */
   1.182 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_FJ_JISHO 146 */
   1.183 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_FJ_MASSHOU 147 */
   1.184 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_FJ_TOUROKU 148 */
   1.185 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_FJ_LOYA 149 */
   1.186 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_FJ_ROYA 150 */
   1.187 +    SDL_SCANCODE_UNKNOWN,               /* 151 */
   1.188 +    SDL_SCANCODE_UNKNOWN,               /* 152 */
   1.189 +    SDL_SCANCODE_UNKNOWN,               /* 153 */
   1.190 +    SDL_SCANCODE_UNKNOWN,               /* 154 */
   1.191 +    SDL_SCANCODE_UNKNOWN,               /* 155 */
   1.192 +    SDL_SCANCODE_UNKNOWN,               /* 156 */
   1.193 +    SDL_SCANCODE_UNKNOWN,               /* 157 */
   1.194 +    SDL_SCANCODE_UNKNOWN,               /* 158 */
   1.195 +    SDL_SCANCODE_UNKNOWN,               /* 159 */
   1.196 +    SDL_SCANCODE_GRAVE,                 /* DOM_VK_CIRCUMFLEX 160 */
   1.197 +    SDL_SCANCODE_KP_EXCLAM,             /* DOM_VK_EXCLAMATION 161 */
   1.198 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_DOUBLE_QUOTE 162 */
   1.199 +    SDL_SCANCODE_KP_HASH,               /* DOM_VK_HASH 163 */
   1.200 +    SDL_SCANCODE_CURRENCYUNIT,          /* DOM_VK_DOLLAR 164 */
   1.201 +    SDL_SCANCODE_KP_PERCENT,            /* DOM_VK_PERCENT 165 */
   1.202 +    SDL_SCANCODE_KP_AMPERSAND,          /* DOM_VK_AMPERSAND 166 */
   1.203 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_UNDERSCORE 167 */
   1.204 +    SDL_SCANCODE_KP_LEFTPAREN,          /* DOM_VK_OPEN_PAREN 168 */
   1.205 +    SDL_SCANCODE_KP_RIGHTPAREN,         /* DOM_VK_CLOSE_PAREN 169 */
   1.206 +    SDL_SCANCODE_KP_MULTIPLY,           /* DOM_VK_ASTERISK 170 */
   1.207 +    SDL_SCANCODE_KP_PLUS,               /* DOM_VK_PLUS 171 */
   1.208 +    SDL_SCANCODE_KP_PLUS,               /* DOM_VK_PIPE 172 */
   1.209 +    SDL_SCANCODE_MINUS,                 /* DOM_VK_HYPHEN_MINUS 173 */
   1.210 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_OPEN_CURLY_BRACKET 174 */
   1.211 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_CLOSE_CURLY_BRACKET 175 */
   1.212 +    SDL_SCANCODE_NONUSBACKSLASH,        /* DOM_VK_TILDE 176 */
   1.213 +    SDL_SCANCODE_UNKNOWN,               /* 177 */
   1.214 +    SDL_SCANCODE_UNKNOWN,               /* 178 */
   1.215 +    SDL_SCANCODE_UNKNOWN,               /* 179 */
   1.216 +    SDL_SCANCODE_UNKNOWN,               /* 180 */
   1.217 +    SDL_SCANCODE_MUTE,                  /* DOM_VK_VOLUME_MUTE 181 */
   1.218 +    SDL_SCANCODE_VOLUMEDOWN,            /* DOM_VK_VOLUME_DOWN 182 */
   1.219 +    SDL_SCANCODE_VOLUMEUP,              /* DOM_VK_VOLUME_UP 183 */
   1.220 +    SDL_SCANCODE_UNKNOWN,               /* 184 */
   1.221 +    SDL_SCANCODE_UNKNOWN,               /* 185 */
   1.222 +    SDL_SCANCODE_UNKNOWN,               /* 186 */
   1.223 +    SDL_SCANCODE_UNKNOWN,               /* 187 */
   1.224 +    SDL_SCANCODE_COMMA,                 /* DOM_VK_COMMA 188 */
   1.225 +    SDL_SCANCODE_UNKNOWN,               /* 189 */
   1.226 +    SDL_SCANCODE_PERIOD,                /* DOM_VK_PERIOD 190 */
   1.227 +    SDL_SCANCODE_SLASH,                 /* DOM_VK_SLASH 191 */
   1.228 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_BACK_QUOTE 192 */
   1.229 +    SDL_SCANCODE_UNKNOWN,               /* 193 */
   1.230 +    SDL_SCANCODE_UNKNOWN,               /* 194 */
   1.231 +    SDL_SCANCODE_UNKNOWN,               /* 195 */
   1.232 +    SDL_SCANCODE_UNKNOWN,               /* 196 */
   1.233 +    SDL_SCANCODE_UNKNOWN,               /* 197 */
   1.234 +    SDL_SCANCODE_UNKNOWN,               /* 198 */
   1.235 +    SDL_SCANCODE_UNKNOWN,               /* 199 */
   1.236 +    SDL_SCANCODE_UNKNOWN,               /* 200 */
   1.237 +    SDL_SCANCODE_UNKNOWN,               /* 201 */
   1.238 +    SDL_SCANCODE_UNKNOWN,               /* 202 */
   1.239 +    SDL_SCANCODE_UNKNOWN,               /* 203 */
   1.240 +    SDL_SCANCODE_UNKNOWN,               /* 204 */
   1.241 +    SDL_SCANCODE_UNKNOWN,               /* 205 */
   1.242 +    SDL_SCANCODE_UNKNOWN,               /* 206 */
   1.243 +    SDL_SCANCODE_UNKNOWN,               /* 207 */
   1.244 +    SDL_SCANCODE_UNKNOWN,               /* 208 */
   1.245 +    SDL_SCANCODE_UNKNOWN,               /* 209 */
   1.246 +    SDL_SCANCODE_UNKNOWN,               /* 210 */
   1.247 +    SDL_SCANCODE_UNKNOWN,               /* 211 */
   1.248 +    SDL_SCANCODE_UNKNOWN,               /* 212 */
   1.249 +    SDL_SCANCODE_UNKNOWN,               /* 213 */
   1.250 +    SDL_SCANCODE_UNKNOWN,               /* 214 */
   1.251 +    SDL_SCANCODE_UNKNOWN,               /* 215 */
   1.252 +    SDL_SCANCODE_UNKNOWN,               /* 216 */
   1.253 +    SDL_SCANCODE_UNKNOWN,               /* 217 */
   1.254 +    SDL_SCANCODE_UNKNOWN,               /* 218 */
   1.255 +    SDL_SCANCODE_LEFTBRACKET,           /* DOM_VK_OPEN_BRACKET 219 */
   1.256 +    SDL_SCANCODE_BACKSLASH,             /* DOM_VK_BACK_SLASH 220 */
   1.257 +    SDL_SCANCODE_RIGHTBRACKET,          /* DOM_VK_CLOSE_BRACKET 221 */
   1.258 +    SDL_SCANCODE_APOSTROPHE,            /* DOM_VK_QUOTE 222 */
   1.259 +    SDL_SCANCODE_UNKNOWN,               /* 223 */
   1.260 +    SDL_SCANCODE_RGUI,                  /* DOM_VK_META 224 */
   1.261 +    SDL_SCANCODE_RALT,                  /* DOM_VK_ALTGR 225 */
   1.262 +    SDL_SCANCODE_UNKNOWN,               /* 226 */
   1.263 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_ICO_HELP 227 */
   1.264 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_ICO_00 228 */
   1.265 +    SDL_SCANCODE_UNKNOWN,               /* 229 */
   1.266 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_ICO_CLEAR 230 */
   1.267 +    SDL_SCANCODE_UNKNOWN,               /* 231 */
   1.268 +    SDL_SCANCODE_UNKNOWN,               /* 232 */
   1.269 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_RESET 233 */
   1.270 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_JUMP 234 */
   1.271 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_PA1 235 */
   1.272 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_PA2 236 */
   1.273 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_PA3 237 */
   1.274 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_WSCTRL 238 */
   1.275 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_CUSEL 239 */
   1.276 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_ATTN 240 */
   1.277 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_FINISH 241 */
   1.278 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_COPY 242 */
   1.279 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_AUTO 243 */
   1.280 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_ENLW 244 */
   1.281 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_BACKTAB 245 */
   1.282 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_ATTN 246 */
   1.283 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_CRSEL 247 */
   1.284 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_EXSEL 248 */
   1.285 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_EREOF 249 */
   1.286 +    SDL_SCANCODE_AUDIOPLAY,             /* DOM_VK_PLAY 250 */
   1.287 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_ZOOM 251 */
   1.288 +    SDL_SCANCODE_UNKNOWN,               /* 252 */
   1.289 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_PA1 253 */
   1.290 +    SDL_SCANCODE_UNKNOWN,               /* DOM_VK_WIN_OEM_CLEAR 254 */
   1.291 +    SDL_SCANCODE_UNKNOWN,               /* 255 */
   1.292 +};
   1.293 +
   1.294 +static Uint8 SDL_NACL_translate_mouse_button(int32_t button) {
   1.295 +    switch (button) {
   1.296 +        case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
   1.297 +            return SDL_BUTTON_LEFT;
   1.298 +        case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
   1.299 +            return SDL_BUTTON_MIDDLE;
   1.300 +        case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
   1.301 +            return SDL_BUTTON_RIGHT;
   1.302 +            
   1.303 +        case PP_INPUTEVENT_MOUSEBUTTON_NONE:
   1.304 +        default:
   1.305 +            return 0;
   1.306 +    }
   1.307 +}
   1.308 +
   1.309 +static SDL_Scancode
   1.310 +SDL_NACL_translate_keycode(int keycode)
   1.311 +{
   1.312 +    SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
   1.313 +
   1.314 +    if (keycode < SDL_arraysize(NACL_Keycodes)) {
   1.315 +        scancode = NACL_Keycodes[keycode];
   1.316 +    }
   1.317 +    if (scancode == SDL_SCANCODE_UNKNOWN) {
   1.318 +        SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> EVDEV KeyCode %d \n", keycode);
   1.319 +    }
   1.320 +    return scancode;
   1.321 +}
   1.322 +
   1.323 +void NACL_PumpEvents(_THIS) {
   1.324 +  PSEvent* ps_event;
   1.325 +  PP_Resource event;  
   1.326 +  PP_InputEvent_Type type;
   1.327 +  PP_InputEvent_Modifier modifiers;
   1.328 +  struct PP_Rect rect;
   1.329 +  struct PP_FloatPoint fp;
   1.330 +  struct PP_Point location;
   1.331 +  struct PP_Var var;
   1.332 +  const char *str;
   1.333 +  char text[64];
   1.334 +  Uint32 str_len;
   1.335 +  SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
   1.336 +  SDL_Mouse *mouse = SDL_GetMouse();
   1.337 +  
   1.338 +  if (driverdata->window) {
   1.339 +    while ((ps_event = PSEventTryAcquire()) != NULL) {
   1.340 +        event = ps_event->as_resource;
   1.341 +        switch(ps_event->type) {
   1.342 +            /* From DidChangeView, contains a view resource */
   1.343 +            case PSE_INSTANCE_DIDCHANGEVIEW:
   1.344 +                driverdata->ppb_view->GetRect(event, &rect);
   1.345 +                NACL_SetScreenResolution(rect.size.width, rect.size.height, SDL_PIXELFORMAT_UNKNOWN);
   1.346 +                // FIXME: Rebuild context? See life.c UpdateContext
   1.347 +                break;
   1.348 +            
   1.349 +            /* From HandleInputEvent, contains an input resource. */
   1.350 +            case PSE_INSTANCE_HANDLEINPUT: 
   1.351 +                type = driverdata->ppb_input_event->GetType(event);
   1.352 +                modifiers = driverdata->ppb_input_event->GetModifiers(event);
   1.353 +                switch(type) {
   1.354 +                    case PP_INPUTEVENT_TYPE_MOUSEDOWN:
   1.355 +                        SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
   1.356 +                        break;
   1.357 +                    case PP_INPUTEVENT_TYPE_MOUSEUP:
   1.358 +                        SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
   1.359 +                        break;
   1.360 +                    case PP_INPUTEVENT_TYPE_WHEEL:
   1.361 +                        /* FIXME: GetTicks provides high resolution scroll events */
   1.362 +                        fp = driverdata->ppb_wheel_input_event->GetDelta(event);
   1.363 +                        SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y);
   1.364 +                        break;
   1.365 +                        
   1.366 +                    case PP_INPUTEVENT_TYPE_MOUSEENTER:
   1.367 +                    case PP_INPUTEVENT_TYPE_MOUSELEAVE:
   1.368 +                        /* FIXME: Mouse Focus */
   1.369 +                        break;
   1.370 +                        
   1.371 +                        
   1.372 +                    case PP_INPUTEVENT_TYPE_MOUSEMOVE: 
   1.373 +                        location = driverdata->ppb_mouse_input_event->GetPosition(event);
   1.374 +                        SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, location.x, location.y);
   1.375 +                        break;
   1.376 +                  
   1.377 +                    case PP_INPUTEVENT_TYPE_TOUCHSTART:
   1.378 +                    case PP_INPUTEVENT_TYPE_TOUCHMOVE:
   1.379 +                    case PP_INPUTEVENT_TYPE_TOUCHEND:
   1.380 +                    case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
   1.381 +                        /* FIXME: Touch events */
   1.382 +                        break;
   1.383 +                      
   1.384 +                    case PP_INPUTEVENT_TYPE_KEYDOWN:
   1.385 +                        SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
   1.386 +                        break;
   1.387 +                        
   1.388 +                    case PP_INPUTEVENT_TYPE_KEYUP:
   1.389 +                        SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
   1.390 +                        break;
   1.391 +                        
   1.392 +                    case PP_INPUTEVENT_TYPE_CHAR:
   1.393 +                        var = driverdata->ppb_keyboard_input_event->GetCharacterText(event);
   1.394 +                        str = driverdata->ppb_var->VarToUtf8(var, &str_len);
   1.395 +                        /* str is not null terminated! */
   1.396 +                        if ( str_len >= SDL_arraysize(text) ) {
   1.397 +                            str_len = SDL_arraysize(text) - 1;
   1.398 +                        }
   1.399 +                        SDL_strlcpy(text, str, str_len );
   1.400 +                        text[str_len] = '\0';
   1.401 +                        
   1.402 +                        SDL_SendKeyboardText(text);
   1.403 +                        /* FIXME: Do we have to handle ref counting? driverdata->ppb_var->Release(var);*/
   1.404 +                        break;
   1.405 +                        
   1.406 +                    default:
   1.407 +                        break;
   1.408 +                }
   1.409 +                break;
   1.410 +                
   1.411 +        
   1.412 +            /* From HandleMessage, contains a PP_Var. */
   1.413 +            case PSE_INSTANCE_HANDLEMESSAGE:
   1.414 +                break;
   1.415 +
   1.416 +            /* From DidChangeFocus, contains a PP_Bool with the current focus state. */
   1.417 +            case PSE_INSTANCE_DIDCHANGEFOCUS:
   1.418 +                break;
   1.419 +
   1.420 +            /* When the 3D context is lost, no resource. */
   1.421 +            case PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST:
   1.422 +                break;
   1.423 +                
   1.424 +            /* When the mouse lock is lost. */
   1.425 +            case PSE_MOUSELOCK_MOUSELOCKLOST:
   1.426 +                break;
   1.427 +
   1.428 +            default:
   1.429 +                break;
   1.430 +        }
   1.431 +        
   1.432 +        PSEventRelease(ps_event);
   1.433 +    }
   1.434 +  }
   1.435 +}