diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-06 16:51:19 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-06 20:05:04 +0100 |
commit | b638e74b6898359886a69c7004930a3036282c47 (patch) | |
tree | 591ee88280d5818c4674daa974ffad54cf544ac2 /Libraries/LibWeb/Layout/BlockFormattingContext.cpp | |
parent | d582828040153397869531faf4c9458db27d93b8 (diff) | |
download | serenity-b638e74b6898359886a69c7004930a3036282c47.zip |
LibWeb: Move box floatation out of normal flow layout
Layout of floating children now places the child in the normal flow and
then floats it left or right afterwards.
Diffstat (limited to 'Libraries/LibWeb/Layout/BlockFormattingContext.cpp')
-rw-r--r-- | Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 4781488ee9..0369775c46 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -587,22 +587,6 @@ 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); } @@ -668,7 +652,31 @@ void BlockFormattingContext::layout_floating_child(Box& box) layout_inside(box, LayoutMode::Default); compute_height(box); + // First we place the box normally (to get the right y coordinate.) place_block_level_non_replaced_element_in_normal_flow(box); + + // Then we float it to the left or right. + + float x = box.effective_offset().x(); + float y = box.effective_offset().y(); + + 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 = context_box().width() - box.width(); + } + m_right_floating_boxes.append(&box); + } + + box.set_offset(x, y); } void BlockFormattingContext::layout_absolutely_positioned_descendant(Box& box) |