[iOS][WK2] KeyboardEvent.key always returns an empty string
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jan 2017 15:45:35 +0000 (15:45 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jan 2017 15:45:35 +0000 (15:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166918
<rdar://problem/29861147>

Reviewed by Wenson Hsieh.

Source/WebKit2:

Make sure that KeyboardEvent.key gets properly initialized on iOS / WK2.

* Shared/WebEvent.h:
* Shared/WebKeyboardEvent.cpp:
(WebKit::WebKeyboardEvent::WebKeyboardEvent):
* Shared/ios/WebIOSEventFactory.mm:
(WebIOSEventFactory::createWebKeyboardEvent):

LayoutTests:

Add layout test coverage.

* fast/events/ios/keyboard-event-key-attribute-expected.txt: Added.
* fast/events/ios/keyboard-event-key-attribute.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/events/ios/keyboard-event-key-attribute-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/keyboard-event-key-attribute.html [new file with mode: 0644]
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebEvent.h
Source/WebKit2/Shared/WebKeyboardEvent.cpp
Source/WebKit2/Shared/ios/WebIOSEventFactory.mm

index d2a153c..5a70f15 100644 (file)
@@ -1,3 +1,16 @@
+2017-01-11  Chris Dumez  <cdumez@apple.com>
+
+        [iOS][WK2] KeyboardEvent.key always returns an empty string
+        https://bugs.webkit.org/show_bug.cgi?id=166918
+        <rdar://problem/29861147>
+
+        Reviewed by Wenson Hsieh.
+
+        Add layout test coverage.
+
+        * fast/events/ios/keyboard-event-key-attribute-expected.txt: Added.
+        * fast/events/ios/keyboard-event-key-attribute.html: Added.
+
 2017-01-11  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
 
         [EFL] Update TestExpectation file for Ubuntu 16.04.
diff --git a/LayoutTests/fast/events/ios/keyboard-event-key-attribute-expected.txt b/LayoutTests/fast/events/ios/keyboard-event-key-attribute-expected.txt
new file mode 100644 (file)
index 0000000..95e308d
--- /dev/null
@@ -0,0 +1,10 @@
+Tests that KeyboardEvent.key is properly initialized on iOS.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.key is "a"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/ios/keyboard-event-key-attribute.html b/LayoutTests/fast/events/ios/keyboard-event-key-attribute.html
new file mode 100644 (file)
index 0000000..9f8f880
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta name="viewport" content="width=device-width">
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<input id="testInput" type="text">
+<script>
+description("Tests that KeyboardEvent.key is properly initialized on iOS.");
+jsTestIsAsync = true;
+
+function getTypingUIScript(x, y)
+{
+    return `
+        (function() {
+            uiController.didShowKeyboardCallback = function() {
+                uiController.typeCharacterUsingHardwareKeyboard('a', function() {
+                    uiController.uiScriptComplete();
+                });
+            };
+            uiController.singleTapAtPoint(${x}, ${y}, function() { });
+        })();`
+}
+
+var testInput = document.getElementById("testInput");
+testInput.onkeydown = function(e) {
+    event = e;
+    shouldBeEqualToString("event.key", "a");
+    finishJSTest();
+};
+
+const x = testInput.offsetLeft + 5;
+const y = testInput.offsetTop + 5;
+testRunner.runUIScript(getTypingUIScript(x, y), function() { });
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index 531e1b2..0fc35ba 100644 (file)
@@ -1,3 +1,19 @@
+2017-01-11  Chris Dumez  <cdumez@apple.com>
+
+        [iOS][WK2] KeyboardEvent.key always returns an empty string
+        https://bugs.webkit.org/show_bug.cgi?id=166918
+        <rdar://problem/29861147>
+
+        Reviewed by Wenson Hsieh.
+
+        Make sure that KeyboardEvent.key gets properly initialized on iOS / WK2.
+
+        * Shared/WebEvent.h:
+        * Shared/WebKeyboardEvent.cpp:
+        (WebKit::WebKeyboardEvent::WebKeyboardEvent):
+        * Shared/ios/WebIOSEventFactory.mm:
+        (WebIOSEventFactory::createWebKeyboardEvent):
+
 2017-01-10  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         [GTK] No way for applications to set notification permissions without waiting for permission request
index 85dec2f..ca92c30 100644 (file)
@@ -247,6 +247,8 @@ public:
     WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, const Vector<WebCore::KeypressCommand>&, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
 #elif PLATFORM(GTK)
     WebKeyboardEvent(Type, const String& text, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, Modifiers, double timestamp);
+#elif PLATFORM(IOS)
+    WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& key, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
 #else
     WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
 #endif
index a6cbcab..00d2b91 100644 (file)
@@ -77,6 +77,24 @@ WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String&
     ASSERT(isKeyboardEventType(type));
 }
 
+#elif PLATFORM(IOS)
+
+WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& key, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp)
+    : WebEvent(type, modifiers, timestamp)
+    , m_text(text)
+    , m_unmodifiedText(unmodifiedText)
+    , m_key(key)
+    , m_keyIdentifier(keyIdentifier)
+    , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
+    , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
+    , m_macCharCode(macCharCode)
+    , m_isAutoRepeat(isAutoRepeat)
+    , m_isKeypad(isKeypad)
+    , m_isSystemKey(isSystemKey)
+{
+    ASSERT(isKeyboardEventType(type));
+}
+
 #else
 
 WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp)
index 117c02d..ee80233 100644 (file)
@@ -55,6 +55,7 @@ WebKit::WebKeyboardEvent WebIOSEventFactory::createWebKeyboardEvent(WebIOSEvent
     WebKit::WebEvent::Type type = (event.type == WebEventKeyUp) ? WebKit::WebEvent::KeyUp : WebKit::WebEvent::KeyDown;
     String text = event.characters;
     String unmodifiedText = event.charactersIgnoringModifiers;
+    String key = WebCore::keyForKeyEvent(event);
     String keyIdentifier = WebCore::keyIdentifierForKeyEvent(event);
     int windowsVirtualKeyCode = event.keyCode;
     int nativeVirtualKeyCode = event.keyCode;
@@ -83,7 +84,7 @@ WebKit::WebKeyboardEvent WebIOSEventFactory::createWebKeyboardEvent(WebIOSEvent
         unmodifiedText = text;
     }
 
-    return WebKit::WebKeyboardEvent(type, text, unmodifiedText, keyIdentifier, windowsVirtualKeyCode, nativeVirtualKeyCode, macCharCode, autoRepeat, isKeypad, isSystemKey, modifiers, timestamp);
+    return WebKit::WebKeyboardEvent(type, text, unmodifiedText, key, keyIdentifier, windowsVirtualKeyCode, nativeVirtualKeyCode, macCharCode, autoRepeat, isKeypad, isSystemKey, modifiers, timestamp);
 }
 
 #endif // PLATFORM(IOS)