LibWeb: Add vertical-align support for table cells

This commit is contained in:
Aliaksandr Kalenik 2022-12-04 20:02:28 +03:00 committed by Andreas Kling
parent ba64d0462c
commit fae0b96fe4
Notes: sideshowbarker 2024-07-17 23:00:03 +09:00
2 changed files with 29 additions and 2 deletions

View file

@ -251,8 +251,11 @@ void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace cons
BlockFormattingContext::compute_height(cell.box, AvailableSpace(AvailableSize::make_indefinite(), AvailableSize::make_indefinite()));
Row& row = m_rows[cell.row_index];
cell.baseline = box_baseline(m_state, cell.box);
auto& row = m_rows[cell.row_index];
row.used_width = max(row.used_width, cell_state.border_box_height());
row.baseline = max(row.baseline, cell.baseline);
}
for (size_t y = 0; y < m_rows.size(); y++) {
@ -293,7 +296,29 @@ void TableFormattingContext::run(Box const& box, LayoutMode, AvailableSpace cons
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);
cell_state.set_content_height(row_state.content_height() - cell_state.border_box_top() - cell_state.border_box_bottom());
float const cell_border_box_height = cell_state.content_height() + cell_state.border_box_top() + cell_state.border_box_bottom();
float const row_content_height = row_state.content_height();
auto const& vertical_align = cell.box.computed_values().vertical_align();
if (vertical_align.has<CSS::VerticalAlign>()) {
switch (vertical_align.get<CSS::VerticalAlign>()) {
case CSS::VerticalAlign::Middle: {
cell_state.padding_top += (row_content_height - cell_border_box_height) / 2;
cell_state.padding_bottom += (row_content_height - cell_border_box_height) / 2;
break;
}
// FIXME: implement actual 'top' and 'bottom' support instead of fall back to 'baseline'
case CSS::VerticalAlign::Top:
case CSS::VerticalAlign::Bottom:
case CSS::VerticalAlign::Baseline: {
cell_state.padding_top += m_rows[cell.row_index].baseline - cell.baseline;
cell_state.padding_bottom += row_content_height - cell_border_box_height;
break;
}
default:
VERIFY_NOT_REACHED();
}
}
cell_state.offset = row_state.offset.translated(cell_state.border_box_left() + m_columns[cell.column_index].left_offset, cell_state.border_box_top());
}

View file

@ -38,6 +38,7 @@ private:
struct Row {
Box& box;
float used_width { 0 };
float baseline { 0 };
};
struct Cell {
@ -46,6 +47,7 @@ private:
size_t row_index;
size_t column_span;
size_t raw_span;
float baseline { 0 };
};
Vector<Cell> m_cells;