mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:48:12 +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/HTML/HTMLHtmlElement.h>
|
||||
#include <LibWeb/Layout/BlockBox.h>
|
||||
#include <LibWeb/Layout/FormattingContext.h>
|
||||
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
|
@ -65,6 +66,13 @@ const BlockBox* Node::containing_block() const
|
|||
return downcast<BlockBox>(ancestor);
|
||||
};
|
||||
|
||||
auto nearest_block_ancestor_that_creates_a_block_formatting_context = [this] {
|
||||
auto* ancestor = parent();
|
||||
while (ancestor && (!is<Box>(*ancestor) || !FormattingContext::creates_block_formatting_context(downcast<Box>(*ancestor))))
|
||||
ancestor = ancestor->parent();
|
||||
return downcast<BlockBox>(ancestor);
|
||||
};
|
||||
|
||||
if (is_text())
|
||||
return nearest_block_ancestor();
|
||||
|
||||
|
@ -82,6 +90,9 @@ const BlockBox* Node::containing_block() const
|
|||
if (position == CSS::Position::Fixed)
|
||||
return &root();
|
||||
|
||||
if (is_floating())
|
||||
return nearest_block_ancestor_that_creates_a_block_formatting_context();
|
||||
|
||||
return nearest_block_ancestor();
|
||||
}
|
||||
|
||||
|
@ -140,10 +151,10 @@ InitialContainingBlockBox& Node::root()
|
|||
return *document().layout_node();
|
||||
}
|
||||
|
||||
void Node::split_into_lines(BlockBox& container, LayoutMode layout_mode)
|
||||
void Node::split_into_lines(InlineFormattingContext& context, LayoutMode layout_mode)
|
||||
{
|
||||
for_each_child([&](auto& child) {
|
||||
child.split_into_lines(container, layout_mode);
|
||||
child.split_into_lines(context, layout_mode);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue