1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

LibWeb: First slightly naive implementation of CSS floats :^)

Boxes can now be floated left or right, which makes text within the
same block formatting context flow around them.

We were creating way too many block formatting contexts. As it turns
out, we don't need one for every new block, but rather there's a set
of rules that determines whether a given block creates a new block
formatting context.

Each BFC keeps track of the floating boxes within it, and IFC's can
then query it to find the available space for line boxes.

There's a huge hack in here where we assume all lines are the exact
line-height. Making this work with vertically non-uniform lines will
require some architectural changes.
This commit is contained in:
Andreas Kling 2020-12-05 20:10:39 +01:00
parent 11256de366
commit 615a4d4f71
18 changed files with 209 additions and 41 deletions

View file

@ -25,6 +25,7 @@
*/
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/BlockBox.h>
#include <LibWeb/Layout/ReplacedBox.h>
@ -117,17 +118,19 @@ float ReplacedBox::calculate_height() const
return used_height;
}
void ReplacedBox::split_into_lines(Layout::BlockBox& container, LayoutMode)
void ReplacedBox::split_into_lines(InlineFormattingContext& context, LayoutMode)
{
auto& containing_block = context.context_box();
// FIXME: This feels out of place. It would be nice if someone at a higher level
// made sure we had usable geometry by the time we start splitting.
prepare_for_replaced_layout();
auto width = calculate_width();
auto height = calculate_height();
auto* line_box = &container.ensure_last_line_box();
if (line_box->width() > 0 && line_box->width() + width > container.width())
line_box = &container.add_line_box();
auto* line_box = &containing_block.ensure_last_line_box();
if (line_box->width() > 0 && line_box->width() + width > context.available_width_at_line(containing_block.line_boxes().size()))
line_box = &containing_block.add_line_box();
line_box->add_fragment(*this, 0, 0, width, height);
}