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

@ -26,6 +26,7 @@
#pragma once
#include <AK/Vector.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Layout/FormattingContext.h>
@ -40,22 +41,32 @@ public:
bool is_initial() const;
const Vector<Box*>& left_floating_boxes() const { return m_left_floating_boxes; }
const Vector<Box*>& right_floating_boxes() const { return m_right_floating_boxes; }
protected:
void compute_width(Box&);
void compute_height(Box&);
private:
virtual bool is_block_formatting_context() const final { return true; }
void compute_width_for_absolutely_positioned_block(Box&);
void layout_initial_containing_block(LayoutMode);
void layout_block_level_children(LayoutMode);
void layout_inline_children(LayoutMode);
void layout_absolutely_positioned_descendants();
void layout_floating_descendants();
void place_block_level_replaced_element_in_normal_flow(Box&);
void place_block_level_non_replaced_element_in_normal_flow(Box&);
void layout_absolutely_positioned_descendant(Box&);
void layout_floating_descendant(Box&);
Vector<Box*> m_left_floating_boxes;
Vector<Box*> m_right_floating_boxes;
};
}