- Revision
- 272489
- Author
- [email protected]
- Date
- 2021-02-08 05:52:53 -0800 (Mon, 08 Feb 2021)
Log Message
[GTK] event.ctrlKey and other are false in keydown event
https://bugs.webkit.org/show_bug.cgi?id=221456
Reviewed by Adrian Perez de Castro.
Source/WebKit:
Modifier keys were not being set on "keydown" events.
For example if you check event.ctrlKey (and other) you'll get always false when the user only typed Ctrl key
(it'll be true when it's in combination with some other key, like Ctrl + P).
This is due to some differences on how X system manages the modifier keys (see http://crbug.com/127142#c8),
but this patch will align WebKitGTK with other platforms and browsers on this case.
Test: fast/events/keyboardevent-modifier.html
* Shared/gtk/WebEventFactory.cpp:
(WebKit::modifiersForEvent): In the case of a keyboard press event check if some modifier key has been pressed.
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseSynthesizeKeyEvent): Check if some modifier key has been pressed.
LayoutTests:
The test only pass in GTK right now, despite testing it manually works fine in all platforms,
it looks like they might need changes to make the test pass.
* TestExpectations:
* fast/events/keyboardevent-modifier-expected.txt: Added.
* fast/events/keyboardevent-modifier.html: Added.
* platform/gtk/TestExpectations:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (272488 => 272489)
--- trunk/LayoutTests/ChangeLog 2021-02-08 13:31:56 UTC (rev 272488)
+++ trunk/LayoutTests/ChangeLog 2021-02-08 13:52:53 UTC (rev 272489)
@@ -1,3 +1,18 @@
+2021-02-08 Manuel Rego Casasnovas <[email protected]>
+
+ [GTK] event.ctrlKey and other are false in keydown event
+ https://bugs.webkit.org/show_bug.cgi?id=221456
+
+ Reviewed by Adrian Perez de Castro.
+
+ The test only pass in GTK right now, despite testing it manually works fine in all platforms,
+ it looks like they might need changes to make the test pass.
+
+ * TestExpectations:
+ * fast/events/keyboardevent-modifier-expected.txt: Added.
+ * fast/events/keyboardevent-modifier.html: Added.
+ * platform/gtk/TestExpectations:
+
2021-02-08 Philippe Normand <[email protected]>
Permission request API for MediaKeySystem access support
Modified: trunk/LayoutTests/TestExpectations (272488 => 272489)
--- trunk/LayoutTests/TestExpectations 2021-02-08 13:31:56 UTC (rev 272488)
+++ trunk/LayoutTests/TestExpectations 2021-02-08 13:52:53 UTC (rev 272489)
@@ -985,6 +985,7 @@
fast/misc/valid-primary-screen-displayID.html [ Skip ]
fast/events/detect-caps-lock.html [ Skip ]
+fast/events/keyboardevent-modifier.html [ Skip ]
fast/forms/auto-fill-button/caps-lock-indicator-should-be-visible-after-hiding-auto-fill-strong-password-button.html [ Skip ]
fast/forms/auto-fill-button/caps-lock-indicator-should-not-be-visible-when-auto-fill-strong-password-button-is-visible.html [ Skip ]
fast/forms/password-scrolled-after-caps-lock-toggled.html [ Skip ]
Added: trunk/LayoutTests/fast/events/keyboardevent-modifier-expected.txt (0 => 272489)
--- trunk/LayoutTests/fast/events/keyboardevent-modifier-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/keyboardevent-modifier-expected.txt 2021-02-08 13:52:53 UTC (rev 272489)
@@ -0,0 +1,9 @@
+
+
+PASS Check key: leftControl - event.key: Control
+PASS Check key: rightControl - event.key: Control
+PASS Check key: leftAlt - event.key: Alt
+PASS Check key: rightAlt - event.key: Alt
+PASS Check key: leftShift - event.key: Shift
+PASS Check key: rightShift - event.key: Shift
+
Added: trunk/LayoutTests/fast/events/keyboardevent-modifier.html (0 => 272489)
--- trunk/LayoutTests/fast/events/keyboardevent-modifier.html (rev 0)
+++ trunk/LayoutTests/fast/events/keyboardevent-modifier.html 2021-02-08 13:52:53 UTC (rev 272489)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src=""
+<script src=""
+<input type="text" id="testInput">
+<script>
+var input = document.getElementById("testInput");
+input.focus();
+
+function sendKeyAndTest(key, ctrlKey, altKey, shiftKey)
+{
+ input._onkeydown_ = function(event) {
+ test(function() {
+ assert_equals(event.ctrlKey, ctrlKey, "event.ctrlKey is: " + ctrlKey ? "true" : "false");
+ assert_equals(event.altKey, altKey, "event.altKey is: " + altKey ? "true" : "false");
+ assert_equals(event.shiftKey, shiftKey, "event.shiftKey is: " + shiftKey ? "true" : "false");
+ }, "Check key: " + key + " - event.key: " + event.key);
+ };
+ eventSender.keyDown(key, []);
+}
+
+sendKeyAndTest("leftControl", true, false, false);
+sendKeyAndTest("rightControl", true, false, false);
+sendKeyAndTest("leftAlt", false, true, false);
+sendKeyAndTest("rightAlt", false, true, false);
+sendKeyAndTest("leftShift", false, false, true);
+sendKeyAndTest("rightShift", false, false, true);
+
+</script>
Modified: trunk/LayoutTests/platform/gtk/TestExpectations (272488 => 272489)
--- trunk/LayoutTests/platform/gtk/TestExpectations 2021-02-08 13:31:56 UTC (rev 272488)
+++ trunk/LayoutTests/platform/gtk/TestExpectations 2021-02-08 13:52:53 UTC (rev 272489)
@@ -55,6 +55,8 @@
imported/w3c/web-platform-tests/css/css-multicol/multicol-width-ch-001.xht [ Pass ]
+fast/events/keyboardevent-modifier.html [ Pass ]
+
# permessage-deflate WebSocket extension
# css-values passing for us
Modified: trunk/Source/WebKit/ChangeLog (272488 => 272489)
--- trunk/Source/WebKit/ChangeLog 2021-02-08 13:31:56 UTC (rev 272488)
+++ trunk/Source/WebKit/ChangeLog 2021-02-08 13:52:53 UTC (rev 272489)
@@ -1,3 +1,23 @@
+2021-02-08 Manuel Rego Casasnovas <[email protected]>
+
+ [GTK] event.ctrlKey and other are false in keydown event
+ https://bugs.webkit.org/show_bug.cgi?id=221456
+
+ Reviewed by Adrian Perez de Castro.
+
+ Modifier keys were not being set on "keydown" events.
+ For example if you check event.ctrlKey (and other) you'll get always false when the user only typed Ctrl key
+ (it'll be true when it's in combination with some other key, like Ctrl + P).
+ This is due to some differences on how X system manages the modifier keys (see http://crbug.com/127142#c8),
+ but this patch will align WebKitGTK with other platforms and browsers on this case.
+
+ Test: fast/events/keyboardevent-modifier.html
+
+ * Shared/gtk/WebEventFactory.cpp:
+ (WebKit::modifiersForEvent): In the case of a keyboard press event check if some modifier key has been pressed.
+ * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+ (webkitWebViewBaseSynthesizeKeyEvent): Check if some modifier key has been pressed.
+
2021-02-08 Antoine Quint <[email protected]>
Unreviewed unified build fix.
Modified: trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp (272488 => 272489)
--- trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp 2021-02-08 13:31:56 UTC (rev 272488)
+++ trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp 2021-02-08 13:52:53 UTC (rev 272489)
@@ -67,6 +67,37 @@
if (PlatformKeyboardEvent::modifiersContainCapsLock(state))
modifiers.add(WebEvent::Modifier::CapsLockKey);
+ GdkEventType type = gdk_event_get_event_type(const_cast<GdkEvent*>(event));
+ if (type != GDK_KEY_PRESS)
+ return modifiers;
+
+ // Modifier masks are set different in X than other platforms. This code makes WebKitGTK
+ // to behave similar to other platforms and other browsers under X (see http://crbug.com/127142#c8).
+
+ guint keyval;
+ gdk_event_get_keyval(event, &keyval);
+ switch (keyval) {
+ case GDK_KEY_Control_L:
+ case GDK_KEY_Control_R:
+ modifiers.add(WebEvent::Modifier::ControlKey);
+ break;
+ case GDK_KEY_Shift_L:
+ case GDK_KEY_Shift_R:
+ modifiers.add(WebEvent::Modifier::ShiftKey);
+ break;
+ case GDK_KEY_Alt_L:
+ case GDK_KEY_Alt_R:
+ modifiers.add(WebEvent::Modifier::AltKey);
+ break;
+ case GDK_KEY_Meta_L:
+ case GDK_KEY_Meta_R:
+ modifiers.add(WebEvent::Modifier::MetaKey);
+ break;
+ case GDK_KEY_Caps_Lock:
+ modifiers.add(WebEvent::Modifier::CapsLockKey);
+ break;
+ }
+
return modifiers;
}
Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp (272488 => 272489)
--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp 2021-02-08 13:31:56 UTC (rev 272488)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp 2021-02-08 13:52:53 UTC (rev 272489)
@@ -2687,6 +2687,30 @@
auto webEventModifiers = toWebKitModifiers(modifiers);
if (type != KeyEventType::Release) {
+ // Modifier masks are set different in X than other platforms. This code makes WebKitGTK
+ // to behave similar to other platforms and other browsers under X (see http://crbug.com/127142#c8).
+ switch (keyval) {
+ case GDK_KEY_Control_L:
+ case GDK_KEY_Control_R:
+ webEventModifiers.add(WebEvent::Modifier::ControlKey);
+ break;
+ case GDK_KEY_Shift_L:
+ case GDK_KEY_Shift_R:
+ webEventModifiers.add(WebEvent::Modifier::ShiftKey);
+ break;
+ case GDK_KEY_Alt_L:
+ case GDK_KEY_Alt_R:
+ webEventModifiers.add(WebEvent::Modifier::AltKey);
+ break;
+ case GDK_KEY_Meta_L:
+ case GDK_KEY_Meta_R:
+ webEventModifiers.add(WebEvent::Modifier::MetaKey);
+ break;
+ case GDK_KEY_Caps_Lock:
+ webEventModifiers.add(WebEvent::Modifier::CapsLockKey);
+ break;
+ }
+
auto filterResult = priv->inputMethodFilter.filterKeyEvent(GDK_KEY_PRESS, keyval, keycode, modifiers);
if (!filterResult.handled) {
priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(