Title: [132411] trunk
Revision
132411
Author
[email protected]
Date
2012-10-24 15:36:28 -0700 (Wed, 24 Oct 2012)

Log Message

Incorrect keycodes for numpad /, -, +, .
https://bugs.webkit.org/show_bug.cgi?id=99188

Patch by Sailesh Agrawal <[email protected]> on 2012-10-24
Reviewed by Tony Chang.

Source/WebCore:

In r57951 we switched to mapping keys by character code.
This regressed the numpad keys which no longer match the Windows virtual key codes.
This CL fixes this by never mapping numpad keys by character code.

Test: platform/mac/fast/events/numpad-keycode-mapping.html

* platform/mac/PlatformEventFactoryMac.mm:
(WebCore::windowsKeyCodeForKeyEvent):

Source/WebKit/chromium:

In r57951 we switched to mapping keys by character code.
This regressed the numpad keys which no longer match the Windows virtual key codes.
This CL fixes this by never mapping numpad keys by character code.

* src/mac/WebInputEventFactory.mm: Disallow mapping numpad keys by character code.
(WebKit::windowsKeyCodeForKeyEvent):
* tests/WebInputEventFactoryTestMac.mm: Test to verify that all numpad keys are correctly mapped.
(TEST):

Tools:

Add key mappings for all numpad keys.

* DumpRenderTree/mac/EventSendingController.mm:
(KeyMappingEntry):
(-[EventSendingController keyDown:withModifiers:withLocation:]): Added all numpad keys.

LayoutTests:

Added test to map numpad keys to windows virtual keycodes. This test is for the Mac port only. DumpRenderTree in the chromium-mac port doesn't use Mac keycodes so this can't be tested on that platform.

* platform/mac/fast/events/numpad-keycode-mapping-expected.txt: Added.
* platform/mac/fast/events/numpad-keycode-mapping.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (132410 => 132411)


--- trunk/LayoutTests/ChangeLog	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/LayoutTests/ChangeLog	2012-10-24 22:36:28 UTC (rev 132411)
@@ -1,3 +1,15 @@
+2012-10-24  Sailesh Agrawal  <[email protected]>
+
+        Incorrect keycodes for numpad /, -, +, .
+        https://bugs.webkit.org/show_bug.cgi?id=99188
+
+        Reviewed by Tony Chang.
+
+        Added test to map numpad keys to windows virtual keycodes. This test is for the Mac port only. DumpRenderTree in the chromium-mac port doesn't use Mac keycodes so this can't be tested on that platform.
+
+        * platform/mac/fast/events/numpad-keycode-mapping-expected.txt: Added.
+        * platform/mac/fast/events/numpad-keycode-mapping.html: Added.
+
 2012-10-24  Levi Weintraub  <[email protected]>
 
         Unreviewed gardening. Marking the software compositing version of

Added: trunk/LayoutTests/platform/mac/fast/events/numpad-keycode-mapping-expected.txt (0 => 132411)


--- trunk/LayoutTests/platform/mac/fast/events/numpad-keycode-mapping-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/events/numpad-keycode-mapping-expected.txt	2012-10-24 22:36:28 UTC (rev 132411)
@@ -0,0 +1,27 @@
+Test that Mac numpad keys are mapped to the correct Windows virtual keycodes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getKeyCode('.') is 0x6E
+PASS getKeyCode('*') is 0x6A
+PASS getKeyCode('+') is 0x6B
+PASS getKeyCode('clear') is 0x0C
+PASS getKeyCode('/') is 0x6F
+PASS getKeyCode('enter') is 0x0D
+PASS getKeyCode('-') is 0x6D
+PASS getKeyCode('=') is 0xBB
+PASS getKeyCode('0') is 0x60
+PASS getKeyCode('1') is 0x61
+PASS getKeyCode('2') is 0x62
+PASS getKeyCode('3') is 0x63
+PASS getKeyCode('4') is 0x64
+PASS getKeyCode('5') is 0x65
+PASS getKeyCode('6') is 0x66
+PASS getKeyCode('7') is 0x67
+PASS getKeyCode('8') is 0x68
+PASS getKeyCode('9') is 0x69
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/mac/fast/events/numpad-keycode-mapping.html (0 => 132411)


