LibWeb: Fix height distribution in "vertical-align: baseline" in TFC

This line changes padding top to align cell content to baseline:
`cell.padding_top += m_rows[cell.row_index].baseline - cell.baseline`

Which means available for distribution height `height_diff` could have
changed so it needs to be refreshed before assigning the rest of it to
padding bottom:
`cell_state.padding_bottom += height_diff;`

Fixes https://github.com/SerenityOS/serenity/issues/22032
This commit is contained in:
Aliaksandr Kalenik 2024-04-19 10:04:00 +02:00 committed by Andreas Kling
commit 7b75d0c1f0
Notes: sideshowbarker 2024-07-17 07:43:44 +09:00
5 changed files with 113 additions and 6 deletions

View file

@ -1080,30 +1080,29 @@ void TableFormattingContext::position_cell_boxes()
for (auto& cell : m_cells) {
auto& cell_state = m_state.get_mutable(cell.box);
auto& row_state = m_state.get(m_rows[cell.row_index].box);
CSSPixels const cell_border_box_height = cell_state.content_height() + cell_state.border_box_top() + cell_state.border_box_bottom();
CSSPixels const row_content_height = compute_row_content_height(cell);
auto const row_content_height = compute_row_content_height(cell);
auto const& vertical_align = cell.box->computed_values().vertical_align();
// The following image shows various alignment lines of a row:
// https://www.w3.org/TR/css-tables-3/images/cell-align-explainer.png
if (vertical_align.has<CSS::VerticalAlign>()) {
auto height_diff = row_content_height - cell_border_box_height;
switch (vertical_align.get<CSS::VerticalAlign>()) {
case CSS::VerticalAlign::Middle: {
auto const height_diff = row_content_height - cell_state.border_box_height();
cell_state.padding_top += height_diff / 2;
cell_state.padding_bottom += height_diff / 2;
break;
}
case CSS::VerticalAlign::Top: {
cell_state.padding_bottom += height_diff;
cell_state.padding_bottom += row_content_height - cell_state.border_box_height();
break;
}
case CSS::VerticalAlign::Bottom: {
cell_state.padding_top += height_diff;
cell_state.padding_top += row_content_height - cell_state.border_box_height();
break;
}
case CSS::VerticalAlign::Baseline: {
cell_state.padding_top += m_rows[cell.row_index].baseline - cell.baseline;
cell_state.padding_bottom += height_diff;
cell_state.padding_bottom += row_content_height - cell_state.border_box_height();
break;
}
case CSS::VerticalAlign::Sub: {