1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

LibWeb: Start working on supporting fixed table layouts

Sometimes people make tables with a specific width. In those cases,
we can't just use the auto-sizing algorithm, but instead have to
respect whatever width the content specifies.

This is a bit rickety right now, since we don't implement generation
of anonymous table boxes.

The basic mechanism here is that block layout (which table-cell uses)
now has a virtual way of asking for the width of the logical containing
block. This is necessary as table-row does not produce a block-level
element and so was previously unable to provide a containing block
width for table-cell layout.

If the table has a non-auto specified width, we now interpret that as
a request to use fixed table layout. This will evolve over time. :^)
This commit is contained in:
Andreas Kling 2020-06-28 15:11:08 +02:00
parent daa88448e1
commit 7fc988b919
5 changed files with 45 additions and 13 deletions

View file

@ -25,6 +25,7 @@
*/
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/LayoutTable.h>
#include <LibWeb/Layout/LayoutTableCell.h>
#include <LibWeb/Layout/LayoutTableRow.h>
@ -47,7 +48,12 @@ void LayoutTableRow::calculate_column_widths(Vector<float>& column_widths)
{
size_t column_index = 0;
for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
cell.layout(LayoutMode::OnlyRequiredLineBreaks);
auto* table = first_ancestor_of_type<LayoutTable>();
if (table && !table->style().width().is_undefined_or_auto()) {
cell.layout(LayoutMode::Default);
} else {
cell.layout(LayoutMode::OnlyRequiredLineBreaks);
}
column_widths[column_index] = max(column_widths[column_index], cell.width());
column_index += cell.colspan();
});
@ -67,7 +73,14 @@ void LayoutTableRow::layout_row(const Vector<float>& column_widths)
content_width += column_widths[column_index++];
tallest_cell_height = max(tallest_cell_height, cell.height());
});
set_width(content_width);
auto* table = first_ancestor_of_type<LayoutTable>();
if (table && !table->style().width().is_undefined_or_auto()) {
set_width(table->width());
} else {
set_width(content_width);
}
set_height(tallest_cell_height);
}