1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:45:07 +00:00

LibHTML: Move layout root from HtmlView to Document

The layout root is now kept alive via Document::m_layout_root.
This will allow us to do more layout-related things inside the inner
layer of LibHTML without reaching out to the HtmlView.

I'd like to keep HtmlView at a slightly higher level, to prevent it
from getting too complex.

This patch also fixes accidental disconnection of the layout tree from
the DOM after doing a layout tree rebuild. ~LayoutNode() now only
unsets the DOM node's layout_node() if it's itself.
This commit is contained in:
Andreas Kling 2019-10-13 12:34:25 +02:00
parent 48ef1d1bd1
commit 49ac0c2e24
6 changed files with 51 additions and 20 deletions

View file

@ -98,10 +98,12 @@ String Document::title() const
void Document::attach_to_frame(Badge<Frame>, Frame& frame)
{
m_frame = frame.make_weak_ptr();
layout();
}
void Document::detach_from_frame(Badge<Frame>, Frame&)
{
m_layout_root = nullptr;
m_frame = nullptr;
}
@ -149,8 +151,15 @@ URL Document::complete_url(const String& string) const
return url;
}
void Document::layout()
{
m_layout_root = create_layout_tree(style_resolver(), nullptr);
m_layout_root->layout();
}
void Document::invalidate_layout()
{
layout();
if (on_invalidate_layout)
on_invalidate_layout();
}
@ -174,3 +183,8 @@ void Document::set_visited_link_color(Color color)
{
m_visited_link_color = color;
}
const LayoutDocument* Document::layout_node() const
{
return static_cast<const LayoutDocument*>(Node::layout_node());
}