mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 01:42:17 +00:00
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:
parent
cf523137ad
commit
b11ba4cc90
Notes:
github-actions[bot]
2025-03-02 22:28:18 +00:00
Author: https://github.com/trflynn89
Commit: b11ba4cc90
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3760
5 changed files with 43 additions and 1 deletions
|
@ -3971,9 +3971,14 @@ void Document::destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. Set document's node navigable's active session history entry's document state's document to null.
|
// 9. Set document's node navigable's active session history entry's document state's document to null.
|
||||||
if (auto navigable = this->navigable())
|
if (auto navigable = this->navigable()) {
|
||||||
navigable->active_session_history_entry()->document_state()->set_document(nullptr);
|
navigable->active_session_history_entry()->document_state()->set_document(nullptr);
|
||||||
|
|
||||||
|
// AD-HOC: We set the page's focused navigable during mouse-down events. If that navigable is this document's
|
||||||
|
// navigable, we must be sure to reset the page's focused navigable.
|
||||||
|
page().navigable_document_destroyed({}, *navigable);
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: 10. Remove document from the owner set of each WorkerGlobalScope object whose set contains document.
|
// FIXME: 10. Remove document from the owner set of each WorkerGlobalScope object whose set contains document.
|
||||||
// FIXME: 11. For each workletGlobalScope in document's worklet global scopes, terminate workletGlobalScope.
|
// FIXME: 11. For each workletGlobalScope in document's worklet global scopes, terminate workletGlobalScope.
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,12 @@ void Page::set_focused_navigable(Badge<EventHandler>, HTML::Navigable& navigable
|
||||||
m_focused_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 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 });
|
(void)top_level_traversable()->navigate({ .url = url, .source_document = *top_level_traversable()->active_document(), .user_involvement = HTML::UserNavigationInvolvement::BrowserUI });
|
||||||
|
|
|
@ -75,6 +75,7 @@ public:
|
||||||
HTML::Navigable const& focused_navigable() const { return const_cast<Page*>(this)->focused_navigable(); }
|
HTML::Navigable const& focused_navigable() const { return const_cast<Page*>(this)->focused_navigable(); }
|
||||||
|
|
||||||
void set_focused_navigable(Badge<EventHandler>, HTML::Navigable&);
|
void set_focused_navigable(Badge<EventHandler>, HTML::Navigable&);
|
||||||
|
void navigable_document_destroyed(Badge<DOM::Document>, HTML::Navigable&);
|
||||||
|
|
||||||
void load(URL::URL const&);
|
void load(URL::URL const&);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
wfh :^)
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<iframe id="iframe"></iframe>
|
||||||
|
<input id="input" />
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
asyncTest(done => {
|
||||||
|
let iframe = document.getElementById("iframe");
|
||||||
|
let input = document.getElementById("input");
|
||||||
|
|
||||||
|
input.addEventListener("change", () => {
|
||||||
|
println(input.value);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
iframe.onload = () => {
|
||||||
|
internals.movePointerTo(20, 40);
|
||||||
|
internals.mouseDown(20, 40);
|
||||||
|
|
||||||
|
iframe.onload = () => {
|
||||||
|
internals.sendText(input, "wfh :^)");
|
||||||
|
internals.commitText();
|
||||||
|
};
|
||||||
|
|
||||||
|
iframe.src = "data:text/html,<p contenteditable>Text 2</p>";
|
||||||
|
};
|
||||||
|
|
||||||
|
iframe.src = "data:text/html,<p contenteditable>Text 1</p>";
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue