diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 891db783b3..15b10fedf4 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -705,6 +705,8 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer } else if (box.computed_values().float_() == CSS::Float::Right) { float_box(FloatSide::Right, m_right_floats); } + + m_state.get_mutable(root()).add_floating_descendant(box); } void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_item_box) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 8da09790a7..2b44735ed6 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -341,18 +341,13 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(L // In addition, if the element has any floating descendants // whose bottom margin edge is below the element's bottom content edge, // then the height is increased to include those edges. - root.for_each_child_of_type([&](Layout::Box& child_box) { - if (!child_box.is_floating()) - return IterationDecision::Continue; + for (auto* floating_box : state.get(root).floating_descendants()) { + auto const& floating_box_state = state.get(*floating_box); + float floating_box_bottom = floating_box_state.offset.y() + floating_box_state.content_height() + floating_box_state.margin_box_bottom(); - auto const& child_box_state = state.get(child_box); - float child_box_bottom = child_box_state.offset.y() + child_box_state.content_height() + child_box_state.margin_box_bottom(); - - if (!bottom.has_value() || child_box_bottom > bottom.value()) - bottom = child_box_bottom; - - return IterationDecision::Continue; - }); + if (!bottom.has_value() || floating_box_bottom > bottom.value()) + bottom = floating_box_bottom; + } return max(0.0f, bottom.value_or(0) - top.value_or(0)); } diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.h b/Userland/Libraries/LibWeb/Layout/LayoutState.h index 35f9043908..f4c7b01ba7 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.h +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.h @@ -109,6 +109,9 @@ struct LayoutState { Optional containing_line_box_fragment; + void add_floating_descendant(Box const& box) { m_floating_descendants.set(&box); } + auto const& floating_descendants() const { return m_floating_descendants; } + private: Layout::NodeWithStyleAndBoxModelMetrics* m_node { nullptr }; @@ -117,6 +120,8 @@ struct LayoutState { bool m_has_definite_width { false }; bool m_has_definite_height { false }; + + HashTable m_floating_descendants; }; void commit();