diff options
author | Andi Gallo <andigallo@proton.me> | 2023-05-23 02:33:57 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-23 06:02:00 +0200 |
commit | 1bbfe4630d31ba0c00a4c12c2d35bd0fa2494e3b (patch) | |
tree | e11ddf5389d8dfeb7a5f18a20b82f0451e2a02c2 | |
parent | 02d94a303c8c8329061e990dbe2e9914fae19965 (diff) | |
download | serenity-1bbfe4630d31ba0c00a4c12c2d35bd0fa2494e3b.zip |
LibWeb: Preserve case for key events
Case-preserving behavior matches observed behavior of other browsers and
the specification.
-rw-r--r-- | Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp index aed2fe34bb..7c2a200202 100644 --- a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp +++ b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp @@ -66,12 +66,26 @@ static unsigned long determine_key_code(KeyCode platform_key, u32 code_point) return platform_key; } +static ErrorOr<String> get_event_key(KeyCode platform_key, u32 code_point) +{ + auto event_key = String::from_deprecated_string(key_code_to_string(platform_key)); + if (event_key.is_error()) { + return event_key; + } + // Original case should be preserved for the key value of the event. + // https://www.w3.org/TR/uievents-key/#key-attr-values + if (is_ascii_lower_alpha(code_point)) { + event_key = event_key.release_value().to_lowercase(); + } + return event_key; +} + WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, KeyCode platform_key, unsigned modifiers, u32 code_point) { auto& vm = realm.vm(); // FIXME: Figure out what these should actually contain. - auto event_key = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(key_code_to_string(platform_key))); + auto event_key = TRY_OR_THROW_OOM(vm, get_event_key(platform_key, code_point)); auto event_code = TRY_OR_THROW_OOM(vm, "FIXME"_string); auto key_code = determine_key_code(platform_key, code_point); |