mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 12:25:06 +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:
parent
11256de366
commit
615a4d4f71
18 changed files with 209 additions and 41 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/Layout/BlockBox.h>
|
||||
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
||||
#include <LibWeb/Layout/InlineFormattingContext.h>
|
||||
#include <LibWeb/Layout/InlineNode.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
|
@ -107,10 +108,14 @@ HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type
|
|||
return { absolute_rect().contains(position.x(), position.y()) ? this : nullptr };
|
||||
}
|
||||
|
||||
void BlockBox::split_into_lines(BlockBox& container, LayoutMode layout_mode)
|
||||
void BlockBox::split_into_lines(InlineFormattingContext& context, LayoutMode layout_mode)
|
||||
{
|
||||
auto& container = context.context_box();
|
||||
auto* line_box = &container.ensure_last_line_box();
|
||||
if (layout_mode != LayoutMode::OnlyRequiredLineBreaks && line_box->width() > 0 && line_box->width() + width() > container.width()) {
|
||||
|
||||
float available_width = context.available_width_at_line(container.line_boxes().size());
|
||||
|
||||
if (layout_mode != LayoutMode::OnlyRequiredLineBreaks && line_box->width() > 0 && line_box->width() + width() > available_width) {
|
||||
line_box = &container.add_line_box();
|
||||
}
|
||||
line_box->add_fragment(*this, 0, 0, width(), height());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue