1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibWeb: Start making our layout system "transactional"

This patch adds a map of Layout::Node to FormattingState::NodeState.
Instead of updating layout nodes incrementally as layout progresses
through the formatting contexts, all updates are now written to the
corresponding NodeState instead.

At the end of layout, FormattingState::commit() is called, which
transfers all the values from the NodeState objects to the Node.

This will soon allow us to perform completely non-destructive layouts
which don't affect the tree.

Note that there are many imperfections here, and still many places
where we assign to the NodeState, but later read directly from the Node
instead. I'm just committing at this stage to make subsequent diffs
easier to understand.
This commit is contained in:
Andreas Kling 2022-02-20 15:51:24 +01:00
parent 561612f219
commit c9700e100e
27 changed files with 754 additions and 571 deletions

View file

@ -16,51 +16,47 @@ namespace Web::Layout {
// https://www.w3.org/TR/css-display/#block-formatting-context
class BlockFormattingContext : public FormattingContext {
public:
explicit BlockFormattingContext(FormattingState&, BlockContainer&, FormattingContext* parent);
explicit BlockFormattingContext(FormattingState&, BlockContainer const&, FormattingContext* parent);
~BlockFormattingContext();
virtual void run(Box&, LayoutMode) override;
virtual void run(Box const&, LayoutMode) override;
bool is_initial() const;
auto const& left_side_floats() const { return m_left_floats; }
auto const& right_side_floats() const { return m_right_floats; }
static float compute_theoretical_height(Box const&);
void compute_width(Box&);
static float compute_theoretical_height(FormattingState const&, Box const&);
void compute_width(Box const&);
// https://www.w3.org/TR/css-display/#block-formatting-context-root
BlockContainer& root() { return static_cast<BlockContainer&>(context_box()); }
BlockContainer const& root() const { return static_cast<BlockContainer const&>(context_box()); }
virtual void parent_context_did_dimension_child_root_box() override;
static void compute_height(Box&);
static void compute_height(Box const&, FormattingState&);
void add_absolutely_positioned_box(Box& box) { m_absolutely_positioned_boxes.append(box); }
protected:
void compute_position(Box&);
void add_absolutely_positioned_box(Box const& box) { m_absolutely_positioned_boxes.append(box); }
private:
virtual bool is_block_formatting_context() const final { return true; }
void compute_width_for_floating_box(Box&);
void compute_width_for_floating_box(Box const&);
void compute_width_for_block_level_replaced_element_in_normal_flow(ReplacedBox&);
void compute_width_for_block_level_replaced_element_in_normal_flow(ReplacedBox const&);
void layout_initial_containing_block(LayoutMode);
void layout_block_level_children(BlockContainer&, LayoutMode);
void layout_inline_children(BlockContainer&, LayoutMode);
void layout_block_level_children(BlockContainer const&, LayoutMode);
void layout_inline_children(BlockContainer const&, LayoutMode);
void compute_vertical_box_model_metrics(Box& child_box, BlockContainer const& containing_block);
void place_block_level_element_in_normal_flow_horizontally(Box& child_box, BlockContainer const&);
void place_block_level_element_in_normal_flow_vertically(Box& child_box, BlockContainer const&);
void compute_vertical_box_model_metrics(Box const& box, BlockContainer const& containing_block);
void place_block_level_element_in_normal_flow_horizontally(Box const& child_box, BlockContainer const&);
void place_block_level_element_in_normal_flow_vertically(Box const& child_box, BlockContainer const&);
void layout_floating_child(Box& child, BlockContainer const& containing_block);
void layout_floating_child(Box const& child, BlockContainer const& containing_block);
void apply_transformations_to_children(Box&);
void apply_transformations_to_children(Box const&);
enum class FloatSide {
Left,
@ -68,14 +64,14 @@ private:
};
struct FloatSideData {
Vector<Box&> boxes;
Vector<Box const&> boxes;
float y_offset { 0 };
};
FloatSideData m_left_floats;
FloatSideData m_right_floats;
Vector<Box&> m_absolutely_positioned_boxes;
Vector<Box const&> m_absolutely_positioned_boxes;
bool m_was_notified_after_parent_dimensioned_my_root_box { false };
};