From 44cf4189754e7453f6c6604ed2d865535db12ac3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 23 Jan 2023 15:03:45 +0100 Subject: [PATCH] LibWeb: Make flex containers be Layout::Box Flex containers were incorrectly represented as BlockContainer before, which would make some CSS layout algorithms do the wrong thing. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 7 +++++-- Userland/Libraries/LibWeb/Layout/Node.cpp | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 413a3faf5b..386d5af754 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -315,12 +315,15 @@ JS::GCPtr Element::create_layout_node_for_display_type(DOM::Docume if (display.is_flow_inside()) return document.heap().allocate_without_realm(document, element, move(style)); if (display.is_flex_inside()) - return document.heap().allocate_without_realm(document, element, move(style)); + return document.heap().allocate_without_realm(document, element, move(style)); dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Support display: {}", display.to_deprecated_string()); return document.heap().allocate_without_realm(document, element, move(style)); } - if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_flex_inside() || display.is_grid_inside()) + if (display.is_flex_inside()) + return document.heap().allocate_without_realm(document, element, move(style)); + + if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_grid_inside()) return document.heap().allocate_without_realm(document, element, move(style)); TODO(); diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index fba5dd4ca4..7dd7f8327f 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -65,8 +65,10 @@ bool Node::can_contain_boxes_with_position_absolute() const static Box const* nearest_ancestor_capable_of_forming_a_containing_block(Node const& node) { for (auto const* ancestor = node.parent(); ancestor; ancestor = ancestor->parent()) { - if (ancestor->is_block_container()) + if (ancestor->is_block_container() + || ancestor->display().is_flex_inside()) { return verify_cast(ancestor); + } } return nullptr; }