From 8812b35c5e0c2c8807bc5101a2ace6e3645ce33c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 8 Jul 2019 07:33:58 +0200 Subject: [PATCH] LibHTML: Reorganize layout tree build so that parents add their children. This will allow us to insert anonymous blocks with ease. --- Libraries/LibHTML/Frame.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Libraries/LibHTML/Frame.cpp b/Libraries/LibHTML/Frame.cpp index 4e88b03a75..6fcc0ba2bb 100644 --- a/Libraries/LibHTML/Frame.cpp +++ b/Libraries/LibHTML/Frame.cpp @@ -69,21 +69,23 @@ RefPtr Frame::generate_layout_tree(const StyledNode& styled_root) } }; - Function(const StyledNode&, LayoutNode*)> resolve_layout = [&](const StyledNode& styled_node, LayoutNode* parent_layout_node) -> RefPtr { + Function(const StyledNode&, LayoutNode*)> build_layout_tree; + build_layout_tree = [&](const StyledNode& styled_node, LayoutNode* parent_layout_node) -> RefPtr { auto layout_node = create_layout_node(styled_node); if (!layout_node) return nullptr; - if (parent_layout_node) - parent_layout_node->append_child(*layout_node); if (styled_node.has_children()) { - for (auto* child = styled_node.first_child(); child; child = child->next_sibling()) { - resolve_layout(*child, layout_node.ptr()); + for (auto* styled_child = styled_node.first_child(); styled_child; styled_child = styled_child->next_sibling()) { + auto layout_child = build_layout_tree(*styled_child, layout_node.ptr()); + if (!layout_child) + continue; + layout_node->append_child(*layout_child); } } return layout_node; }; - return resolve_layout(styled_root, nullptr); + return build_layout_tree(styled_root, nullptr); } void Frame::layout()