From 3c0c300039307208be3a220c77075bfd01f1dd79 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 3 Dec 2023 08:42:32 -0500 Subject: [PATCH] LibWeb: Check all entries in the focus chain when unfocusing a node The way this step was currently implemented, we would bail the unfocus steps if the node isn't the first entry in the chain. --- Userland/Libraries/LibWeb/HTML/Focus.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Focus.cpp b/Userland/Libraries/LibWeb/HTML/Focus.cpp index 6ceff5584b..648dc4373a 100644 --- a/Userland/Libraries/LibWeb/HTML/Focus.cpp +++ b/Userland/Libraries/LibWeb/HTML/Focus.cpp @@ -212,6 +212,7 @@ void run_focusing_steps(DOM::Node* new_focus_target, DOM::Node* fallback_target, run_focus_update_steps(old_chain, new_chain, new_focus_target); } +// https://html.spec.whatwg.org/multipage/interaction.html#unfocusing-steps void run_unfocusing_steps(DOM::Node* old_focus_target) { // NOTE: The unfocusing steps do not always result in the focus changing, even when applied to the currently focused @@ -254,11 +255,9 @@ void run_unfocusing_steps(DOM::Node* old_focus_target) auto old_chain = focus_chain(top_level_browsing_context->currently_focused_area()); // 5. If old focus target is not one of the entries in old chain, then return. - for (auto& node : old_chain) { - if (old_focus_target != node) { - return; - } - } + auto it = old_chain.find_if([&](auto const& node) { return old_focus_target == node; }); + if (it == old_chain.end()) + return; // 6. If old focus target is not a focusable area, then return. if (!old_focus_target->is_focusable())