mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibWeb: Add Frame::ViewportClient and use it for Layout::ImageBox
Image boxes want to know whether they are inside the visible viewport. This is used to pause/resume animations, and to update the purgeable memory volatility state. Previously we would traverse the entire layout tree on every resize, calling a helper on each ImageBox. Make those boxes register with the frame they are interested in instead, saving us all that traversal. This also makes it easier for other parts of the code to learn about viewport changes in the future. :^)
This commit is contained in:
parent
1c6f278677
commit
9b0ca75f84
6 changed files with 39 additions and 22 deletions
|
@ -110,11 +110,11 @@ void Frame::set_size(const Gfx::IntSize& size)
|
|||
if (m_size == size)
|
||||
return;
|
||||
m_size = size;
|
||||
if (m_document) {
|
||||
if (m_document)
|
||||
m_document->update_layout();
|
||||
if (m_document->layout_node())
|
||||
m_document->layout_node()->did_set_viewport_rect({}, viewport_rect());
|
||||
}
|
||||
|
||||
for (auto* client : m_viewport_clients)
|
||||
client->frame_did_set_viewport_rect(viewport_rect());
|
||||
}
|
||||
|
||||
void Frame::set_viewport_scroll_offset(const Gfx::IntPoint& offset)
|
||||
|
@ -123,8 +123,8 @@ void Frame::set_viewport_scroll_offset(const Gfx::IntPoint& offset)
|
|||
return;
|
||||
m_viewport_scroll_offset = offset;
|
||||
|
||||
if (m_document && m_document->layout_node())
|
||||
m_document->layout_node()->did_set_viewport_rect({}, viewport_rect());
|
||||
for (auto* client : m_viewport_clients)
|
||||
client->frame_did_set_viewport_rect(viewport_rect());
|
||||
}
|
||||
|
||||
void Frame::set_needs_display(const Gfx::IntRect& rect)
|
||||
|
@ -274,4 +274,16 @@ String Frame::selected_text() const
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
void Frame::register_viewport_client(ViewportClient& client)
|
||||
{
|
||||
auto result = m_viewport_clients.set(&client);
|
||||
ASSERT(result == AK::HashSetResult::InsertedNewEntry);
|
||||
}
|
||||
|
||||
void Frame::unregister_viewport_client(ViewportClient& client)
|
||||
{
|
||||
bool was_removed = m_viewport_clients.remove(&client);
|
||||
ASSERT(was_removed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue