LibWeb: Improve step 3 of "focus chain" from the HTML spec

This function was unnecessarily nested, which created a scenario where
we could get stuck in an infinite loop without advancing the
current_object pointer up the browsing context container chain.
This commit is contained in:
Andreas Kling 2022-02-07 01:43:01 +01:00
parent 086eb1ad7b
commit 1ea2467a7a
Notes: sideshowbarker 2024-07-17 19:41:18 +09:00

View file

@ -302,12 +302,12 @@ static Vector<DOM::Node&> focus_chain(DOM::Node* subject)
if (!is<DOM::Document>(*current_object)) {
// 3. If currentObject is a focusable area, then set currentObject to currentObject's DOM anchor's node document.
current_object = &current_object->document();
} else if (is<DOM::Document>(*current_object)) {
} else if (is<DOM::Document>(*current_object)
&& static_cast<DOM::Document&>(*current_object).browsing_context()
&& !static_cast<DOM::Document&>(*current_object).browsing_context()->is_top_level()) {
// Otherwise, if currentObject is a Document whose browsing context is a child browsing context,
// then set currentObject to currentObject's browsing context's container.
auto& document = static_cast<DOM::Document&>(*current_object);
if (document.browsing_context() && !document.browsing_context()->is_top_level())
current_object = document.browsing_context()->container();
current_object = static_cast<DOM::Document&>(*current_object).browsing_context()->container();
} else {
break;
}