LibWeb: Clear the document's page's focused navigable upon destruction

We set the page's focused navigable upon mouse-down events from the UI.
However, we neglected to ever clear that focused navigable upon events
such as subsequent page navigations. This left the page with a stale
reference to a no-longer-active navigable. The effect was that any key
events from the UI would not be sent to the new page until either the
reference was collected by GC, or another mouse-down event occurred.

In the test added here, without this fix, the text sent to the input
element would not be received, and the change event would not fire.
This commit is contained in:
Timothy Flynn 2025-03-01 18:31:59 -05:00 committed by Tim Flynn
parent cf523137ad
commit b11ba4cc90
Notes: github-actions[bot] 2025-03-02 22:28:18 +00:00
5 changed files with 43 additions and 1 deletions

View file

@ -63,6 +63,12 @@ void Page::set_focused_navigable(Badge<EventHandler>, HTML::Navigable& navigable
m_focused_navigable = navigable;
}
void Page::navigable_document_destroyed(Badge<DOM::Document>, HTML::Navigable& navigable)
{
if (&navigable == m_focused_navigable.ptr())
m_focused_navigable.clear();
}
void Page::load(URL::URL const& url)
{
(void)top_level_traversable()->navigate({ .url = url, .source_document = *top_level_traversable()->active_document(), .user_involvement = HTML::UserNavigationInvolvement::BrowserUI });