mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibHTML: Add function for invalidating the document layout
This allows any external actor to signal that the document layout may be stale. This can be used when loading resources, changing the size or placement of an element, adding/removing nodes, or really any time.
This commit is contained in:
parent
15a016d3e3
commit
ef8b754a46
Notes:
sideshowbarker
2024-07-19 11:47:38 +09:00
Author: https://github.com/deoxxa Commit: https://github.com/SerenityOS/serenity/commit/ef8b754a468 Pull-request: https://github.com/SerenityOS/serenity/pull/634
3 changed files with 15 additions and 0 deletions
|
@ -126,6 +126,12 @@ URL Document::complete_url(const String& string) const
|
|||
return url;
|
||||
}
|
||||
|
||||
void Document::invalidate_layout()
|
||||
{
|
||||
if (on_invalidate_layout)
|
||||
on_invalidate_layout();
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> Document::create_layout_node(const StyleResolver&, const StyleProperties*) const
|
||||
{
|
||||
return adopt(*new LayoutDocument(*this, StyleProperties::create()));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/String.h>
|
||||
|
@ -63,6 +64,9 @@ public:
|
|||
Color visited_link_color() const { return m_visited_link_color; }
|
||||
void set_visited_link_color(Color);
|
||||
|
||||
void invalidate_layout();
|
||||
Function<void()> on_invalidate_layout;
|
||||
|
||||
private:
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_properties) const override;
|
||||
|
||||
|
|
|
@ -31,7 +31,12 @@ void HtmlView::set_document(Document* document)
|
|||
{
|
||||
if (document == m_document)
|
||||
return;
|
||||
|
||||
if (m_document)
|
||||
m_document->on_invalidate_layout = nullptr;
|
||||
|
||||
m_document = document;
|
||||
m_document->on_invalidate_layout = [this]() { layout_and_sync_size(); };
|
||||
|
||||
main_frame().set_document(document);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue