From 48240a6fc37333e273b8515939e383024105013b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 3 Dec 2023 09:12:12 -0500 Subject: [PATCH] LibWeb: Focus the document element when unfocusing an element Otherwise, the currently focused element remains focused. --- Tests/LibWeb/Text/expected/input-blur.txt | 2 ++ Tests/LibWeb/Text/input/input-blur.html | 18 ++++++++++++++++++ Userland/Libraries/LibWeb/HTML/Focus.cpp | 4 +++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/input-blur.txt create mode 100644 Tests/LibWeb/Text/input/input-blur.html diff --git a/Tests/LibWeb/Text/expected/input-blur.txt b/Tests/LibWeb/Text/expected/input-blur.txt new file mode 100644 index 0000000000..6b6d977d72 --- /dev/null +++ b/Tests/LibWeb/Text/expected/input-blur.txt @@ -0,0 +1,2 @@ + focus +blur diff --git a/Tests/LibWeb/Text/input/input-blur.html b/Tests/LibWeb/Text/input/input-blur.html new file mode 100644 index 0000000000..1fef4a10b9 --- /dev/null +++ b/Tests/LibWeb/Text/input/input-blur.html @@ -0,0 +1,18 @@ + + + diff --git a/Userland/Libraries/LibWeb/HTML/Focus.cpp b/Userland/Libraries/LibWeb/HTML/Focus.cpp index 648dc4373a..0b9b6e6aad 100644 --- a/Userland/Libraries/LibWeb/HTML/Focus.cpp +++ b/Userland/Libraries/LibWeb/HTML/Focus.cpp @@ -91,6 +91,8 @@ static void run_focus_update_steps(Vector> old_chain, Vect // FIXME: This isn't entirely right. if (is(*entry)) entry->document().set_focused_element(&static_cast(*entry)); + else if (is(*entry)) + entry->document().set_focused_element(static_cast(*entry).document_element()); JS::GCPtr focus_event_target; if (is(*entry)) { @@ -268,7 +270,7 @@ void run_unfocusing_steps(DOM::Node* old_focus_target) // 8. If topDocument's node navigable has system focus, then run the focusing steps for topDocument's viewport. if (top_document->navigable()->traversable_navigable()->system_visibility_state() == HTML::VisibilityState::Visible) { - // FIXME: run the focusing steps for topDocument's viewport (??) + run_focusing_steps(top_document); } else { // FIXME: Otherwise, apply any relevant platform-specific conventions for removing system focus from // topDocument's browsing context, and run the focus update steps with old chain, an empty list, and null