mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
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. :^)
This commit is contained in:
parent
af757a1659
commit
6b4281c3aa
Notes:
sideshowbarker
2024-07-19 01:02:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6b4281c3aa4
1 changed files with 17 additions and 20 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue