dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / layout / table_formatting_context_2.lucb
#==============================================================================================
#
# table_formatting_context_2 - Layout::TableFormattingContext: the table width and its
# distribution to the columns
#
# DESCRIPTION:
# Port of LibWeb/Layout/TableFormattingContext.cpp (lines 469-905): the caption width
# minimum (CAPMIN), the used width of the table
# (https://drafts.csswg.org/css-tables-3/#computing-the-table-width), the width
# distribution algorithm with its sizing-guesses
# (https://www.w3.org/TR/css-tables-3/#width-distribution-algorithm), and the
# distribution of excess width to the columns in auto and fixed mode
# (https://www.w3.org/TR/css-tables-3/#distributing-width-to-columns).
#
# The column filters and base width getters (C++ lambdas without captures) are functions
# over a column.
#
# Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
# mark: The table width =========================================================================
## The `outer_size_for_inner_size` lambda of TableFormattingContext::compute_capmin: the caption's inner size with its
## horizontal margins, borders and padding.
func layout_table_formatting_context_caption_outer_size_for_inner_size(computed_values: const CssComputedValues*, margin_left: gfx.CssPixels, margin_right: gfx.CssPixels, padding_left: gfx.CssPixels, padding_right: gfx.CssPixels, inner_size: gfx.CssPixels) -> gfx.CssPixels:
return inner_size.add(margin_left).add(css_computed_values_border_left(computed_values).width).add(padding_left).add(padding_right).add(css_computed_values_border_right(computed_values).width).add(margin_right)
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:469 Web::Layout::TableFormattingContext::compute_capmin.
func layout_table_formatting_context_compute_capmin(this: LayoutTableFormattingContext*) -> gfx.CssPixels:
let base = this.layout_formatting_context()
# The caption width minimum (CAPMIN) is the largest of the table captions min-content contribution:
# https://drafts.csswg.org/css-tables-3/#computing-the-table-width
var capmin = layout_zero_px()
let width_of_table_wrapper_containing_block = layout_table_formatting_context_table_wrapper_containing_block_width(this)
for child in layout_node_children(layout_table_formatting_context_table_box(this).layout_node()):
let child_display = layout_node_display(child)
if not css_display_is_table_caption(&child_display):
continue
assert(layout_node_is_box(child))
let child_box = (LayoutBox*)child
let computed_values = layout_box_computed(child_box)
let margin = css_computed_values_margin(computed_values)
let computed_margin_left = css_length_box_left_const(&margin)
let resolved_margin_left = css_length_percentage_or_auto_resolved_or_auto(&computed_margin_left, child_box.layout_node(), width_of_table_wrapper_containing_block)
let margin_left = css_length_or_auto_to_px_or_zero(&resolved_margin_left, child_box.layout_node())
let computed_margin_right = css_length_box_right_const(&margin)
let resolved_margin_right = css_length_percentage_or_auto_resolved_or_auto(&computed_margin_right, child_box.layout_node(), width_of_table_wrapper_containing_block)
let margin_right = css_length_or_auto_to_px_or_zero(&resolved_margin_right, child_box.layout_node())
let padding = css_computed_values_padding(computed_values)
let padding_left = layout_table_formatting_context_to_px_or_zero(css_length_box_left_const(&padding), child_box, width_of_table_wrapper_containing_block)
let padding_right = layout_table_formatting_context_to_px_or_zero(css_length_box_right_const(&padding), child_box, width_of_table_wrapper_containing_block)
var caption_min_content_contribution = layout_table_formatting_context_caption_outer_size_for_inner_size(computed_values, margin_left, margin_right, padding_left, padding_right, layout_formatting_context_calculate_min_content_width(base, child_box))
let width = css_computed_values_width(computed_values)
if not css_size_is_auto(&width) and not css_size_contains_percentage(&width):
let preferred_inner_width = layout_formatting_context_calculate_inner_width(base, child_box, layout_available_size_make_definite(width_of_table_wrapper_containing_block), width)
caption_min_content_contribution = ak.max(caption_min_content_contribution, layout_table_formatting_context_caption_outer_size_for_inner_size(computed_values, margin_left, margin_right, padding_left, padding_right, preferred_inner_width))
capmin = ak.max(caption_min_content_contribution, capmin)
return capmin
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:508 Web::Layout::width_is_auto_or_indefinite_percentage.
func layout_width_is_auto_or_indefinite_percentage(width: CssSize, containing_block_state: const LayoutStateUsedValues*?) -> bool:
if css_size_is_auto(&width):
return true
if css_size_contains_percentage(&width):
let state = containing_block_state else return true
if not layout_state_used_values_has_definite_width(state):
return true
return false
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:519 Web::Layout::TableFormattingContext::compute_table_width.
func layout_table_formatting_context_compute_table_width(this: LayoutTableFormattingContext*):
let base = this.layout_formatting_context()
let state = base.m_state
let table_box = layout_table_formatting_context_table_box(this)
let available_space = layout_table_formatting_context_available_space(this)
# https://drafts.csswg.org/css-tables-3/#computing-the-table-width
let table_box_state = layout_state_get_mutable(state, table_box.layout_node_with_style())
let computed_values = layout_box_computed(table_box)
let width_of_table_containing_block = available_space.width
# Percentages on 'width' and 'height' on the table are relative to the table wrapper box's containing block,
# not the table wrapper box itself.
let width_of_table_wrapper_containing_block = layout_table_formatting_context_table_wrapper_containing_block_width(this)
# Compute undistributable space due to border spacing: https://www.w3.org/TR/css-tables-3/#computing-undistributable-space.
let undistributable_space = layout_table_formatting_context_mul_count(layout_table_formatting_context_border_spacing_horizontal(this), ak.vector_size(&this.m_columns) + 1)
let columns = ak.vector_span(&this.m_columns)
# The row/column-grid width minimum (GRIDMIN) width is the sum of the min-content width
# of all the columns plus cell spacing or borders.
var grid_min = layout_zero_px()
for column in &columns:
grid_min = grid_min.add(column.min_size)
grid_min = grid_min.add(undistributable_space)
# The row/column-grid width maximum (GRIDMAX) width is the sum of the max-content width
# of all the columns plus cell spacing or borders.
var grid_max = layout_zero_px()
for column in &columns:
grid_max = grid_max.add(column.max_size)
grid_max = grid_max.add(undistributable_space)
# The used min-width of a table is the greater of the resolved min-width, CAPMIN, and GRIDMIN.
var used_min_width = ak.max(grid_min, layout_table_formatting_context_compute_capmin(this))
let min_width = css_computed_values_min_width(computed_values)
if not css_size_is_auto(&min_width):
used_min_width = ak.max(used_min_width, css_size_to_px(&min_width, table_box.layout_node(), width_of_table_wrapper_containing_block))
let width = css_computed_values_width(computed_values)
let table_wrapper_containing_block = layout_node_containing_block(layout_table_formatting_context_table_wrapper(this).layout_node()) else trap("a table wrapper without a containing block")
var used_width = layout_zero_px()
if layout_available_size_is_min_content(&available_space.width):
used_width = grid_min
elif layout_available_size_is_max_content(&available_space.width):
used_width = grid_max
elif layout_width_is_auto_or_indefinite_percentage(width, layout_state_try_get_layout_node_with_style(state, table_wrapper_containing_block.layout_node_with_style())):
# If the table-root has 'width: auto', the used width is the greater of
# min(GRIDMAX, the table’s containing block width), the used min-width of the table.
if layout_available_size_is_definite(&width_of_table_containing_block):
used_width = ak.max(ak.min(grid_max, layout_available_size_to_px_or_zero(&width_of_table_containing_block)), used_min_width)
else:
used_width = ak.max(grid_max, used_min_width)
# https://www.w3.org/TR/CSS22/tables.html#auto-table-layout
# A percentage value for a column width is relative to the table width. If the table has 'width: auto',
# a percentage represents a constraint on the column's width, which a UA should try to satisfy.
for cell in &ak.vector_span(&this.m_cells):
let cell_width = css_computed_values_width(layout_box_computed(cell.box))
if css_size_is_percentage(&cell_width):
var adjusted_used_width = undistributable_space
let percentage = layout_table_formatting_context_percentage_value(&cell_width)
if percentage != 0.0:
adjusted_used_width = adjusted_used_width.add(gfx.css_pixels_nearest_value_for_f64(math.ceil(gfx.mul_css_pixels_f64(cell.outer_max_width, 100.0 / percentage))))
if layout_available_size_is_definite(&width_of_table_containing_block):
used_width = ak.min(ak.max(used_width, adjusted_used_width), layout_available_size_to_px_or_zero(&width_of_table_containing_block))
else:
used_width = ak.max(used_width, adjusted_used_width)
elif css_size_is_max_content(&width):
used_width = grid_max
else:
# If the table-root’s width property has a computed value (resolving to
# resolved-table-width) other than auto, the used width is the greater
# of resolved-table-width, and the used min-width of the table.
var resolved_table_width = css_size_to_px(&width, table_box.layout_node(), width_of_table_wrapper_containing_block)
# Since used_width is content width, we need to subtract the border and padding spacing from the specified width for a consistent comparison.
if css_computed_values_box_sizing(computed_values) == css_data.BoxSizing.border_box:
resolved_table_width = resolved_table_width.sub(layout_state_used_values_border_box_left(table_box_state).add(layout_state_used_values_border_box_right(table_box_state)))
used_width = ak.max(resolved_table_width, used_min_width)
if not layout_formatting_context_should_treat_max_width_as_none(base, table_box, available_space.width):
let max_width = css_computed_values_max_width(computed_values)
used_width = ak.min(used_width, css_size_to_px(&max_width, table_box.layout_node(), width_of_table_wrapper_containing_block))
layout_state_used_values_set_content_width(table_box_state, used_width)
let table_wrapper_box_state = layout_state_get_mutable(state, layout_table_formatting_context_table_wrapper(this).layout_node_with_style())
layout_state_used_values_set_content_width(table_wrapper_box_state, layout_state_used_values_border_box_width(table_box_state))
# mark: Sizing-guesses ==========================================================================
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:606 Web::Layout::TableFormattingContext::compute_columns_total_used_width.
func layout_table_formatting_context_compute_columns_total_used_width(this: LayoutTableFormattingContext*) -> gfx.CssPixels:
var total_used_width = layout_zero_px()
for column in ak.vector_span(&this.m_columns):
total_used_width = total_used_width.add(column.used_width)
return total_used_width
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:615 Web::Layout::compute_columns_total_candidate_width.
func layout_compute_columns_total_candidate_width(candidate_widths: const ak.Vector[gfx.CssPixels]*) -> gfx.CssPixels:
var total_candidate_width = layout_zero_px()
for width in ak.vector_span_const(candidate_widths):
total_candidate_width = total_candidate_width.add(width)
return total_candidate_width
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:624 Web::Layout::TableFormattingContext::commit_candidate_column_widths.
func layout_table_formatting_context_commit_candidate_column_widths(this: LayoutTableFormattingContext*, candidate_widths: const ak.Vector[gfx.CssPixels]*):
assert(ak.vector_size(candidate_widths) == ak.vector_size(&this.m_columns))
for i in 0..<ak.vector_size(&this.m_columns):
ak.vector_at(&this.m_columns, i).used_width = *ak.vector_at_const(candidate_widths, i)
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:632 Web::Layout::TableFormattingContext::assign_columns_width_linear_combination.
func layout_table_formatting_context_assign_columns_width_linear_combination(this: LayoutTableFormattingContext*, candidate_widths: const ak.Vector[gfx.CssPixels]*, available_width: gfx.CssPixels):
let columns_total_candidate_width = layout_compute_columns_total_candidate_width(candidate_widths)
let columns_total_used_width = layout_table_formatting_context_compute_columns_total_used_width(this)
if columns_total_candidate_width == columns_total_used_width:
return
let candidate_weight = gfx.div_css_pixels_f64(available_width.sub(columns_total_used_width), columns_total_candidate_width.sub(columns_total_used_width).to_double())
for i in 0..<ak.vector_size(&this.m_columns):
let column = ak.vector_at(&this.m_columns, i)
column.used_width = gfx.css_pixels_nearest_value_for_f64(gfx.mul_css_pixels_f64(*ak.vector_at_const(candidate_widths, i), candidate_weight) + gfx.mul_css_pixels_f64(column.used_width, 1.0 - candidate_weight))
# mark: Distributing excess width ===============================================================
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:647 Web::Layout::TableFormattingContext::distribute_excess_width_proportionally_to_base_width.
func layout_table_formatting_context_distribute_excess_width_proportionally_to_base_width(this: LayoutTableFormattingContext*, excess_width: gfx.CssPixels, column_filter: func(const LayoutTableFormattingContextColumn*) -> bool, base_width_getter: func(const LayoutTableFormattingContextColumn*) -> gfx.CssPixels) -> bool:
let columns = ak.vector_span(&this.m_columns)
var found_matching_columns = false
var total_base_width = layout_zero_px()
for column in &columns:
if column_filter(column):
total_base_width = total_base_width.add(base_width_getter(column))
found_matching_columns = true
if not found_matching_columns:
return false
assert(total_base_width.gt(layout_zero_px()))
for column in &columns:
if column_filter(column):
column.used_width = column.used_width.add(gfx.css_pixels_nearest_value_for_f64(gfx.div_css_pixels_f64(excess_width.mul(base_width_getter(column)), total_base_width.to_double())))
return true
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:670 Web::Layout::TableFormattingContext::distribute_excess_width_equally.
func layout_table_formatting_context_distribute_excess_width_equally(this: LayoutTableFormattingContext*, excess_width: gfx.CssPixels, column_filter: func(const LayoutTableFormattingContextColumn*) -> bool) -> bool:
let columns = ak.vector_span(&this.m_columns)
var matching_column_count: usize = 0
for column in &columns:
if column_filter(column):
matching_column_count += 1
if matching_column_count == 0:
return false
for column in &columns:
if column_filter(column):
column.used_width = column.used_width.add(layout_table_formatting_context_div_count(excess_width, matching_column_count))
# `return matching_column_count;` converts the count to bool.
return matching_column_count != 0
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:690 Web::Layout::TableFormattingContext::distribute_excess_width_by_intrinsic_percentage.
func layout_table_formatting_context_distribute_excess_width_by_intrinsic_percentage(this: LayoutTableFormattingContext*, excess_width: gfx.CssPixels, column_filter: func(const LayoutTableFormattingContextColumn*) -> bool) -> bool:
let columns = ak.vector_span(&this.m_columns)
var found_matching_columns = false
var total_percentage_width: f64 = 0.0
for column in &columns:
if column_filter(column):
found_matching_columns = true
total_percentage_width += column.intrinsic_percentage
if not found_matching_columns:
return false
for column in &columns:
if column_filter(column):
column.used_width = column.used_width.add(gfx.css_pixels_nearest_value_for_f64(gfx.mul_css_pixels_f64(excess_width, column.intrinsic_percentage) / total_percentage_width))
return true
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:711 Web::Layout::TableFormattingContext::distribute_width_to_columns.
func layout_table_formatting_context_distribute_width_to_columns(this: LayoutTableFormattingContext*):
# Implements https://www.w3.org/TR/css-tables-3/#width-distribution-algorithm
# The total horizontal border spacing is defined for each table:
# - For tables laid out in separated-borders mode containing at least one column, the horizontal component of the computed value of the border-spacing property times one plus the number of columns in the table
# - Otherwise, 0
let total_horizontal_border_spacing = layout_zero_px() if ak.vector_is_empty(&this.m_columns) else layout_table_formatting_context_mul_count(layout_table_formatting_context_border_spacing_horizontal(this), ak.vector_size(&this.m_columns) + 1)
# The assignable table width is the used width of the table minus the total horizontal border spacing (if any).
# This is the width that we will be able to allocate to the columns.
let available_width = layout_state_used_values_content_width(layout_state_get(this.formatting_context.m_state, layout_table_formatting_context_table_box(this).layout_node_with_style())).sub(total_horizontal_border_spacing)
var candidate_widths = ak.Vector[gfx.CssPixels]()
ak.vector_resize(&candidate_widths, ak.vector_size(&this.m_columns))
# 1. The min-content sizing-guess is the set of column width assignments where each column is assigned its min-content width.
for i in 0..<ak.vector_size(&this.m_columns):
let column = ak.vector_at(&this.m_columns, i)
# In fixed mode, the min-content width of percent-columns and auto-columns is considered to be zero:
# https://www.w3.org/TR/css-tables-3/#width-distribution-in-fixed-mode
if layout_table_formatting_context_use_fixed_mode_layout(this) and not column.is_constrained:
continue
column.used_width = column.min_size
*ak.vector_at(&candidate_widths, i) = column.min_size
# 2. The min-content-percentage sizing-guess is the set of column width assignments where:
# - each percent-column is assigned the larger of:
# - its intrinsic percentage width times the assignable width and
# - its min-content width.
# - all other columns are assigned their min-content width.
for i in 0..<ak.vector_size(&this.m_columns):
let column = ak.vector_at(&this.m_columns, i)
if column.has_intrinsic_percentage:
*ak.vector_at(&candidate_widths, i) = ak.max(column.min_size, gfx.css_pixels_nearest_value_for_f64(gfx.mul_css_pixels_f64(available_width, column.intrinsic_percentage / 100.0)))
# If the assignable table width is less than or equal to the max-content sizing-guess, the used widths of the columns must be the
# linear combination (with weights adding to 1) of the two consecutive sizing-guesses whose width sums bound the available width.
if available_width.lt(layout_compute_columns_total_candidate_width(&candidate_widths)):
layout_table_formatting_context_assign_columns_width_linear_combination(this, &candidate_widths, available_width)
return
else:
layout_table_formatting_context_commit_candidate_column_widths(this, &candidate_widths)
# 3. The min-content-specified sizing-guess is the set of column width assignments where:
# - each percent-column is assigned the larger of:
# - its intrinsic percentage width times the assignable width and
# - its min-content width
# - any other column that is constrained is assigned its max-content width
# - all other columns are assigned their min-content width.
for i in 0..<ak.vector_size(&this.m_columns):
let column = ak.vector_at(&this.m_columns, i)
if column.is_constrained:
*ak.vector_at(&candidate_widths, i) = column.max_size
if available_width.lt(layout_compute_columns_total_candidate_width(&candidate_widths)):
layout_table_formatting_context_assign_columns_width_linear_combination(this, &candidate_widths, available_width)
return
else:
layout_table_formatting_context_commit_candidate_column_widths(this, &candidate_widths)
# 4. The max-content sizing-guess is the set of column width assignments where:
# - each percent-column is assigned the larger of:
# - its intrinsic percentage width times the assignable width and
# - its min-content width
# - all other columns are assigned their max-content width.
for i in 0..<ak.vector_size(&this.m_columns):
let column = ak.vector_at(&this.m_columns, i)
if not column.has_intrinsic_percentage:
*ak.vector_at(&candidate_widths, i) = column.max_size
if available_width.lt(layout_compute_columns_total_candidate_width(&candidate_widths)):
layout_table_formatting_context_assign_columns_width_linear_combination(this, &candidate_widths, available_width)
return
else:
layout_table_formatting_context_commit_candidate_column_widths(this, &candidate_widths)
# Otherwise, the used widths of the columns are the result of starting from the max-content sizing-guess and distributing
# the excess width to the columns of the table according to the rules for distributing excess width to columns (for used width).
layout_table_formatting_context_distribute_excess_width_to_columns(this, available_width)
## Rule 1's column filter of distribute_excess_width_to_columns.
func layout_table_formatting_context_column_grows_by_rule_1(column: const LayoutTableFormattingContextColumn*) -> bool:
return not column.is_constrained and column.has_originating_cells and column.intrinsic_percentage == 0.0 and column.max_size.gt(layout_zero_px())
## Rule 2's column filter of distribute_excess_width_to_columns.
func layout_table_formatting_context_column_grows_by_rule_2(column: const LayoutTableFormattingContextColumn*) -> bool:
return not column.is_constrained and column.has_originating_cells and column.intrinsic_percentage == 0.0
## Rule 3's column filter of distribute_excess_width_to_columns.
func layout_table_formatting_context_column_grows_by_rule_3(column: const LayoutTableFormattingContextColumn*) -> bool:
return column.is_constrained and column.intrinsic_percentage == 0.0 and column.max_size.gt(layout_zero_px())
## The column filter of rule 4 of distribute_excess_width_to_columns and of the third rule of the fixed mode.
func layout_table_formatting_context_column_has_intrinsic_percentage_width(column: const LayoutTableFormattingContextColumn*) -> bool:
return column.intrinsic_percentage > 0.0
## Rule 5's column filter of distribute_excess_width_to_columns.
func layout_table_formatting_context_column_has_originating_cells(column: const LayoutTableFormattingContextColumn*) -> bool:
return column.has_originating_cells
## Rule 6's column filter of distribute_excess_width_to_columns: every column.
func layout_table_formatting_context_column_any(column: const LayoutTableFormattingContextColumn*) -> bool:
_ = column
return true
## The base width getter of rules 1 and 3 of distribute_excess_width_to_columns.
func layout_table_formatting_context_column_max_size(column: const LayoutTableFormattingContextColumn*) -> gfx.CssPixels:
return column.max_size
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:804 Web::Layout::TableFormattingContext::distribute_excess_width_to_columns.
func layout_table_formatting_context_distribute_excess_width_to_columns(this: LayoutTableFormattingContext*, available_width: gfx.CssPixels):
# Implements https://www.w3.org/TR/css-tables-3/#distributing-width-to-columns
let columns_total_used_width = layout_table_formatting_context_compute_columns_total_used_width(this)
if columns_total_used_width.ge(available_width):
return
var excess_width = available_width.sub(columns_total_used_width)
if excess_width == layout_zero_px():
return
if layout_table_formatting_context_use_fixed_mode_layout(this):
layout_table_formatting_context_distribute_excess_width_to_columns_fixed_mode(this, excess_width)
return
# 1. If there are non-constrained columns that have originating cells with intrinsic percentage width of 0% and with nonzero
# max-content width (aka the columns allowed to grow by this rule), the distributed widths of the columns allowed to grow
# by this rule are increased in proportion to max-content width so the total increase adds to the excess width.
if layout_table_formatting_context_distribute_excess_width_proportionally_to_base_width(this, excess_width, layout_table_formatting_context_column_grows_by_rule_1, layout_table_formatting_context_column_max_size):
excess_width = available_width.sub(layout_table_formatting_context_compute_columns_total_used_width(this))
if excess_width == layout_zero_px():
return
# 2. Otherwise, if there are non-constrained columns that have originating cells with intrinsic percentage width of 0% (aka the columns
# allowed to grow by this rule, which thanks to the previous rule must have zero max-content width), the distributed widths of the
# columns allowed to grow by this rule are increased by equal amounts so the total increase adds to the excess width.
if layout_table_formatting_context_distribute_excess_width_equally(this, excess_width, layout_table_formatting_context_column_grows_by_rule_2):
excess_width = available_width.sub(layout_table_formatting_context_compute_columns_total_used_width(this))
if excess_width == layout_zero_px():
return
# 3. Otherwise, if there are constrained columns with intrinsic percentage width of 0% and with nonzero max-content width
# (aka the columns allowed to grow by this rule, which, due to other rules, must have originating cells), the distributed widths of the
# columns allowed to grow by this rule are increased in proportion to max-content width so the total increase adds to the excess width.
if layout_table_formatting_context_distribute_excess_width_proportionally_to_base_width(this, excess_width, layout_table_formatting_context_column_grows_by_rule_3, layout_table_formatting_context_column_max_size):
excess_width = available_width.sub(layout_table_formatting_context_compute_columns_total_used_width(this))
if excess_width == layout_zero_px():
return
# 4. Otherwise, if there are columns with intrinsic percentage width greater than 0% (aka the columns allowed to grow by this rule,
# which, due to other rules, must have originating cells), the distributed widths of the columns allowed to grow by this rule are
# increased in proportion to intrinsic percentage width so the total increase adds to the excess width.
if layout_table_formatting_context_distribute_excess_width_by_intrinsic_percentage(this, excess_width, layout_table_formatting_context_column_has_intrinsic_percentage_width):
excess_width = available_width.sub(layout_table_formatting_context_compute_columns_total_used_width(this))
if excess_width == layout_zero_px():
return
# 5. Otherwise, if there is any such column, the distributed widths of all columns that have originating cells are increased by equal amounts
# so the total increase adds to the excess width.
if layout_table_formatting_context_distribute_excess_width_equally(this, excess_width, layout_table_formatting_context_column_has_originating_cells):
excess_width = available_width.sub(layout_table_formatting_context_compute_columns_total_used_width(this))
if excess_width == layout_zero_px():
return
# 6. Otherwise, the distributed widths of all columns are increased by equal amounts so the total increase adds to the excess width.
_ = layout_table_formatting_context_distribute_excess_width_equally(this, excess_width, layout_table_formatting_context_column_any)
## The first column filter of distribute_excess_width_to_columns_fixed_mode: the columns with no width specified.
func layout_table_formatting_context_column_has_no_specified_width(column: const LayoutTableFormattingContextColumn*) -> bool:
return not column.is_constrained and not column.has_intrinsic_percentage
## The second column filter of distribute_excess_width_to_columns_fixed_mode: the columns with a non-zero length width.
func layout_table_formatting_context_column_has_used_width(column: const LayoutTableFormattingContextColumn*) -> bool:
return column.used_width.gt(layout_zero_px())
## The base width getter of distribute_excess_width_to_columns_fixed_mode.
func layout_table_formatting_context_column_used_width(column: const LayoutTableFormattingContextColumn*) -> gfx.CssPixels:
return column.used_width
## The last column filter of distribute_excess_width_to_columns_fixed_mode: the zero-sized columns.
func layout_table_formatting_context_column_is_zero_sized(column: const LayoutTableFormattingContextColumn*) -> bool:
return column.used_width == layout_zero_px()
## Ported from Libraries/LibWeb/Layout/TableFormattingContext.cpp:886 Web::Layout::TableFormattingContext::distribute_excess_width_to_columns_fixed_mode.
func layout_table_formatting_context_distribute_excess_width_to_columns_fixed_mode(this: LayoutTableFormattingContext*, excess_width: gfx.CssPixels):
# Implements the fixed mode for https://www.w3.org/TR/css-tables-3/#distributing-width-to-columns.
# If there are any columns with no width specified, the excess width is distributed in equally to such columns
if layout_table_formatting_context_distribute_excess_width_equally(this, excess_width, layout_table_formatting_context_column_has_no_specified_width):
return
# otherwise, if there are columns with non-zero length widths from the base assignment, the excess width is distributed proportionally to width among those columns
if layout_table_formatting_context_distribute_excess_width_proportionally_to_base_width(this, excess_width, layout_table_formatting_context_column_has_used_width, layout_table_formatting_context_column_used_width):
return
# otherwise, if there are columns with non-zero percentage widths from the base assignment, the excess width is distributed proportionally to percentage width among those columns
if layout_table_formatting_context_distribute_excess_width_by_intrinsic_percentage(this, excess_width, layout_table_formatting_context_column_has_intrinsic_percentage_width):
return
# otherwise, the excess width is distributed equally to the zero-sized columns
_ = layout_table_formatting_context_distribute_excess_width_equally(this, excess_width, layout_table_formatting_context_column_is_zero_sized)