summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAliaksandr Kalenik <kalenik.aliaksandr@gmail.com>2022-12-09 13:44:41 +0300
committerAndreas Kling <kling@serenityos.org>2022-12-09 12:53:05 +0100
commit1a81521dd9de6b873de00fa7574966068b27dce3 (patch)
treecf2222f47fe32f863a32c4166f0be39188e57cac /Userland
parent1da26f73955ffe4e2c450029920c625f0bd2c883 (diff)
downloadserenity-1a81521dd9de6b873de00fa7574966068b27dce3.zip
LibWeb: Consider specified cell widths in a table
This change makes outer min-content width and outer max-content width for cells to be calculated in the way specifed in the spec: - The outer min-content width of a table-cell is max(min-width, min-content width) adjusted by the cell intrinsic offsets. - The outer max-content width of a table-cell in a non-constrained column is max(min-width, width, min-content width, min(max-width, max-content width)) adjusted by the cell intrinsic offsets. - The outer max-content width of a table-cell in a constrained column is max(min-width, width, min-content width, min(max-width, width)) adjusted by the cell intrinsic offsets.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
index 1b19fc0a8f..68c1b12cc8 100644
--- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
@@ -106,15 +106,28 @@ void TableFormattingContext::compute_table_measures()
for (auto& cell : m_cells) {
auto width_of_containing_block = m_state.get(*cell.box.containing_block()).content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
- float padding_left = cell.box.computed_values().padding().left().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
- float padding_right = cell.box.computed_values().padding().right().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
- float border_left = cell.box.computed_values().border_left().width;
- float border_right = cell.box.computed_values().border_right().width;
-
- auto min_width = calculate_min_content_width(cell.box) + padding_left + padding_right + border_left + border_right;
- auto max_width = calculate_max_content_width(cell.box) + padding_left + padding_right + border_left + border_right;
- m_columns[cell.column_index].min_width = max(m_columns[cell.column_index].min_width, min_width);
- m_columns[cell.column_index].max_width = max(m_columns[cell.column_index].max_width, max_width);
+ auto& computed_values = cell.box.computed_values();
+ float padding_left = computed_values.padding().left().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
+ float padding_right = computed_values.padding().right().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
+ float border_left = computed_values.border_left().width;
+ float border_right = computed_values.border_right().width;
+ float width = computed_values.width().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
+ auto cell_intrinsic_offsets = padding_left + padding_right + border_left + border_right;
+ auto min_content_width = calculate_min_content_width(cell.box);
+ auto max_content_width = calculate_max_content_width(cell.box);
+
+ float min_width = min_content_width;
+ if (!computed_values.min_width().is_auto())
+ min_width = max(min_width, computed_values.min_width().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box));
+
+ float max_width = computed_values.width().is_auto() ? max_content_width : width;
+ if (!computed_values.max_width().is_none())
+ max_width = min(max_width, computed_values.max_width().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box));
+
+ auto cell_outer_min_content_width = min_width + cell_intrinsic_offsets;
+ auto cell_outer_max_content_width = max(max(width, min_width), max_width) + cell_intrinsic_offsets;
+ m_columns[cell.column_index].min_width = max(m_columns[cell.column_index].min_width, cell_outer_min_content_width);
+ m_columns[cell.column_index].max_width = max(m_columns[cell.column_index].max_width, cell_outer_max_content_width);
}
for (auto& column : m_columns) {