1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:48: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

@ -34,16 +34,22 @@ class FormattingContext {
public:
virtual void run(LayoutMode) = 0;
Box& context_box() { return m_context_box; }
const Box& context_box() const { return m_context_box; }
Box& context_box() { return *m_context_box; }
const Box& context_box() const { return *m_context_box; }
FormattingContext* parent() { return m_parent; }
const FormattingContext* parent() const { return m_parent; }
virtual bool is_block_formatting_context() const { return false; }
static bool creates_block_formatting_context(const Box&);
protected:
FormattingContext(Box&, FormattingContext* parent = nullptr);
virtual ~FormattingContext();
void set_context_box(Box& box) { m_context_box = &box; }
void layout_inside(Box&, LayoutMode);
struct ShrinkToFitResult {
@ -54,7 +60,7 @@ protected:
ShrinkToFitResult calculate_shrink_to_fit_widths(Box&);
FormattingContext* m_parent { nullptr };
Box& m_context_box;
Box* m_context_box { nullptr };
};
}