1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 19:45:08 +00:00

LibHTML: Move layout tree building to a LayoutTreeBuilder class

Building a whole layout tree shouldn't be a concern of Node, so this
patch moves it to a separate class.
This commit is contained in:
Andreas Kling 2019-10-15 12:22:41 +02:00
parent d14b60533f
commit f7cd5662ef
6 changed files with 70 additions and 39 deletions

View file

@ -19,41 +19,6 @@ Node::~Node()
{
}
RefPtr<LayoutNode> Node::create_layout_tree(const StyleResolver& resolver, const StyleProperties* parent_style) const
{
auto layout_node = create_layout_node(resolver, parent_style);
if (!layout_node)
return nullptr;
if (!has_children())
return layout_node;
Vector<RefPtr<LayoutNode>> layout_children;
bool have_inline_children = false;
bool have_block_children = false;
static_cast<const ParentNode&>(*this).for_each_child([&](const Node& child) {
auto layout_child = child.create_layout_tree(resolver, &layout_node->style());
if (!layout_child)
return;
if (!layout_child->is_block())
have_inline_children = true;
if (layout_child->is_block())
have_block_children = true;
layout_children.append(move(layout_child));
});
for (auto layout_child : layout_children)
if (have_block_children && have_inline_children && !layout_child->is_block()) {
if (layout_child->is_text() && static_cast<const LayoutText&>(*layout_child).text_for_style(*parent_style) == " ")
continue;
layout_node->inline_wrapper().append_child(*layout_child);
} else {
layout_node->append_child(*layout_child);
}
return layout_node;
}
const HTMLAnchorElement* Node::enclosing_link_element() const
{
return first_ancestor_of_type<HTMLAnchorElement>();