1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:38:13 +00:00

LibWeb: Rewrite CSS float implementation to use offset-from-edge

The previous implementation used relative X offsets for both left and
right-side floats. This made right-side floats super awkward, since we
could only determine their X position once the width of the BFC root was
known, and for BFC roots with automatic width, this was not even working
at all most of the time.

This patch changes the way we deal with floats so that BFC keeps track
of the offset-from-edge for each float. The offset is the distance from
the BFC root edge (left or right, depending on float direction) to the
"innermost" margin edge of the floating box.

Floating box are now laid out in two passes: while going through the
normal flow layout, we put floats in their *static* position (i.e the
position they would have occupied if they weren't floating) and then
update the Y position value to the final one.

The second pass occurs later on, when the BFC root has had its width
assigned by the parent context. Once we know the root width, we can
set the X position value of floating boxes. (Because the X position of
right-side floats is relative to the right edge of the BFC root.)
This commit is contained in:
Andreas Kling 2022-03-18 14:44:36 +01:00
parent 28642de6ed
commit 39b7fbfeb9
7 changed files with 245 additions and 83 deletions

View file

@ -27,7 +27,8 @@ public:
void dimension_box_on_line(Box const&, LayoutMode);
AvailableSpaceForLineInfo available_space_for_line(float y) const;
float leftmost_x_offset_at(float y) const;
float available_space_for_line(float y) const;
private:
void generate_line_boxes(LayoutMode);