From 6b4281c3aa4bd421b00a83af17bc158d5fd2b883 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 6 Dec 2020 01:59:35 +0100 Subject: [PATCH] LibWeb: Do floating box placement together with other boxes I realized that we're supposed to float the boxes sideways, but not always to y=0, so that makes it logical to share the placement logic with other normal non-replaced blocks. This is still pretty buggy but we're getting closer. :^) --- .../LibWeb/Layout/BlockFormattingContext.cpp | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index a95e341cd8..53a22166a4 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -587,6 +587,22 @@ void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_fl } } + if (box.style().float_() == CSS::Float::Left) { + if (!m_left_floating_boxes.is_empty()) { + auto& previous_floating_box = *m_left_floating_boxes.last(); + x = previous_floating_box.effective_offset().x() + previous_floating_box.width(); + } + m_left_floating_boxes.append(&box); + } else if (box.style().float_() == CSS::Float::Right) { + if (!m_right_floating_boxes.is_empty()) { + auto& previous_floating_box = *m_right_floating_boxes.last(); + x = previous_floating_box.effective_offset().x() - box.width(); + } else { + x = containing_block.width() - box.width(); + } + m_right_floating_boxes.append(&box); + } + box.set_offset(x, y); } @@ -648,31 +664,12 @@ void BlockFormattingContext::layout_floating_descendants() void BlockFormattingContext::layout_floating_descendant(Box& box) { ASSERT(box.is_floating()); - auto& containing_block = context_box(); compute_width(box); layout_inside(box, LayoutMode::Default); compute_height(box); - if (box.style().float_() == CSS::Float::Left) { - float x = 0; - if (!m_left_floating_boxes.is_empty()) { - auto& previous_floating_box = *m_left_floating_boxes.last(); - x = previous_floating_box.effective_offset().x() + previous_floating_box.width(); - } - box.set_offset(x, 0); - m_left_floating_boxes.append(&box); - } else if (box.style().float_() == CSS::Float::Right) { - float x = 0; - if (!m_right_floating_boxes.is_empty()) { - auto& previous_floating_box = *m_right_floating_boxes.last(); - x = previous_floating_box.effective_offset().x() - box.width(); - } else { - x = containing_block.width() - box.width(); - } - box.set_offset(x, 0); - m_right_floating_boxes.append(&box); - } + place_block_level_non_replaced_element_in_normal_flow(box); } void BlockFormattingContext::layout_absolutely_positioned_descendant(Box& box)