LibWeb: Make BrowsingContext ask PageClient when it wants to be scrolled

BrowsingContext shouldn't be scrolling itself, instead it has to update
the layout (to ensure that we have current document metrics, and then
ask the PageClient nicely to scroll it.

This fixes an issue where BrowsingContext sometimes believed itself to
be scrolled, but OOPWV had a different idea.
This commit is contained in:
Andreas Kling 2022-04-06 15:32:38 +02:00
parent 06d97c892b
commit 0f6e1f7a32
Notes: sideshowbarker 2024-07-17 14:19:17 +09:00
3 changed files with 11 additions and 12 deletions

View file

@ -149,16 +149,6 @@ void BrowsingContext::set_size(Gfx::IntSize const& size)
HTML::main_thread_event_loop().schedule();
}
void BrowsingContext::set_viewport_scroll_offset(Gfx::IntPoint const& offset)
{
if (m_viewport_scroll_offset == offset)
return;
m_viewport_scroll_offset = offset;
for (auto* client : m_viewport_clients)
client->browsing_context_did_set_viewport_rect(viewport_rect());
}
void BrowsingContext::set_needs_display()
{
set_needs_display(viewport_rect());
@ -179,6 +169,15 @@ void BrowsingContext::set_needs_display(Gfx::IntRect const& rect)
container()->layout_node()->set_needs_display();
}
void BrowsingContext::scroll_to(Gfx::IntPoint const& position)
{
if (active_document())
active_document()->force_layout();
if (m_page)
m_page->client().page_did_request_scroll_to(position);
}
void BrowsingContext::scroll_to_anchor(String const& fragment)
{
if (!active_document())

View file

@ -54,7 +54,6 @@ public:
void set_needs_display(Gfx::IntRect const&);
Gfx::IntPoint const& viewport_scroll_offset() const { return m_viewport_scroll_offset; }
void set_viewport_scroll_offset(Gfx::IntPoint const&);
Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
void set_viewport_rect(Gfx::IntRect const&);
@ -64,6 +63,7 @@ public:
Web::EventHandler& event_handler() { return m_event_handler; }
Web::EventHandler const& event_handler() const { return m_event_handler; }
void scroll_to(Gfx::IntPoint const&);
void scroll_to_anchor(String const&);
BrowsingContext& top_level_browsing_context()

View file

@ -344,7 +344,7 @@ void FrameLoader::resource_did_load()
if (!url.fragment().is_empty())
browsing_context().scroll_to_anchor(url.fragment());
else
browsing_context().set_viewport_scroll_offset({ 0, 0 });
browsing_context().scroll_to({ 0, 0 });
if (auto* page = browsing_context().page())
page->client().page_did_finish_loading(url);