1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibWeb: Use actual line height to calculate float y in IFC

Before, we were using the line height from NodeWithStyle::line_height()
 to calculate the y offset for floats inside the IFC. However, this
value doesn't always correspond to the actual height of a line box. For
instance, adding a fragment for an inline-block might change the height
of the line box. With this change, we recalculate the height of the
line box after adding a new fragment and use this recalculated height
value to determine the y position for floats.

Fixes https://github.com/SerenityOS/serenity/issues/20982
This commit is contained in:
Aliaksandr Kalenik 2023-09-09 15:39:22 +02:00 committed by Andreas Kling
parent 6ab11e5f44
commit df2bc8187c
4 changed files with 50 additions and 3 deletions

View file

@ -111,11 +111,11 @@ CSSPixels LineBuilder::y_for_float_to_be_inserted_here(Box const& box)
CSSPixels candidate_y = m_current_y;
CSSPixels current_line_width = ensure_last_line_box().width();
auto const& current_line = ensure_last_line_box();
// If there's already inline content on the current line, check if the new float can fit
// alongside the content. If not, place it on the next line.
if (current_line_width > 0 && (current_line_width + width) > m_available_width_for_current_line)
candidate_y += m_context.containing_block().line_height();
if (current_line.width() > 0 && (current_line.width() + width) > m_available_width_for_current_line)
candidate_y += current_line.height();
// Then, look for the next Y position where we can fit the new float.
// FIXME: This is super dumb, we move 1px downwards per iteration and stop