1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibWeb: Reorganize layout system in terms of formatting contexts

This is a first (huge) step towards modernizing the layout architecture
and bringing it closer to spec language.

Layout is now performed by a stack of formatting contexts, operating on
the box tree (or layout tree, if you will.)

There are currently three types of formatting context:

- BlockFormattingContext (BFC)
- InlineFormattingContext (IFC)
- TableFormattingContext (TFC)

Document::layout() creates the initial BlockFormattingContext (BFC)
which lays out the initial containing block (ICB), and then we recurse
through the tree, creating BFC, IFC or TFC as appropriate and handing
over control at the context boundaries.

The majority of this patch is just refactoring the old logic spread out
in LayoutBlock and LayoutTableRowGroup, and turning into these context
classes instead. A lot more cleanup will be needed.

There are many architectural wins here, the main one being that layout
is no longer performed by boxes themselves, which gives us much greater
flexibility in the outer/inner layout of a given box.
This commit is contained in:
Andreas Kling 2020-11-22 13:38:18 +01:00
parent 00aac65af5
commit e1a24edfa9
46 changed files with 1360 additions and 882 deletions

View file

@ -38,17 +38,10 @@ public:
virtual const char* class_name() const override { return "LayoutBlock"; }
virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void paint(PaintContext&, PaintPhase) override;
virtual LayoutNode& inline_wrapper() override;
Vector<LineBox>& line_boxes() { return m_line_boxes; }
const Vector<LineBox>& line_boxes() const { return m_line_boxes; }
LineBox& ensure_last_line_box();
LineBox& add_line_box();
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
LayoutBlock* previous_sibling() { return downcast<LayoutBlock>(LayoutNode::previous_sibling()); }
@ -63,36 +56,10 @@ public:
virtual void split_into_lines(LayoutBlock& container, LayoutMode) override;
void layout_inside(LayoutMode);
protected:
void compute_width();
void compute_height();
void layout_absolutely_positioned_descendants();
virtual float width_of_logical_containing_block() const;
private:
virtual bool is_block() const override { return true; }
struct ShrinkToFitResult {
float preferred_width { 0 };
float preferred_minimum_width { 0 };
};
ShrinkToFitResult calculate_shrink_to_fit_width();
void compute_width_for_absolutely_positioned_block();
void place_block_level_non_replaced_element_in_normal_flow(LayoutBlock&);
void place_block_level_replaced_element_in_normal_flow(LayoutReplaced&);
void layout_absolutely_positioned_descendant(LayoutBox&);
NonnullRefPtr<CSS::StyleProperties> style_for_anonymous_block() const;
void layout_inline_children(LayoutMode);
void layout_contained_boxes(LayoutMode);
Vector<LineBox> m_line_boxes;
};
template<typename Callback>