OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006-2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006-2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 int keyval = hardwareCodeToGDKKeyval[event->hardware_keycode]; | 163 int keyval = hardwareCodeToGDKKeyval[event->hardware_keycode]; |
164 if (keyval) | 164 if (keyval) |
165 return WebCore::windowsKeyCodeForKeyEvent(keyval); | 165 return WebCore::windowsKeyCodeForKeyEvent(keyval); |
166 } | 166 } |
167 | 167 |
168 // This key is one that keyboard-layout drivers cannot change. | 168 // This key is one that keyboard-layout drivers cannot change. |
169 // Use |event->keyval| to retrieve its |windowsKeyCode| value. | 169 // Use |event->keyval| to retrieve its |windowsKeyCode| value. |
170 return WebCore::windowsKeyCodeForKeyEvent(event->keyval); | 170 return WebCore::windowsKeyCodeForKeyEvent(event->keyval); |
171 } | 171 } |
172 | 172 |
| 173 // Gets the corresponding control character of a specified key code. See: |
| 174 // http://en.wikipedia.org/wiki/Control_characters |
| 175 // We emulate Windows behavior here. |
| 176 static WebUChar getControlCharacter(int windowsKeyCode, bool shift) |
| 177 { |
| 178 if (windowsKeyCode >= WebCore::VKEY_A && windowsKeyCode <= WebCore::VKEY_Z) { |
| 179 // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A |
| 180 return windowsKeyCode - WebCore::VKEY_A + 1; |
| 181 } |
| 182 if (shift) { |
| 183 // following graphics chars require shift key to input. |
| 184 switch (windowsKeyCode) { |
| 185 // ctrl-@ maps to \x00 (Null byte) |
| 186 case WebCore::VKEY_2: |
| 187 return 0; |
| 188 // ctrl-^ maps to \x1E (Record separator, Information separator two) |
| 189 case WebCore::VKEY_6: |
| 190 return 0x1E; |
| 191 // ctrl-_ maps to \x1F (Unit separator, Information separator one) |
| 192 case WebCore::VKEY_OEM_MINUS: |
| 193 return 0x1F; |
| 194 // Returns 0 for all other keys to avoid inputting unexpected chars. |
| 195 default: |
| 196 return 0; |
| 197 } |
| 198 } else { |
| 199 switch (windowsKeyCode) { |
| 200 // ctrl-[ maps to \x1B (Escape) |
| 201 case WebCore::VKEY_OEM_4: |
| 202 return 0x1B; |
| 203 // ctrl-\ maps to \x1C (File separator, Information separator four) |
| 204 case WebCore::VKEY_OEM_5: |
| 205 return 0x1C; |
| 206 // ctrl-] maps to \x1D (Group separator, Information separator three) |
| 207 case WebCore::VKEY_OEM_6: |
| 208 return 0x1D; |
| 209 // ctrl-Enter maps to \x0A (Line feed) |
| 210 case WebCore::VKEY_RETURN: |
| 211 return 0x0A; |
| 212 // Returns 0 for all other keys to avoid inputting unexpected chars. |
| 213 default: |
| 214 return 0; |
| 215 } |
| 216 } |
| 217 } |
| 218 |
173 // WebKeyboardEvent ----------------------------------------------------------- | 219 // WebKeyboardEvent ----------------------------------------------------------- |
174 | 220 |
175 WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event) | 221 WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event) |
176 { | 222 { |
177 WebKeyboardEvent result; | 223 WebKeyboardEvent result; |
178 | 224 |
179 result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time); | 225 result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time); |
180 result.modifiers = gdkStateToWebEventModifiers(event->state); | 226 result.modifiers = gdkStateToWebEventModifiers(event->state); |
181 | 227 |
182 switch (event->type) { | 228 switch (event->type) { |
(...skipping 15 matching lines...) Expand all Loading... |
198 // F10 is not special on Linux, so don't treat it as system key. | 244 // F10 is not special on Linux, so don't treat it as system key. |
199 if (result.modifiers & WebInputEvent::AltKey) | 245 if (result.modifiers & WebInputEvent::AltKey) |
200 result.isSystemKey = true; | 246 result.isSystemKey = true; |
201 | 247 |
202 // The key code tells us which physical key was pressed (for example, the | 248 // The key code tells us which physical key was pressed (for example, the |
203 // A key went down or up). It does not determine whether A should be lower | 249 // A key went down or up). It does not determine whether A should be lower |
204 // or upper case. This is what text does, which should be the keyval. | 250 // or upper case. This is what text does, which should be the keyval. |
205 result.windowsKeyCode = gdkEventToWindowsKeyCode(event); | 251 result.windowsKeyCode = gdkEventToWindowsKeyCode(event); |
206 result.nativeKeyCode = event->hardware_keycode; | 252 result.nativeKeyCode = event->hardware_keycode; |
207 | 253 |
208 switch (event->keyval) { | 254 if (result.windowsKeyCode == WebCore::VKEY_RETURN) |
209 // We need to treat the enter key as a key press of character \r. This | 255 // We need to treat the enter key as a key press of character \r. This |
210 // is apparently just how webkit handles it and what it expects. | 256 // is apparently just how webkit handles it and what it expects. |
211 case GDK_ISO_Enter: | 257 result.unmodifiedText[0] = '\r'; |
212 case GDK_KP_Enter: | 258 else |
213 case GDK_Return: | |
214 result.unmodifiedText[0] = result.text[0] = static_cast<WebUChar>('\r'); | |
215 break; | |
216 default: | |
217 // This should set text to 0 when it's not a real character. | |
218 // FIXME: fix for non BMP chars | 259 // FIXME: fix for non BMP chars |
219 // TODO(james.su@gmail.com): | 260 result.unmodifiedText[0] = |
220 // Support control characters input like Windows. | |
221 // See: http://en.wikipedia.org/wiki/Control_characters | |
222 result.unmodifiedText[0] = result.text[0] = | |
223 static_cast<WebUChar>(gdk_keyval_to_unicode(event->keyval)); | 261 static_cast<WebUChar>(gdk_keyval_to_unicode(event->keyval)); |
224 } | 262 |
| 263 // If ctrl key is pressed down, then control character shall be input. |
| 264 if (result.modifiers & WebInputEvent::ControlKey) |
| 265 result.text[0] = getControlCharacter( |
| 266 result.windowsKeyCode, result.modifiers & WebInputEvent::ShiftKey); |
| 267 else |
| 268 result.text[0] = result.unmodifiedText[0]; |
225 | 269 |
226 result.setKeyIdentifierFromWindowsKeyCode(); | 270 result.setKeyIdentifierFromWindowsKeyCode(); |
227 | 271 |
228 // FIXME: Do we need to set IsAutoRepeat or IsKeyPad? | 272 // FIXME: Do we need to set IsAutoRepeat or IsKeyPad? |
229 | 273 |
230 return result; | 274 return result; |
231 } | 275 } |
232 | 276 |
233 WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, int state, double timeStampSeconds) | 277 WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, int state, double timeStampSeconds) |
234 { | 278 { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 case GDK_SCROLL_RIGHT: | 427 case GDK_SCROLL_RIGHT: |
384 result.deltaX = -scrollbarPixelsPerTick; | 428 result.deltaX = -scrollbarPixelsPerTick; |
385 result.wheelTicksX = 1; | 429 result.wheelTicksX = 1; |
386 break; | 430 break; |
387 } | 431 } |
388 | 432 |
389 return result; | 433 return result; |
390 } | 434 } |
391 | 435 |
392 } // namespace WebKit | 436 } // namespace WebKit |
OLD | NEW |