mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-25 17:43:44 +00:00
Fix for bug 3824 -- fix key mappings on Mac, so that all known raptor key codes are output where possible.
This commit is contained in:
parent
8da90006e7
commit
d955a54b76
@ -188,60 +188,176 @@ PRBool nsMacEventHandler::HandleMenuCommand(
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
#define homeKey 0x01 /* ascii code for home key */
|
||||
#define enterKey 0x03 /* ascii code for enter key */
|
||||
#define endKey 0x04 /* ascii code for end key */
|
||||
#define helpKey 0x05 /* ascii code for help key */
|
||||
#define deleteKey 0x08 /* ascii code for delete/backspace */
|
||||
#define tabKey 0x09 /* ascii code for tab key */
|
||||
#define pageUpKey 0x0B /* ascii code for page up key */
|
||||
#define pageDownKey 0x0C /* ascii code for page down key */
|
||||
#define returnKey 0x0D /* ascii code for return key */
|
||||
#define leftArrow 0x1C /* ascii code for left arrow key */
|
||||
#define rightArrow 0x1D /* ascii code for right arrow key */
|
||||
#define upArrow 0x1E /* ascii code for up arrow key */
|
||||
#define downArrow 0x1F /* ascii code for down arrow key */
|
||||
#define forwardDelKey 0x7F /* ascii code for forward delete key */
|
||||
#define spaceKey 0x20 /* ascii code for a space */
|
||||
|
||||
#define escapeKeyCode 0x35 /* key code for escape key */
|
||||
#define clearKeyCode 0x47 /* key code for clear key */
|
||||
// Key code constants
|
||||
enum
|
||||
{
|
||||
kEscapeKeyCode = 0x35,
|
||||
kShiftKeyCode = 0x38,
|
||||
kCapsLockKeyCode = 0x39,
|
||||
kControlKeyCode = 0x3B,
|
||||
kOptionkeyCode = 0x3A, // left and right option keys
|
||||
kClearKeyCode = 0x47,
|
||||
|
||||
// function keys
|
||||
kF1KeyCode = 0x7A,
|
||||
kF2KeyCode = 0x78,
|
||||
kF3KeyCode = 0x63,
|
||||
kF4KeyCode = 0x76,
|
||||
kF5KeyCode = 0x60,
|
||||
kF6KeyCode = 0x61,
|
||||
kF7KeyCode = 0x62,
|
||||
kF8KeyCode = 0x64,
|
||||
kF9KeyCode = 0x65,
|
||||
kF10KeyCode = 0x6D,
|
||||
kF11KeyCode = 0x67,
|
||||
kF12KeyCode = 0x6F,
|
||||
kF13KeyCode = 0x69,
|
||||
kF14KeyCode = 0x6B,
|
||||
kF15KeyCode = 0x71,
|
||||
|
||||
kPrintScreenKeyCode = kF13KeyCode,
|
||||
kScrollLockKeyCode = kF14KeyCode,
|
||||
kPauseKeyCode = kF15KeyCode,
|
||||
|
||||
// keypad
|
||||
kKeypad0KeyCode = 0x52,
|
||||
kKeypad1KeyCode = 0x53,
|
||||
kKeypad2KeyCode = 0x54,
|
||||
kKeypad3KeyCode = 0x55,
|
||||
kKeypad4KeyCode = 0x56,
|
||||
kKeypad5KeyCode = 0x57,
|
||||
kKeypad6KeyCode = 0x58,
|
||||
kKeypad7KeyCode = 0x59,
|
||||
kKeypad8KeyCode = 0x5B,
|
||||
kKeypad9KeyCode = 0x5C,
|
||||
|
||||
kKeypadMultiplyKeyCode = 0x43,
|
||||
kKeypadAddKeyCode = 0x45,
|
||||
kKeypadSubtractKeyCode = 0x4E,
|
||||
kKeypadDecimalKeyCode = 0x41,
|
||||
kKeypadDivideKeyCode = 0x4B,
|
||||
kKeypadEqualsKeyCode = 0x51, // no correpsonding raptor key code
|
||||
|
||||
kInsertKeyCode = 0x72, // also help key
|
||||
kDeleteKeyCode = 0x75 // also forward delete key
|
||||
|
||||
};
|
||||
|
||||
static PRUint32 ConvertMacToRaptorKeyCode(UInt32 eventMessage, UInt32 eventModifiers)
|
||||
{
|
||||
UInt8 charCode = (eventMessage & charCodeMask);
|
||||
UInt8 keyCode = (eventMessage & keyCodeMask) >> 8;
|
||||
PRUint32 raptorKeyCode;
|
||||
PRUint32 raptorKeyCode = 0;
|
||||
|
||||
// temporary hack until we figure out the key handling strategy (sfraser)
|
||||
switch (keyCode)
|
||||
{
|
||||
// case ?? : raptorKeyCode = NS_VK_CANCEL; break; // don't know what this key means. Nor does joki
|
||||
|
||||
// modifiers. We don't get separate events for these
|
||||
case kEscapeKeyCode: raptorKeyCode = NS_VK_ESCAPE; break;
|
||||
case kShiftKeyCode: raptorKeyCode = NS_VK_SHIFT; break;
|
||||
case kCapsLockKeyCode: raptorKeyCode = NS_VK_CAPS_LOCK; break;
|
||||
case kControlKeyCode: raptorKeyCode = NS_VK_CONTROL; break;
|
||||
case kOptionkeyCode: raptorKeyCode = NS_VK_ALT; break;
|
||||
case kClearKeyCode: raptorKeyCode = NS_VK_CLEAR; break;
|
||||
|
||||
// function keys
|
||||
case kF1KeyCode: raptorKeyCode = NS_VK_F1; break;
|
||||
case kF2KeyCode: raptorKeyCode = NS_VK_F2; break;
|
||||
case kF3KeyCode: raptorKeyCode = NS_VK_F3; break;
|
||||
case kF4KeyCode: raptorKeyCode = NS_VK_F4; break;
|
||||
case kF5KeyCode: raptorKeyCode = NS_VK_F5; break;
|
||||
case kF6KeyCode: raptorKeyCode = NS_VK_F6; break;
|
||||
case kF7KeyCode: raptorKeyCode = NS_VK_F7; break;
|
||||
case kF8KeyCode: raptorKeyCode = NS_VK_F8; break;
|
||||
case kF9KeyCode: raptorKeyCode = NS_VK_F9; break;
|
||||
case kF10KeyCode: raptorKeyCode = NS_VK_F10; break;
|
||||
case kF11KeyCode: raptorKeyCode = NS_VK_F11; break;
|
||||
case kF12KeyCode: raptorKeyCode = NS_VK_F12; break;
|
||||
// case kF13KeyCode: raptorKeyCode = NS_VK_F13; break; // clash with the 3 below
|
||||
// case kF14KeyCode: raptorKeyCode = NS_VK_F14; break;
|
||||
// case kF15KeyCode: raptorKeyCode = NS_VK_F15; break;
|
||||
case kPauseKeyCode: raptorKeyCode = NS_VK_PAUSE; break;
|
||||
case kScrollLockKeyCode: raptorKeyCode = NS_VK_SCROLL_LOCK; break;
|
||||
case kPrintScreenKeyCode: raptorKeyCode = NS_VK_PRINTSCREEN; break;
|
||||
|
||||
if (charCode >= ' ' && charCode <= '~') // ~ is 0x7E
|
||||
{
|
||||
raptorKeyCode = charCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (charCode)
|
||||
{
|
||||
case homeKey: raptorKeyCode = NS_VK_HOME; break;
|
||||
case enterKey: raptorKeyCode = NS_VK_RETURN; break; // fix me!
|
||||
case endKey: raptorKeyCode = NS_VK_END; break;
|
||||
//case helpKey: raptorKeyCode = ; break;
|
||||
case deleteKey: raptorKeyCode = NS_VK_DELETE; break;
|
||||
case tabKey: raptorKeyCode = NS_VK_TAB; break;
|
||||
// keypad
|
||||
case kKeypad0KeyCode: raptorKeyCode = NS_VK_NUMPAD0; break;
|
||||
case kKeypad1KeyCode: raptorKeyCode = NS_VK_NUMPAD1; break;
|
||||
case kKeypad2KeyCode: raptorKeyCode = NS_VK_NUMPAD2; break;
|
||||
case kKeypad3KeyCode: raptorKeyCode = NS_VK_NUMPAD3; break;
|
||||
case kKeypad4KeyCode: raptorKeyCode = NS_VK_NUMPAD4; break;
|
||||
case kKeypad5KeyCode: raptorKeyCode = NS_VK_NUMPAD5; break;
|
||||
case kKeypad6KeyCode: raptorKeyCode = NS_VK_NUMPAD6; break;
|
||||
case kKeypad7KeyCode: raptorKeyCode = NS_VK_NUMPAD7; break;
|
||||
case kKeypad8KeyCode: raptorKeyCode = NS_VK_NUMPAD8; break;
|
||||
case kKeypad9KeyCode: raptorKeyCode = NS_VK_NUMPAD9; break;
|
||||
|
||||
case pageUpKey: raptorKeyCode = NS_VK_PAGE_UP; break;
|
||||
case pageDownKey: raptorKeyCode = NS_VK_PAGE_DOWN; break;
|
||||
case returnKey: raptorKeyCode = NS_VK_RETURN; break;
|
||||
case kKeypadMultiplyKeyCode: raptorKeyCode = NS_VK_MULTIPLY; break;
|
||||
case kKeypadAddKeyCode: raptorKeyCode = NS_VK_ADD; break;
|
||||
case kKeypadSubtractKeyCode: raptorKeyCode = NS_VK_SUBTRACT; break;
|
||||
case kKeypadDecimalKeyCode: raptorKeyCode = NS_VK_DECIMAL; break;
|
||||
case kKeypadDivideKeyCode: raptorKeyCode = NS_VK_DIVIDE; break;
|
||||
// case ?? : raptorKeyCode = NS_VK_SEPARATOR; break;
|
||||
|
||||
case leftArrow: raptorKeyCode = NS_VK_LEFT; break;
|
||||
case rightArrow: raptorKeyCode = NS_VK_RIGHT; break;
|
||||
case upArrow: raptorKeyCode = NS_VK_UP; break;
|
||||
case downArrow: raptorKeyCode = NS_VK_DOWN; break;
|
||||
|
||||
case escapeKeyCode: raptorKeyCode = NS_VK_ESCAPE; break;
|
||||
case clearKeyCode: raptorKeyCode = NS_VK_CLEAR; break;
|
||||
}
|
||||
// these may clash with forward delete and help
|
||||
// case kInsertKeyCode: raptorKeyCode = NS_VK_INSERT; break;
|
||||
// case kDeleteKeyCode: raptorKeyCode = NS_VK_DELETE; break;
|
||||
|
||||
default:
|
||||
|
||||
// if we haven't gotten the key code already, look at the char code
|
||||
switch (charCode)
|
||||
{
|
||||
case kReturnCharCode: raptorKeyCode = NS_VK_RETURN; break;
|
||||
case kEnterCharCode: raptorKeyCode = NS_VK_RETURN; break; // fix me!
|
||||
case kBackspaceCharCode: raptorKeyCode = NS_VK_BACK; break;
|
||||
case kDeleteCharCode: raptorKeyCode = NS_VK_DELETE; break;
|
||||
case kTabCharCode: raptorKeyCode = NS_VK_TAB; break;
|
||||
|
||||
case kHomeCharCode: raptorKeyCode = NS_VK_HOME; break;
|
||||
case kEndCharCode: raptorKeyCode = NS_VK_END; break;
|
||||
case kPageUpCharCode: raptorKeyCode = NS_VK_PAGE_UP; break;
|
||||
case kPageDownCharCode: raptorKeyCode = NS_VK_PAGE_DOWN; break;
|
||||
|
||||
case kLeftArrowCharCode: raptorKeyCode = NS_VK_LEFT; break;
|
||||
case kRightArrowCharCode: raptorKeyCode = NS_VK_RIGHT; break;
|
||||
case kUpArrowCharCode: raptorKeyCode = NS_VK_UP; break;
|
||||
case kDownArrowCharCode: raptorKeyCode = NS_VK_DOWN; break;
|
||||
case ' ': raptorKeyCode = NS_VK_SPACE; break;
|
||||
case ';': raptorKeyCode = NS_VK_SEMICOLON; break;
|
||||
case '=': raptorKeyCode = NS_VK_EQUALS; break;
|
||||
case ',': raptorKeyCode = NS_VK_COMMA; break;
|
||||
case '.': raptorKeyCode = NS_VK_PERIOD; break;
|
||||
case '/': raptorKeyCode = NS_VK_SLASH; break;
|
||||
case '`': raptorKeyCode = NS_VK_BACK_QUOTE; break;
|
||||
case '{':
|
||||
case '[': raptorKeyCode = NS_VK_OPEN_BRACKET; break;
|
||||
case '\\': raptorKeyCode = NS_VK_BACK_SLASH; break;
|
||||
case '}':
|
||||
case ']': raptorKeyCode = NS_VK_CLOSE_BRACKET; break;
|
||||
case '\'':
|
||||
case '"': raptorKeyCode = NS_VK_QUOTE; break;
|
||||
|
||||
default:
|
||||
|
||||
if (charCode >= '0' && charCode <= '9') // numerals
|
||||
{
|
||||
raptorKeyCode = charCode;
|
||||
}
|
||||
else if (charCode >= 'a' && charCode <= 'z') // lowercase
|
||||
{
|
||||
raptorKeyCode = toupper(charCode);
|
||||
}
|
||||
else if (charCode >= 'A' && charCode <= 'Z') // uppercase
|
||||
{
|
||||
raptorKeyCode = charCode;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return raptorKeyCode;
|
||||
@ -600,6 +716,7 @@ void nsMacEventHandler::ConvertOSEventToMouseEvent(
|
||||
aMouseEvent.isShift = ((aOSEvent.modifiers & shiftKey) != 0);
|
||||
aMouseEvent.isControl = ((aOSEvent.modifiers & controlKey) != 0);
|
||||
aMouseEvent.isAlt = ((aOSEvent.modifiers & optionKey) != 0);
|
||||
aMouseEvent.isCommand = ((aOSEvent.modifiers & cmdKey) != 0);
|
||||
|
||||
// nsMouseEvent
|
||||
aMouseEvent.clickCount = lastClickCount;
|
||||
|
Loading…
Reference in New Issue
Block a user