--- trunk/LayoutTests/platform/mac/fast/events/numpad-keycode-mapping.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/events/numpad-keycode-mapping.html	2012-10-24 22:36:28 UTC (rev 132411)
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script>
+
+description("Test that Mac numpad keys are mapped to the correct Windows virtual keycodes.");
+
+var lastKeyboardEvent;
+document._onkeydown_ = function(event) {
+    lastKeyboardEvent = event;
+}
+
+function getKeyCode(keyName) {
+    var numpadLocation = 3;
+    eventSender.keyDown(keyName, 0, numpadLocation);
+    return lastKeyboardEvent.keyCode;
+}
+
+if (window.eventSender) {
+    shouldBe("getKeyCode('.')", "0x6E");
+    shouldBe("getKeyCode('*')", "0x6A");
+    shouldBe("getKeyCode('+')", "0x6B");
+    shouldBe("getKeyCode('clear')", "0x0C");
+    shouldBe("getKeyCode('/')", "0x6F");
+    shouldBe("getKeyCode('enter')", "0x0D");
+    shouldBe("getKeyCode('-')", "0x6D");
+    shouldBe("getKeyCode('=')", "0xBB");
+    shouldBe("getKeyCode('0')", "0x60");
+    shouldBe("getKeyCode('1')", "0x61");
+    shouldBe("getKeyCode('2')", "0x62");
+    shouldBe("getKeyCode('3')", "0x63");
+    shouldBe("getKeyCode('4')", "0x64");
+    shouldBe("getKeyCode('5')", "0x65");
+    shouldBe("getKeyCode('6')", "0x66");
+    shouldBe("getKeyCode('7')", "0x67");
+    shouldBe("getKeyCode('8')", "0x68");
+    shouldBe("getKeyCode('9')", "0x69");
+}
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (132410 => 132411)


--- trunk/Source/WebCore/ChangeLog	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/Source/WebCore/ChangeLog	2012-10-24 22:36:28 UTC (rev 132411)
@@ -1,3 +1,19 @@
+2012-10-24  Sailesh Agrawal  <[email protected]>
+
+        Incorrect keycodes for numpad /, -, +, .
+        https://bugs.webkit.org/show_bug.cgi?id=99188
+
+        Reviewed by Tony Chang.
+
+        In r57951 we switched to mapping keys by character code.
+        This regressed the numpad keys which no longer match the Windows virtual key codes.
+        This CL fixes this by never mapping numpad keys by character code.
+
+        Test: platform/mac/fast/events/numpad-keycode-mapping.html
+
+        * platform/mac/PlatformEventFactoryMac.mm:
+        (WebCore::windowsKeyCodeForKeyEvent):
+
 2012-10-24  Simon Fraser  <[email protected]>
 
         Null-check the RenderView in ocument::windowScreenDidChange to fix a crash when saving PDFs

Modified: trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm (132410 => 132411)


--- trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm	2012-10-24 22:36:28 UTC (rev 132411)
@@ -327,7 +327,7 @@
     // 2. Keys for which there is no known Mac virtual key codes, like PrintScreen.
     // 3. Certain punctuation keys. On Windows, these are also remapped depending on current keyboard layout,
     //    but see comment in windowsKeyCodeForCharCode().
