Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 57433782cf018a78f66796bc6412e159a21ac082
https://github.com/WebKit/WebKit/commit/57433782cf018a78f66796bc6412e159a21ac082
Author: Chris Dumez <[email protected]>
Date: 2026-06-25 (Thu, 25 Jun 2026)
Changed paths:
M
LayoutTests/fast/events/constructors/keyboard-event-constructor-expected.txt
M LayoutTests/fast/events/constructors/keyboard-event-constructor.html
M
LayoutTests/fast/events/constructors/keyboard-event-getModifierState-expected.txt
M LayoutTests/fast/events/constructors/keyboard-event-getModifierState.html
M
LayoutTests/fast/events/constructors/mouse-event-getModifierState-expected.txt
M LayoutTests/fast/events/constructors/mouse-event-getModifierState.html
M LayoutTests/fast/events/init-event-clears-capslock-expected.txt
M LayoutTests/fast/events/init-event-clears-capslock.html
A
LayoutTests/imported/w3c/web-platform-tests/uievents/constructors/event-getmodifierstate-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/uievents/constructors/event-getmodifierstate.html
M Source/WebCore/dom/UIEventWithKeyState.cpp
M Source/WebCore/dom/UIEventWithKeyState.h
M Source/WebCore/platform/PlatformEvent.h
M Source/WebCore/platform/win/WindowsKeyNames.cpp
M Source/WebCore/platform/win/WindowsKeyNames.h
M Source/WebKit/Shared/WebEvent.serialization.in
M Source/WebKit/Shared/WebEventConversion.cpp
M Source/WebKit/Shared/WebEventModifier.cpp
M Source/WebKit/Shared/WebEventModifier.h
M Source/WebKit/Shared/gtk/WebEventFactory.cpp
M Source/WebKit/Shared/win/WebEventFactory.cpp
M Tools/TestWebKitAPI/PlatformWin.cmake
A Tools/TestWebKitAPI/Tests/WebCore/win/WindowsKeyNames.cpp
Log Message:
-----------
KeyboardEvent/MouseEvent getModifierState("AltGraph") always returns false
https://bugs.webkit.org/show_bug.cgi?id=317576
Reviewed by Darin Adler and Anne van Kesteren.
UIEventWithKeyState tracks the AltGraph modifier: modifiersFromInitializer()
reads EventModifierInit.modifierAltGraph and records Modifier::AltGraphKey in
m_modifiers. However, getModifierState() had no branch for the "AltGraph" key
identifier, so it fell through to the default and returned false even when the
event was constructed with modifierAltGraph: true. This diverges from the UI
Events specification, which lists "AltGraph" as a valid modifier key value, and
from Blink and Gecko, both of which report it.
Add an altGraphKey() accessor alongside capsLockKey() and handle "AltGraph" in
getModifierState(). This fixes the JS-constructed (initEvent) path.
Beyond that, the AltGraph state was never propagated for trusted (native) events
on any platform. The PlatformEventModifier::AltGraphKey bit was set only from
initializers, and the WebKit-process WebEventModifier enum did not even have an
AltGraphKey value, so the bit was dropped crossing the UI/Web process boundary.
As a result getModifierState("AltGraph") would still return false for real
keystrokes even on keyboards that have an AltGr key.
The UI Events specification states that "Some operating systems simulate the
AltGraph modifier key with the combination of the Alt and Control modifier keys"
and that "Implementations are encouraged to use the AltGraph modifier key"
(https://www.w3.org/TR/uievents/#keys-modifiers). It lists AltGraph as a
first-class modifier key value and places no normative equivalence between
AltGraph and Control+Alt. Blink and Gecko both follow this guidance, exposing
AltGraph rather than Control + Alt for AltGr input. This change matches them; it
does not implement the broader (and incorrect) notion that any Control+Alt is
AltGraph (https://webkit.org/b/76988), which would break genuine Control+Alt
shortcuts.
Plumb AltGraph through the trusted-event path:
- Add WebEventModifier::AltGraphKey and serialize it, and carry it through both
directions of WebEventConversion as well as
modifiersFromPlatformEventModifiers.
- Windows has no dedicated AltGr key and, on layouts that define AltGraph,
simulates it via the Control+Alt combination. WindowsKeyNames::
shouldExposeAltGraphForKeyEvent() reports AltGraph in place of Control + Alt
in
the same three cases Blink does: a held right-Alt (VK_RMENU) on such a layout
(regardless of which key it modifies); a character message (WM_CHAR /
WM_SYSCHAR / WM_IME_CHAR) delivered while Control and Alt are down (the
produced
character is itself the evidence of AltGr); and a key whose printable
character
requires the Control+Alt combination on the active layout (an AltGraph-shifted
key). Mouse and wheel events carry no key code, so they use the right-Alt case
alone via shouldExposeLeftControlPlusRightAltAsAltGraph(). Both paths reuse
the
existing m_hasAltGraph layout detection and m_printableKeyCodeToKey lookup.
- GTK: map the X11 Mod5 state (GTK3) and the ISO_Level3/Level5 key values to
AltGraphKey. GTK4 no longer exposes the Mod5 mask through GdkModifierType, so
only the AltGraph key event itself is covered there.
macOS/iOS keyboards have no AltGr key, so the modifier is intentionally not
populated from native events on those platforms.
The accompanying web-platform-test exhaustively covers getModifierState() for
every modifier exposed through EventModifierInit (Control, Shift, Alt, Meta,
AltGraph, CapsLock) on both KeyboardEvent and MouseEvent: each modifier set in
isolation, all of them set together, and none set, asserting independence and
that the spec modifiers without an init member always read back as false.
The Windows AltGr handling cannot be exercised from a layout test (it depends on
the active OS keyboard layout), so it is covered by a TestWebKitAPI unit test
that mirrors Chromium's AltGraphEventTest: it activates the US English and
French (France) layouts, synthesizes the relevant key state, and asserts that
WindowsKeyNames reports AltGraph for the right-Alt, AltGraph-shifted, and
character-message cases while leaving plain Control+Alt and AltGraph-less
layouts
untouched. It skips gracefully when a layout is not installed.
Test:
imported/w3c/web-platform-tests/uievents/constructors/event-getmodifierstate.html
* LayoutTests/fast/events/constructors/keyboard-event-constructor-expected.txt:
* LayoutTests/fast/events/constructors/keyboard-event-constructor.html:
*
LayoutTests/fast/events/constructors/keyboard-event-getModifierState-expected.txt:
* LayoutTests/fast/events/constructors/keyboard-event-getModifierState.html:
*
LayoutTests/fast/events/constructors/mouse-event-getModifierState-expected.txt:
* LayoutTests/fast/events/constructors/mouse-event-getModifierState.html:
* LayoutTests/fast/events/init-event-clears-capslock-expected.txt:
* LayoutTests/fast/events/init-event-clears-capslock.html:
*
LayoutTests/imported/w3c/web-platform-tests/uievents/constructors/event-getmodifierstate-expected.txt:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/uievents/constructors/event-getmodifierstate.html:
Added.
* Source/WebCore/dom/UIEventWithKeyState.cpp:
(WebCore::UIEventWithKeyState::getModifierState const):
* Source/WebCore/dom/UIEventWithKeyState.h:
(WebCore::UIEventWithKeyState::altGraphKey const):
* Source/WebCore/platform/PlatformEvent.h:
* Source/WebCore/platform/win/WindowsKeyNames.cpp:
(WebCore::WindowsKeyNames::currentKeyModifiers):
(WebCore::WindowsKeyNames::printableKeyFromVirtualKey):
(WebCore::WindowsKeyNames::domKeyFromParams):
(WebCore::WindowsKeyNames::shouldExposeLeftControlPlusRightAltAsAltGraph):
(WebCore::WindowsKeyNames::shouldExposeAltGraphForKeyEvent):
* Source/WebCore/platform/win/WindowsKeyNames.h:
* Source/WebKit/Shared/WebEvent.serialization.in:
* Source/WebKit/Shared/WebEventConversion.cpp:
(WebKit::platform):
(WebKit::kit):
* Source/WebKit/Shared/WebEventModifier.cpp:
(WebKit::modifiersFromPlatformEventModifiers):
* Source/WebKit/Shared/WebEventModifier.h:
* Source/WebKit/Shared/gtk/WebEventFactory.cpp:
(WebKit::modifiersForEvent):
* Source/WebKit/Shared/win/WebEventFactory.cpp:
(WebKit::modifiersForEvent):
(WebKit::modifiersForCurrentKeyState):
(WebKit::WebEventFactory::createWebKeyboardEvent):
* Tools/TestWebKitAPI/PlatformWin.cmake:
* Tools/TestWebKitAPI/Tests/WebCore/win/WindowsKeyNames.cpp: Added.
Canonical link: https://commits.webkit.org/315804@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications