From af2064ab74cc756e62829726e56e9260a8369b49 Mon Sep 17 00:00:00 2001 From: mikiubo Date: Sat, 4 Jan 2025 02:27:04 +0100 Subject: [PATCH] LibWeb: Trigger click on Return KeyDown event --- Libraries/LibWeb/Page/EventHandler.cpp | 8 ++++ .../focus-tabindex-event.txt | 0 .../focus-tabindex-event.html | 38 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-event.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-event.html diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 0c789c46465d..a89c1d5b9261 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -1090,6 +1090,14 @@ EventResult EventHandler::handle_keydown(UIEvents::KeyCode key, u32 modifiers, u } } } + + if (key == UIEvents::KeyCode::Key_Return) { + if (auto* element = m_navigable->active_document()->focused_element(); is(element)) { + auto& html_element = static_cast(*element); + html_element.click(); + return EventResult::Handled; + } + } // FIXME: Implement scroll by line and by page instead of approximating the behavior of other browsers. auto arrow_key_scroll_distance = 100; diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-event.txt b/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-event.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/Tests/LibWeb/Text/input/wpt-import/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-event.html b/Tests/LibWeb/Text/input/wpt-import/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-event.html new file mode 100644 index 000000000000..55ded8fa95bf --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/editing/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-event.html @@ -0,0 +1,38 @@ + + +HTML Test: tabindex - focus, click + + + + + + + + +

Test steps

+

Focus on the button below by "Tab" key, then press "Enter" key

+ +

+ +