LibWeb: Save layout mode inside formatting context object

FormattingContext::run() does not allow reentrancy, so it's safe to
save and access layout mode from FC object. This avoids need to drill it
through methods of a formatting context and makes it clear that this
value could never be changed after FC construction.
This commit is contained in:
Aliaksandr Kalenik 2024-09-11 01:03:02 +02:00 committed by Andreas Kling
commit 90b8bfc04c
Notes: github-actions[bot] 2024-09-11 07:30:59 +00:00
15 changed files with 124 additions and 124 deletions

View file

@ -14,8 +14,8 @@
namespace Web::Layout {
TableFormattingContext::TableFormattingContext(LayoutState& state, Box const& root, FormattingContext* parent)
: FormattingContext(Type::Table, state, root, parent)
TableFormattingContext::TableFormattingContext(LayoutState& state, LayoutMode layout_mode, Box const& root, FormattingContext* parent)
: FormattingContext(Type::Table, layout_mode, state, root, parent)
{
}
@ -31,7 +31,7 @@ static inline bool is_table_column(Box const& box)
return box.display().is_table_column();
}
CSSPixels TableFormattingContext::run_caption_layout(LayoutMode layout_mode, CSS::CaptionSide phase)
CSSPixels TableFormattingContext::run_caption_layout(CSS::CaptionSide phase)
{
CSSPixels caption_height = 0;
for (auto* child = table_box().first_child(); child; child = child->next_sibling()) {
@ -40,8 +40,8 @@ CSSPixels TableFormattingContext::run_caption_layout(LayoutMode layout_mode, CSS
}
// The caption boxes are principal block-level boxes that retain their own content, padding, margin, and border areas,
// and are rendered as normal block boxes inside the table wrapper box, as described in https://www.w3.org/TR/CSS22/tables.html#model
auto caption_context = make<BlockFormattingContext>(m_state, *verify_cast<BlockContainer>(child), this);
caption_context->run(layout_mode, *m_available_space);
auto caption_context = make<BlockFormattingContext>(m_state, m_layout_mode, *verify_cast<BlockContainer>(child), this);
caption_context->run(*m_available_space);
VERIFY(child->is_box());
auto const& child_box = static_cast<Box const&>(*child);
// FIXME: Since caption only has inline children, BlockFormattingContext doesn't resolve the vertical metrics.
@ -828,7 +828,7 @@ void TableFormattingContext::distribute_excess_width_to_columns_fixed_mode(CSSPi
distribute_excess_width_equally(excess_width, [](auto const& column) { return column.used_width == 0; });
}
void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
void TableFormattingContext::compute_table_height()
{
// First pass of row height calculation:
for (auto& row : m_rows) {
@ -878,7 +878,7 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
// - the horizontal/vertical border-spacing times the amount of spanned visible columns/rows minus one
// FIXME: Account for visibility.
cell_state.set_content_width(span_width - cell_state.border_box_left() - cell_state.border_box_right() + (cell.column_span - 1) * border_spacing_horizontal());
if (auto independent_formatting_context = layout_inside(cell.box, layout_mode, cell_state.available_inner_space_or_constraints_from(*m_available_space))) {
if (auto independent_formatting_context = layout_inside(cell.box, m_layout_mode, cell_state.available_inner_space_or_constraints_from(*m_available_space))) {
cell_state.set_content_height(independent_formatting_context->automatic_content_height());
independent_formatting_context->parent_context_did_dimension_child_root_box();
}
@ -961,7 +961,7 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
}
cell_state.set_content_width(span_width - cell_state.border_box_left() - cell_state.border_box_right() + (cell.column_span - 1) * border_spacing_horizontal());
if (auto independent_formatting_context = layout_inside(cell.box, layout_mode, cell_state.available_inner_space_or_constraints_from(*m_available_space))) {
if (auto independent_formatting_context = layout_inside(cell.box, m_layout_mode, cell_state.available_inner_space_or_constraints_from(*m_available_space))) {
independent_formatting_context->parent_context_did_dimension_child_root_box();
}
@ -1607,11 +1607,11 @@ void TableFormattingContext::run_until_width_calculation(AvailableSpace const& a
compute_table_width();
}
void TableFormattingContext::run(LayoutMode layout_mode, AvailableSpace const& available_space)
void TableFormattingContext::run(AvailableSpace const& available_space)
{
m_available_space = available_space;
auto total_captions_height = run_caption_layout(layout_mode, CSS::CaptionSide::Top);
auto total_captions_height = run_caption_layout(CSS::CaptionSide::Top);
run_until_width_calculation(available_space);
@ -1622,7 +1622,7 @@ void TableFormattingContext::run(LayoutMode layout_mode, AvailableSpace const& a
// Distribute the width of the table among columns.
distribute_width_to_columns();
compute_table_height(layout_mode);
compute_table_height();
distribute_height_to_rows();
@ -1631,7 +1631,7 @@ void TableFormattingContext::run(LayoutMode layout_mode, AvailableSpace const& a
m_state.get_mutable(table_box()).set_content_height(m_table_height);
total_captions_height += run_caption_layout(layout_mode, CSS::CaptionSide::Bottom);
total_captions_height += run_caption_layout(CSS::CaptionSide::Bottom);
// Table captions are positioned between the table margins and its borders (outside the grid box borders) as described in
// https://www.w3.org/TR/css-tables-3/#bounding-box-assignment