-    if ([event type] == NSKeyDown || [event type] == NSKeyUp) {
+    if (!isKeypadEvent(event) && ([event type] == NSKeyDown || [event type] == NSKeyUp)) {
         // Cmd switches Roman letters for Dvorak-QWERTY layout, so try modified characters first.
         NSString* s = [event characters];
         code = [s length] > 0 ? windowsKeyCodeForCharCode([s characterAtIndex:0]) : 0;

Modified: trunk/Source/WebKit/chromium/ChangeLog (132410 => 132411)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-10-24 22:36:28 UTC (rev 132411)
@@ -1,3 +1,19 @@
+2012-10-24  Sailesh Agrawal  <[email protected]>
+
+        Incorrect keycodes for numpad /, -, +, .
+        https://bugs.webkit.org/show_bug.cgi?id=99188
+
+        Reviewed by Tony Chang.
+
+        In r57951 we switched to mapping keys by character code.
+        This regressed the numpad keys which no longer match the Windows virtual key codes.
+        This CL fixes this by never mapping numpad keys by character code.
+
+        * src/mac/WebInputEventFactory.mm: Disallow mapping numpad keys by character code.
+        (WebKit::windowsKeyCodeForKeyEvent):
+        * tests/WebInputEventFactoryTestMac.mm: Test to verify that all numpad keys are correctly mapped.
+        (TEST):
+
 2012-10-24  Terry Anderson  <[email protected]>
 
         Handle two-finger tap gestures in the same way as long-press gestures

Modified: trunk/Source/WebKit/chromium/src/mac/WebInputEventFactory.mm (132410 => 132411)


--- trunk/Source/WebKit/chromium/src/mac/WebInputEventFactory.mm	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/Source/WebKit/chromium/src/mac/WebInputEventFactory.mm	2012-10-24 22:36:28 UTC (rev 132411)
@@ -169,7 +169,7 @@
     // 2. Keys for which there is no known Mac virtual key codes, like PrintScreen.
     // 3. Certain punctuation keys. On Windows, these are also remapped depending on current keyboard layout,
     //    but see comment in windowsKeyCodeForCharCode().
-    if ([event type] == NSKeyDown || [event type] == NSKeyUp) {
+    if (!isKeypadEvent(event) && ([event type] == NSKeyDown || [event type] == NSKeyUp)) {
         // Cmd switches Roman letters for Dvorak-QWERTY layout, so try modified characters first.
         NSString* s = [event characters];
         code = [s length] > 0 ? WebCore::windowsKeyCodeForCharCode([s characterAtIndex:0]) : 0;

Modified: trunk/Source/WebKit/chromium/tests/WebInputEventFactoryTestMac.mm (132410 => 132411)


--- trunk/Source/WebKit/chromium/tests/WebInputEventFactoryTestMac.mm	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/Source/WebKit/chromium/tests/WebInputEventFactoryTestMac.mm	2012-10-24 22:36:28 UTC (rev 132411)
@@ -36,12 +36,19 @@
 #include "KeyboardEvent.h"
 #include "WebInputEvent.h"
 #include "WebInputEventFactory.h"
+#include "WindowsKeyboardCodes.h"
 
 using WebKit::WebInputEventFactory;
 using WebKit::WebKeyboardEvent;
 
 namespace {
 
+struct KeyMappingEntry {
+    int macKeyCode;
+    unichar character;
+    int windowsKeyCode;
+};
+
 NSEvent* BuildFakeKeyEvent(NSUInteger keyCode, unichar character, NSUInteger modifierFlags)
 {
     NSString* string = [NSString stringWithCharacters:&character length:1];
@@ -82,3 +89,35 @@
     webEvent = WebInputEventFactory::keyboardEvent(macEvent);
     EXPECT_EQ(0, webEvent.modifiers);
 }
+
+// Test that numpad keys get mapped correctly.
+TEST(WebInputEventFactoryTestMac, NumPadMapping)
+{
+    KeyMappingEntry table[] =
+    {
+        {65, '.', VK_DECIMAL},
+        {67, '*', VK_MULTIPLY},
+        {69, '+', VK_ADD},
+        {71, NSClearLineFunctionKey, VK_CLEAR},
+        {75, '/', VK_DIVIDE},
+        {76, 3,   VK_RETURN},
+        {78, '-', VK_SUBTRACT},
+        {81, '=', VK_OEM_PLUS},
+        {82, '0', VK_NUMPAD0},
+        {83, '1', VK_NUMPAD1},
+        {84, '2', VK_NUMPAD2},
+        {85, '3', VK_NUMPAD3},
+        {86, '4', VK_NUMPAD4},
+        {87, '5', VK_NUMPAD5},
+        {88, '6', VK_NUMPAD6},
+        {89, '7', VK_NUMPAD7},
+        {91, '8', VK_NUMPAD8},
+        {92, '9', VK_NUMPAD9},
+    };
+
+    for (size_t i = 0; i < arraysize(table); ++i) {
+        NSEvent* macEvent = BuildFakeKeyEvent(table[i].macKeyCode, table[i].character, 0);
+        WebKeyboardEvent webEvent = WebInputEventFactory::keyboardEvent(macEvent);
+        EXPECT_EQ(table[i].windowsKeyCode, webEvent.windowsKeyCode);
+    }
+}

Modified: trunk/Tools/ChangeLog (132410 => 132411)


--- trunk/Tools/ChangeLog	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/Tools/ChangeLog	2012-10-24 22:36:28 UTC (rev 132411)
@@ -1,3 +1,16 @@
+2012-10-24  Sailesh Agrawal  <[email protected]>
+
+        Incorrect keycodes for numpad /, -, +, .
+        https://bugs.webkit.org/show_bug.cgi?id=99188
+
+        Reviewed by Tony Chang.
+
+        Add key mappings for all numpad keys.
+
+        * DumpRenderTree/mac/EventSendingController.mm:
+        (KeyMappingEntry):
+        (-[EventSendingController keyDown:withModifiers:withLocation:]): Added all numpad keys.
+
 2012-10-24  Dirk Pranke  <[email protected]>
 
         webkitpy: clean up references to Skipped files

Modified: trunk/Tools/DumpRenderTree/mac/EventSendingController.mm (132410 => 132411)


--- trunk/Tools/DumpRenderTree/mac/EventSendingController.mm	2012-10-24 22:04:00 UTC (rev 132410)
+++ trunk/Tools/DumpRenderTree/mac/EventSendingController.mm	2012-10-24 22:36:28 UTC (rev 132411)
@@ -57,6 +57,13 @@
     NoMouseButton = -1
 };
 
+struct KeyMappingEntry {
+    int macKeyCode;
+    int macNumpadKeyCode;
+    unichar character;
+    NSString* characterName;
+};
+
 NSPoint lastMousePosition;
 NSPoint lastClickPosition;
 int lastClickButton = NoMouseButton;
@@ -699,14 +706,6 @@
         keyCode = 0x4C;
     else if ([character isEqualToString:@"\x8"])
         keyCode = 0x33;
-    else if ([character isEqualToString:@"7"])
-        keyCode = 0x1A;
-    else if ([character isEqualToString:@"5"])
-        keyCode = 0x17;
-    else if ([character isEqualToString:@"9"])
-        keyCode = 0x19;
-    else if ([character isEqualToString:@"0"])
-        keyCode = 0x1D;
     else if ([character isEqualToString:@"a"])
         keyCode = 0x00;
     else if ([character isEqualToString:@"b"])
@@ -716,6 +715,38 @@
     else if ([character isEqualToString:@"e"])
         keyCode = 0x0E;
 
+    KeyMappingEntry table[] = {
+        {0x2F, 0x41, '.', nil},
+        {0,    0x43, '*', nil},
+        {0,    0x45, '+', nil},
+        {0,    0x47, NSClearLineFunctionKey, @"clear"},
+        {0x2C, 0x4B, '/', nil},
+        {0,    0x4C, 3, @"enter" },
+        {0x1B, 0x4E, '-', nil},
+        {0x18, 0x51, '=', nil},
+        {0x1D, 0x52, '0', nil},
+        {0x12, 0x53, '1', nil},
+        {0x13, 0x54, '2', nil},
+        {0x14, 0x55, '3', nil},
+        {0x15, 0x56, '4', nil},
+        {0x17, 0x57, '5', nil},
+        {0x16, 0x58, '6', nil},
+        {0x1A, 0x59, '7', nil},
+        {0x1C, 0x5B, '8', nil},
+        {0x19, 0x5C, '9', nil},
+    };
+    for (unsigned i = 0; i < WTF_ARRAY_LENGTH(table); ++i) {
+        NSString* currentCharacterString = [NSString stringWithCharacters:&table[i].character length:1];
+        if ([character isEqualToString:currentCharacterString] || [character isEqualToString:table[i].characterName]) {
+            if (keyLocation == DOM_KEY_LOCATION_NUMPAD)
+                keyCode = table[i].macNumpadKeyCode;
+            else
+                keyCode = table[i].macKeyCode;
+            eventCharacter = currentCharacterString;
+            break;
+        }
+    }
+
     NSString *charactersIgnoringModifiers = eventCharacter;
 
     int modifierFlags = 0;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to