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
commit 615a4d4f71
Notes: sideshowbarker 2024-07-19 01:02:59 +09:00
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 };
};
}