LibWeb: Move event handling & cursor from BrowsingContext to Navigable

This was a long standing FIXME since the introduction of navigables.
This commit is contained in:
Andreas Kling 2024-04-26 16:59:04 +02:00
commit 0ebfc0a4c4
Notes: sideshowbarker 2024-07-17 01:46:43 +09:00
26 changed files with 364 additions and 360 deletions

View file

@ -1138,4 +1138,33 @@ void TraversableNavigable::set_system_visibility_state(VisibilityState visibilit
}
}
// https://html.spec.whatwg.org/multipage/interaction.html#currently-focused-area-of-a-top-level-traversable
JS::GCPtr<DOM::Node> TraversableNavigable::currently_focused_area()
{
// 1. If traversable does not have system focus, then return null.
if (!is_focused())
return nullptr;
// 2. Let candidate be traversable's active document.
auto candidate = active_document();
// 3. While candidate's focused area is a navigable container with a non-null content navigable:
// set candidate to the active document of that navigable container's content navigable.
while (candidate->focused_element()
&& is<HTML::NavigableContainer>(candidate->focused_element())
&& static_cast<HTML::NavigableContainer&>(*candidate->focused_element()).content_navigable()) {
candidate = static_cast<HTML::NavigableContainer&>(*candidate->focused_element()).content_navigable()->active_document();
}
// 4. If candidate's focused area is non-null, set candidate to candidate's focused area.
if (candidate->focused_element()) {
// NOTE: We return right away here instead of assigning to candidate,
// since that would require compromising type safety.
return candidate->focused_element();
}
// 5. Return candidate.
return candidate;
}
}