Mac Chromium: Ignore system numpad modifier
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Oct 2012 22:07:19 +0000 (22:07 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Oct 2012 22:07:19 +0000 (22:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97161

Patch by Sailesh Agrawal <sail@chromium.org> on 2012-10-08
Reviewed by Tony Chang.

On Mac, arrow key events have numpad modifier set. This is inconsistent with other platforms.

My fix is to only rely on keycode to decide when to set the numpad modifier.

This code is not exersided by layout tests so I added a new unit test for this.

* WebKit.gypi:
* WebKitUnitTests.gyp:
* src/mac/WebInputEventFactory.mm:
(WebKit::isKeypadEvent): Removed check for numpad modifier.
* tests/WebInputEventFactoryTestMac.mm: Added.
(TEST): Added new test for WebInputEventFactory::keyboardEvent().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130691 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/WebKitUnitTests.gyp
Source/WebKit/chromium/src/mac/WebInputEventFactory.mm
Source/WebKit/chromium/tests/WebInputEventFactoryTestMac.mm [new file with mode: 0644]

index c4a06d9..2943332 100644 (file)
@@ -1,3 +1,23 @@
+2012-10-08  Sailesh Agrawal  <sail@chromium.org>
+
+        Mac Chromium: Ignore system numpad modifier
+        https://bugs.webkit.org/show_bug.cgi?id=97161
+
+        Reviewed by Tony Chang.
+
+        On Mac, arrow key events have numpad modifier set. This is inconsistent with other platforms.
+
+        My fix is to only rely on keycode to decide when to set the numpad modifier.
+
+        This code is not exersided by layout tests so I added a new unit test for this.
+
+        * WebKit.gypi:
+        * WebKitUnitTests.gyp:
+        * src/mac/WebInputEventFactory.mm:
+        (WebKit::isKeypadEvent): Removed check for numpad modifier.
+        * tests/WebInputEventFactoryTestMac.mm: Added.
+        (TEST): Added new test for WebInputEventFactory::keyboardEvent().
+
 2012-10-08  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed.  Rolled DEPS.
index f428cb1..e817f9a 100644 (file)
             'tests/WebFrameTest.cpp',
             'tests/WebImageTest.cpp',
             'tests/WebInputEventConversionTest.cpp',
+            'tests/WebInputEventFactoryTestMac.mm',
             'tests/WebMediaPlayerClientImplTest.cpp',
             'tests/WebPageNewSerializerTest.cpp',
             'tests/WebPageSerializerTest.cpp',
index 12d0a95..0063125 100644 (file)
                         '<(chromium_src_dir)/testing/android/native_test.gyp:native_test_native_code',
                     ],
                 }],
+                ['OS=="mac"', {
+                    'include_dirs': [
+                        'public/mac',
+                    ],
+                }],
             ],
         }                
     ], # targets
index b3a22fe..4854ae2 100644 (file)
@@ -135,9 +135,6 @@ static bool isKeypadEvent(NSEvent* event)
         return false;
     }
 
-    if ([event modifierFlags] & NSNumericPadKeyMask)
-        return true;
-
     switch ([event keyCode]) {
     case 71: // Clear
     case 81: // =
diff --git a/Source/WebKit/chromium/tests/WebInputEventFactoryTestMac.mm b/Source/WebKit/chromium/tests/WebInputEventFactoryTestMac.mm
new file mode 100644 (file)
index 0000000..73a29bc
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#import <Cocoa/Cocoa.h>
+#include <gtest/gtest.h>
+
+#include "KeyboardEvent.h"
+#include "WebInputEvent.h"
+#include "WebInputEventFactory.h"
+
+using WebKit::WebInputEventFactory;
+using WebKit::WebKeyboardEvent;
+
+namespace {
+
+NSEvent* BuildFakeKeyEvent(NSUInteger keyCode, unichar character, NSUInteger modifierFlags)
+{
+    NSString* string = [NSString stringWithCharacters:&character length:1];
+    return [NSEvent keyEventWithType:NSKeyDown
+                            location:NSZeroPoint
+                       modifierFlags:modifierFlags
+                           timestamp:0.0
+                        windowNumber:0
+                             context:nil
+                          characters:string
+         charactersIgnoringModifiers:string
+                           isARepeat:NO
+                             keyCode:keyCode];
+}
+
+} // namespace
+
+// Test that arrow keys don't have numpad modifier set.
+TEST(WebInputEventFactoryTestMac, ArrowKeyNumPad)
+{
+    // Left
+    NSEvent* macEvent = BuildFakeKeyEvent(0x7B, NSLeftArrowFunctionKey, NSNumericPadKeyMask);
+    WebKeyboardEvent webEvent = WebInputEventFactory::keyboardEvent(macEvent);
+    EXPECT_EQ(0, webEvent.modifiers);
+
+    // Right
+    macEvent = BuildFakeKeyEvent(0x7C, NSRightArrowFunctionKey, NSNumericPadKeyMask);
+    webEvent = WebInputEventFactory::keyboardEvent(macEvent);
+    EXPECT_EQ(0, webEvent.modifiers);
+
+    // Down
+    macEvent = BuildFakeKeyEvent(0x7D, NSDownArrowFunctionKey, NSNumericPadKeyMask);
+    webEvent = WebInputEventFactory::keyboardEvent(macEvent);
+    EXPECT_EQ(0, webEvent.modifiers);
+
+    // Up
+    macEvent = BuildFakeKeyEvent(0x7E, NSUpArrowFunctionKey, NSNumericPadKeyMask);
+    webEvent = WebInputEventFactory::keyboardEvent(macEvent);
+    EXPECT_EQ(0, webEvent.modifiers);
+}