From 6712bbc0eeeb8635a25e4442d0d20c906dbe537f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 Apr 2022 18:44:14 +0200 Subject: [PATCH] LibWeb: Tidy up Layout::TreeBuilder ancestor stack a little bit - Make it a vector of references since we never put null pointers on the ancestor stack. - Use Vector::in_reverse() to iterate backwards. --- Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp | 12 ++++++------ Userland/Libraries/LibWeb/Layout/TreeBuilder.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index 4c556f6bd58..c50b7ae9717 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -146,9 +146,9 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& return; auto insert_node_into_inline_or_block_ancestor = [this](auto& node, bool prepend = false) { - if (node->is_inline() && !(node->is_inline_block() && m_parent_stack.last()->computed_values().display().is_flex_inside())) { + if (node->is_inline() && !(node->is_inline_block() && m_ancestor_stack.last().computed_values().display().is_flex_inside())) { // Inlines can be inserted into the nearest ancestor. - auto& insertion_point = insertion_parent_for_inline_node(*m_parent_stack.last()); + auto& insertion_point = insertion_parent_for_inline_node(m_ancestor_stack.last()); if (prepend) insertion_point.prepend_child(*node); else @@ -157,9 +157,9 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& } else { // Non-inlines can't be inserted into an inline parent, so find the nearest non-inline ancestor. auto& nearest_non_inline_ancestor = [&]() -> Layout::NodeWithStyle& { - for (ssize_t i = m_parent_stack.size() - 1; i >= 0; --i) { - if (!m_parent_stack[i]->is_inline() || m_parent_stack[i]->is_inline_block()) - return *m_parent_stack[i]; + for (auto& ancestor : m_ancestor_stack.in_reverse()) { + if (!ancestor.is_inline() || ancestor.is_inline_block()) + return ancestor; } VERIFY_NOT_REACHED(); }(); @@ -178,7 +178,7 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context& if (!dom_node.parent_or_shadow_host()) { m_layout_root = layout_node; } else if (layout_node->is_svg_box()) { - m_parent_stack.last()->append_child(*layout_node); + m_ancestor_stack.last().append_child(*layout_node); } else { insert_node_into_inline_or_block_ancestor(layout_node); } diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.h b/Userland/Libraries/LibWeb/Layout/TreeBuilder.h index 7089e4b3792..45be0c08371 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.h +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.h @@ -26,8 +26,8 @@ private: void create_layout_tree(DOM::Node&, Context&); - void push_parent(Layout::NodeWithStyle& node) { m_parent_stack.append(&node); } - void pop_parent() { m_parent_stack.take_last(); } + void push_parent(Layout::NodeWithStyle& node) { m_ancestor_stack.append(node); } + void pop_parent() { m_ancestor_stack.take_last(); } template void for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback); @@ -41,7 +41,7 @@ private: void generate_missing_parents(NodeWithStyle& root); RefPtr m_layout_root; - Vector m_parent_stack; + Vector m_ancestor_stack; }; }