1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include <qnamespace.h>
8 #include "mozilla/ArrayUtils.h"
9 #include "mozilla/TextEvents.h"
12 #include "nsQtKeyUtils.h"
14 using namespace mozilla
;
15 using namespace mozilla::widget
;
19 int vkCode
; // Platform independent key code
20 int keysym
; // Qt key code
23 static struct nsKeyConverter nsKeycodes
[] =
25 // { NS_VK_CANCEL, Qt::Key_Cancel },
26 { NS_VK_BACK
, Qt::Key_Backspace
},
27 { NS_VK_TAB
, Qt::Key_Tab
},
28 { NS_VK_TAB
, Qt::Key_Backtab
},
29 // { NS_VK_CLEAR, Qt::Key_Clear },
30 { NS_VK_RETURN
, Qt::Key_Return
},
31 { NS_VK_RETURN
, Qt::Key_Enter
},
32 { NS_VK_SHIFT
, Qt::Key_Shift
},
33 { NS_VK_CONTROL
, Qt::Key_Control
},
34 { NS_VK_ALT
, Qt::Key_Alt
},
35 { NS_VK_PAUSE
, Qt::Key_Pause
},
36 { NS_VK_CAPS_LOCK
, Qt::Key_CapsLock
},
37 { NS_VK_ESCAPE
, Qt::Key_Escape
},
38 { NS_VK_SPACE
, Qt::Key_Space
},
39 { NS_VK_PAGE_UP
, Qt::Key_PageUp
},
40 { NS_VK_PAGE_DOWN
, Qt::Key_PageDown
},
41 { NS_VK_END
, Qt::Key_End
},
42 { NS_VK_HOME
, Qt::Key_Home
},
43 { NS_VK_LEFT
, Qt::Key_Left
},
44 { NS_VK_UP
, Qt::Key_Up
},
45 { NS_VK_RIGHT
, Qt::Key_Right
},
46 { NS_VK_DOWN
, Qt::Key_Down
},
47 { NS_VK_PRINTSCREEN
, Qt::Key_Print
},
48 { NS_VK_INSERT
, Qt::Key_Insert
},
49 { NS_VK_DELETE
, Qt::Key_Delete
},
50 { NS_VK_HELP
, Qt::Key_Help
},
52 { NS_VK_0
, Qt::Key_0
},
53 { NS_VK_1
, Qt::Key_1
},
54 { NS_VK_2
, Qt::Key_2
},
55 { NS_VK_3
, Qt::Key_3
},
56 { NS_VK_4
, Qt::Key_4
},
57 { NS_VK_5
, Qt::Key_5
},
58 { NS_VK_6
, Qt::Key_6
},
59 { NS_VK_7
, Qt::Key_7
},
60 { NS_VK_8
, Qt::Key_8
},
61 { NS_VK_9
, Qt::Key_9
},
63 { NS_VK_SEMICOLON
, Qt::Key_Semicolon
},
64 { NS_VK_EQUALS
, Qt::Key_Equal
},
66 { NS_VK_A
, Qt::Key_A
},
67 { NS_VK_B
, Qt::Key_B
},
68 { NS_VK_C
, Qt::Key_C
},
69 { NS_VK_D
, Qt::Key_D
},
70 { NS_VK_E
, Qt::Key_E
},
71 { NS_VK_F
, Qt::Key_F
},
72 { NS_VK_G
, Qt::Key_G
},
73 { NS_VK_H
, Qt::Key_H
},
74 { NS_VK_I
, Qt::Key_I
},
75 { NS_VK_J
, Qt::Key_J
},
76 { NS_VK_K
, Qt::Key_K
},
77 { NS_VK_L
, Qt::Key_L
},
78 { NS_VK_M
, Qt::Key_M
},
79 { NS_VK_N
, Qt::Key_N
},
80 { NS_VK_O
, Qt::Key_O
},
81 { NS_VK_P
, Qt::Key_P
},
82 { NS_VK_Q
, Qt::Key_Q
},
83 { NS_VK_R
, Qt::Key_R
},
84 { NS_VK_S
, Qt::Key_S
},
85 { NS_VK_T
, Qt::Key_T
},
86 { NS_VK_U
, Qt::Key_U
},
87 { NS_VK_V
, Qt::Key_V
},
88 { NS_VK_W
, Qt::Key_W
},
89 { NS_VK_X
, Qt::Key_X
},
90 { NS_VK_Y
, Qt::Key_Y
},
91 { NS_VK_Z
, Qt::Key_Z
},
93 { NS_VK_NUMPAD0
, Qt::Key_0
},
94 { NS_VK_NUMPAD1
, Qt::Key_1
},
95 { NS_VK_NUMPAD2
, Qt::Key_2
},
96 { NS_VK_NUMPAD3
, Qt::Key_3
},
97 { NS_VK_NUMPAD4
, Qt::Key_4
},
98 { NS_VK_NUMPAD5
, Qt::Key_5
},
99 { NS_VK_NUMPAD6
, Qt::Key_6
},
100 { NS_VK_NUMPAD7
, Qt::Key_7
},
101 { NS_VK_NUMPAD8
, Qt::Key_8
},
102 { NS_VK_NUMPAD9
, Qt::Key_9
},
103 { NS_VK_MULTIPLY
, Qt::Key_Asterisk
},
104 { NS_VK_ADD
, Qt::Key_Plus
},
105 // { NS_VK_SEPARATOR, Qt::Key_Separator },
106 { NS_VK_SUBTRACT
, Qt::Key_Minus
},
107 { NS_VK_DECIMAL
, Qt::Key_Period
},
108 { NS_VK_DIVIDE
, Qt::Key_Slash
},
109 { NS_VK_F1
, Qt::Key_F1
},
110 { NS_VK_F2
, Qt::Key_F2
},
111 { NS_VK_F3
, Qt::Key_F3
},
112 { NS_VK_F4
, Qt::Key_F4
},
113 { NS_VK_F5
, Qt::Key_F5
},
114 { NS_VK_F6
, Qt::Key_F6
},
115 { NS_VK_F7
, Qt::Key_F7
},
116 { NS_VK_F8
, Qt::Key_F8
},
117 { NS_VK_F9
, Qt::Key_F9
},
118 { NS_VK_F10
, Qt::Key_F10
},
119 { NS_VK_F11
, Qt::Key_F11
},
120 { NS_VK_F12
, Qt::Key_F12
},
121 { NS_VK_F13
, Qt::Key_F13
},
122 { NS_VK_F14
, Qt::Key_F14
},
123 { NS_VK_F15
, Qt::Key_F15
},
124 { NS_VK_F16
, Qt::Key_F16
},
125 { NS_VK_F17
, Qt::Key_F17
},
126 { NS_VK_F18
, Qt::Key_F18
},
127 { NS_VK_F19
, Qt::Key_F19
},
128 { NS_VK_F20
, Qt::Key_F20
},
129 { NS_VK_F21
, Qt::Key_F21
},
130 { NS_VK_F22
, Qt::Key_F22
},
131 { NS_VK_F23
, Qt::Key_F23
},
132 { NS_VK_F24
, Qt::Key_F24
},
134 { NS_VK_NUM_LOCK
, Qt::Key_NumLock
},
135 { NS_VK_SCROLL_LOCK
, Qt::Key_ScrollLock
},
137 { NS_VK_COMMA
, Qt::Key_Comma
},
138 { NS_VK_PERIOD
, Qt::Key_Period
},
139 { NS_VK_SLASH
, Qt::Key_Slash
},
140 { NS_VK_BACK_QUOTE
, Qt::Key_QuoteLeft
},
141 { NS_VK_OPEN_BRACKET
, Qt::Key_ParenLeft
},
142 { NS_VK_CLOSE_BRACKET
, Qt::Key_ParenRight
},
143 { NS_VK_QUOTE
, Qt::Key_QuoteDbl
},
145 { NS_VK_META
, Qt::Key_Meta
}
149 QtKeyCodeToDOMKeyCode(int aKeysym
)
153 // First, try to handle alphanumeric input, not listed in nsKeycodes:
154 // most likely, more letters will be getting typed in than things in
155 // the key list, so we will look through these first.
157 // since X has different key symbols for upper and lowercase letters and
158 // mozilla does not, convert gdk's to mozilla's
159 if (aKeysym
>= Qt::Key_A
&& aKeysym
<= Qt::Key_Z
)
160 return aKeysym
- Qt::Key_A
+ NS_VK_A
;
163 if (aKeysym
>= Qt::Key_0
&& aKeysym
<= Qt::Key_9
)
164 return aKeysym
- Qt::Key_0
+ NS_VK_0
;
167 // if (aKeysym >= Qt::Key_KP_0 && aKeysym <= Qt::Key_KP_9)
168 // return aKeysym - Qt::Key_KP_0 + NS_VK_NUMPAD0;
171 for (i
= 0; i
< ArrayLength(nsKeycodes
); i
++) {
172 if (nsKeycodes
[i
].keysym
== aKeysym
)
173 return(nsKeycodes
[i
].vkCode
);
177 if (aKeysym
>= Qt::Key_F1
&& aKeysym
<= Qt::Key_F24
)
178 return aKeysym
- Qt::Key_F1
+ NS_VK_F1
;
184 DOMKeyCodeToQtKeyCode(int aKeysym
)
188 // First, try to handle alphanumeric input, not listed in nsKeycodes:
189 // most likely, more letters will be getting typed in than things in
190 // the key list, so we will look through these first.
192 if (aKeysym
>= NS_VK_A
&& aKeysym
<= NS_VK_Z
)
193 // gdk and DOM both use the ASCII codes for these keys.
197 if (aKeysym
>= NS_VK_0
&& aKeysym
<= NS_VK_9
)
198 // gdk and DOM both use the ASCII codes for these keys.
199 return aKeysym
- Qt::Key_0
+ NS_VK_0
;
202 if (aKeysym
>= NS_VK_NUMPAD0
&& aKeysym
<= NS_VK_NUMPAD9
) {
203 NS_ERROR("keypad numbers conversion not implemented");
204 //return aKeysym - NS_VK_NUMPAD0 + Qt::Key_KP_0;
209 for (i
= 0; i
< ArrayLength(nsKeycodes
); ++i
) {
210 if (nsKeycodes
[i
].vkCode
== aKeysym
) {
211 return nsKeycodes
[i
].keysym
;
216 if (aKeysym
>= NS_VK_F1
&& aKeysym
<= NS_VK_F9
)
217 return aKeysym
- NS_VK_F1
+ Qt::Key_F1
;
223 QtKeyCodeToDOMKeyNameIndex(int aKeysym
)
227 #define NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex) \
228 case aNativeKey: return aKeyNameIndex;
230 #include "NativeKeyToDOMKeyName.h"
232 #undef NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX
235 case Qt::Key_QuoteDbl
:
236 case Qt::Key_NumberSign
:
238 case Qt::Key_Percent
:
239 case Qt::Key_Ampersand
:
240 case Qt::Key_Apostrophe
:
241 case Qt::Key_ParenLeft
:
242 case Qt::Key_ParenRight
:
243 case Qt::Key_Asterisk
:
260 case Qt::Key_Semicolon
:
263 case Qt::Key_Greater
:
264 case Qt::Key_Question
:
292 case Qt::Key_BracketLeft
:
293 case Qt::Key_Backslash
:
294 case Qt::Key_BracketRight
:
295 case Qt::Key_AsciiCircum
:
296 case Qt::Key_Underscore
:
297 case Qt::Key_QuoteLeft
:
298 case Qt::Key_BraceLeft
:
300 case Qt::Key_BraceRight
:
301 case Qt::Key_AsciiTilde
:
302 case Qt::Key_exclamdown
:
304 case Qt::Key_sterling
:
305 case Qt::Key_currency
:
307 case Qt::Key_brokenbar
:
308 case Qt::Key_section
:
309 case Qt::Key_diaeresis
:
310 case Qt::Key_copyright
:
311 case Qt::Key_ordfeminine
:
312 case Qt::Key_guillemotleft
:
313 case Qt::Key_notsign
:
315 case Qt::Key_registered
:
318 case Qt::Key_plusminus
:
319 case Qt::Key_twosuperior
:
320 case Qt::Key_threesuperior
:
323 case Qt::Key_paragraph
:
324 case Qt::Key_periodcentered
:
325 case Qt::Key_cedilla
:
326 case Qt::Key_onesuperior
:
327 case Qt::Key_masculine
:
328 case Qt::Key_guillemotright
:
329 case Qt::Key_onequarter
:
330 case Qt::Key_onehalf
:
331 case Qt::Key_threequarters
:
332 case Qt::Key_questiondown
:
335 case Qt::Key_Acircumflex
:
337 case Qt::Key_Adiaeresis
:
340 case Qt::Key_Ccedilla
:
343 case Qt::Key_Ecircumflex
:
344 case Qt::Key_Ediaeresis
:
347 case Qt::Key_Icircumflex
:
348 case Qt::Key_Idiaeresis
:
353 case Qt::Key_Ocircumflex
:
355 case Qt::Key_Odiaeresis
:
356 case Qt::Key_multiply
:
357 case Qt::Key_Ooblique
:
360 case Qt::Key_Ucircumflex
:
361 case Qt::Key_Udiaeresis
:
365 case Qt::Key_division
:
366 case Qt::Key_ydiaeresis
:
367 return KEY_NAME_INDEX_PrintableKey
;
369 case Qt::Key_Backtab
:
370 case Qt::Key_Direction_L
:
371 case Qt::Key_Direction_R
:
372 case Qt::Key_SingleCandidate
:
373 case Qt::Key_Hiragana_Katakana
:
374 case Qt::Key_Zenkaku_Hankaku
:
375 case Qt::Key_Touroku
:
378 case Qt::Key_Hangul_Start
:
379 case Qt::Key_Hangul_End
:
380 case Qt::Key_Hangul_Hanja
:
381 case Qt::Key_Hangul_Jamo
:
382 case Qt::Key_Hangul_Romaja
:
383 case Qt::Key_Hangul_Jeonja
:
384 case Qt::Key_Hangul_Banja
:
385 case Qt::Key_Hangul_PreHanja
:
386 case Qt::Key_Hangul_PostHanja
:
387 case Qt::Key_Hangul_Special
:
388 case Qt::Key_Dead_Belowdot
:
389 case Qt::Key_Dead_Hook
:
390 case Qt::Key_Dead_Horn
:
391 case Qt::Key_TrebleUp
:
392 case Qt::Key_TrebleDown
:
393 case Qt::Key_Standby
:
394 case Qt::Key_OpenUrl
:
395 case Qt::Key_LaunchMedia
:
396 case Qt::Key_KeyboardLightOnOff
:
397 case Qt::Key_KeyboardBrightnessUp
:
398 case Qt::Key_KeyboardBrightnessDown
:
400 case Qt::Key_ScreenSaver
:
403 case Qt::Key_LightBulb
:
405 case Qt::Key_History
:
406 case Qt::Key_AddFavorite
:
407 case Qt::Key_HotLinks
:
408 case Qt::Key_Finance
:
409 case Qt::Key_Community
:
410 case Qt::Key_BackForward
:
411 case Qt::Key_ApplicationLeft
:
412 case Qt::Key_ApplicationRight
:
415 case Qt::Key_Calculator
:
416 case Qt::Key_ToDoList
:
417 case Qt::Key_ClearGrab
:
419 case Qt::Key_Display
:
421 case Qt::Key_Documents
:
423 case Qt::Key_Explorer
:
429 case Qt::Key_Meeting
:
432 case Qt::Key_MySites
:
434 case Qt::Key_OfficeHome
:
437 case Qt::Key_Calendar
:
439 case Qt::Key_RotateWindows
:
440 case Qt::Key_RotationPB
:
441 case Qt::Key_RotationKB
:
445 case Qt::Key_SplitScreen
:
446 case Qt::Key_Support
:
447 case Qt::Key_TaskPane
:
448 case Qt::Key_Terminal
:
455 case Qt::Key_ZoomOut
:
457 case Qt::Key_Messenger
:
459 case Qt::Key_MailForward
:
460 case Qt::Key_Pictures
:
462 case Qt::Key_Battery
:
463 case Qt::Key_Bluetooth
:
466 case Qt::Key_AudioRepeat
:
467 case Qt::Key_AudioCycleTrack
:
469 case Qt::Key_Hibernate
:
471 case Qt::Key_TopMenu
:
472 case Qt::Key_PowerDown
:
473 case Qt::Key_Suspend
:
474 case Qt::Key_ContrastAdjust
:
475 case Qt::Key_TouchpadToggle
:
476 case Qt::Key_TouchpadOn
:
477 case Qt::Key_TouchpadOff
:
478 case Qt::Key_unknown
:
480 case Qt::Key_CameraFocus
:
481 case Qt::Key_Context1
:
482 case Qt::Key_Context2
:
483 case Qt::Key_Context3
:
484 case Qt::Key_Context4
:
490 case Qt::Key_ToggleCallHangup
:
491 case Qt::Key_VoiceDial
:
492 case Qt::Key_LastNumberRedial
:
493 case Qt::Key_Printer
:
496 return KEY_NAME_INDEX_Unidentified
;
501 ScanCodeToDOMCodeNameIndex(int32_t aScanCode
)
505 #define NS_NATIVE_KEY_TO_DOM_CODE_NAME_INDEX(aNativeKey, aCodeNameIndex) \
506 case aNativeKey: return aCodeNameIndex;
508 #include "NativeKeyToDOMCodeName.h"
510 #undef NS_NATIVE_KEY_TO_DOM_CODE_NAME_INDEX
513 return CODE_NAME_INDEX_UNKNOWN
;