Commit 90aa9cca authored by dtapuska's avatar dtapuska Committed by Commit bot

Fix Keypad keyboard events on Mac; so the KeyboardCodes reflect the Keypad location.

Ensure Keypad Events on Mac have the correct keycode associated with
them by avoiding the character conversion code and doing the
correct check based on the mac KeyCode value.

For example '0' as a Keypad character was producing the exact
same keycode as '0' as an alpha numeric key because it was
compared via the text conversion function first.

This code is taken from the WebInputEventFactory.mm in blink.

BUG=493833

Review URL: https://codereview.chromium.org/1331383004

Cr-Commit-Position: refs/heads/master@{#348798}
parent a7122c30
...@@ -200,6 +200,42 @@ const KeyCodeMap kKeyCodesMap[] = { ...@@ -200,6 +200,42 @@ const KeyCodeMap kKeyCodesMap[] = {
{ VKEY_OEM_CLEAR /* 0xFE */, kVK_ANSI_KeypadClear, kClearCharCode } { VKEY_OEM_CLEAR /* 0xFE */, kVK_ANSI_KeypadClear, kClearCharCode }
}; };
bool IsKeypadEvent(NSEvent* event) {
// Check that this is the type of event that has a keyCode.
switch ([event type]) {
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
break;
default:
return false;
}
switch ([event keyCode]) {
case kVK_ANSI_KeypadClear:
case kVK_ANSI_KeypadEquals:
case kVK_ANSI_KeypadMultiply:
case kVK_ANSI_KeypadDivide:
case kVK_ANSI_KeypadMinus:
case kVK_ANSI_KeypadPlus:
case kVK_ANSI_KeypadEnter:
case kVK_ANSI_KeypadDecimal:
case kVK_ANSI_Keypad0:
case kVK_ANSI_Keypad1:
case kVK_ANSI_Keypad2:
case kVK_ANSI_Keypad3:
case kVK_ANSI_Keypad4:
case kVK_ANSI_Keypad5:
case kVK_ANSI_Keypad6:
case kVK_ANSI_Keypad7:
case kVK_ANSI_Keypad8:
case kVK_ANSI_Keypad9:
return true;
}
return false;
}
// A convenient array for getting symbol characters on the number keys. // A convenient array for getting symbol characters on the number keys.
const char kShiftCharsForNumberKeys[] = ")!@#$%^&*("; const char kShiftCharsForNumberKeys[] = ")!@#$%^&*(";
...@@ -533,7 +569,8 @@ int MacKeyCodeForWindowsKeyCode(KeyboardCode keycode, ...@@ -533,7 +569,8 @@ int MacKeyCodeForWindowsKeyCode(KeyboardCode keycode,
KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event) { KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event) {
KeyboardCode code = VKEY_UNKNOWN; KeyboardCode code = VKEY_UNKNOWN;
if ([event type] == NSKeyDown || [event type] == NSKeyUp) { if (!IsKeypadEvent(event) &&
([event type] == NSKeyDown || [event type] == NSKeyUp)) {
NSString* characters = [event characters]; NSString* characters = [event characters];
if ([characters length] > 0) if ([characters length] > 0)
code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); code = KeyboardCodeFromCharCode([characters characterAtIndex:0]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment