From 87f0e835eb7fee2af95a365f29113f315571a755 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 20 Jan 2023 00:59:43 +0100 Subject: LibWeb: Improve auto height calculation for tables Change `compute_auto_height_for_block_level_element` to use max height (`m_automatic_content_height` produced from TFC) for tables with auto height which is more correct behaviour than treating them like block containers. --- Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 3 +++ Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp | 6 ++++-- Userland/Libraries/LibWeb/Layout/TableFormattingContext.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 59d11806cb..dd0c2efde5 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -404,6 +404,9 @@ CSSPixels BlockFormattingContext::compute_auto_height_for_block_level_element(Bo // max-content size. return calculate_max_content_height(box, available_space.width); } + if (display.is_table_inside()) { + return calculate_max_content_height(box, available_space.height); + } // https://www.w3.org/TR/CSS22/visudet.html#normal-block // 10.6.3 Block-level non-replaced elements in normal flow when 'overflow' computes to 'visible' diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index d0d7ae51e9..aa488751de 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -414,7 +414,7 @@ void TableFormattingContext::calculate_row_heights(LayoutMode layout_mode) } } -void TableFormattingContext::position_row_boxes() +void TableFormattingContext::position_row_boxes(CSSPixels& total_content_height) { auto const& table_state = m_state.get(table_box()); @@ -456,6 +456,8 @@ void TableFormattingContext::position_row_boxes() row_group_top_offset += row_group_height; }); + + total_content_height = max(row_top_offset, row_group_top_offset) - table_state.border_top - table_state.padding_top; } void TableFormattingContext::position_cell_boxes() @@ -520,7 +522,7 @@ void TableFormattingContext::run(Box const& box, LayoutMode layout_mode, Availab distribute_width_to_columns(); calculate_row_heights(layout_mode); - position_row_boxes(); + position_row_boxes(total_content_height); position_cell_boxes(); m_state.get_mutable(table_box()).set_content_height(total_content_height); diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h index 3776ed82c0..96122e7abd 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -33,7 +33,7 @@ private: void distribute_width_to_columns(); void determine_intrisic_size_of_table_container(AvailableSpace const& available_space); void calculate_row_heights(LayoutMode layout_mode); - void position_row_boxes(); + void position_row_boxes(CSSPixels&); void position_cell_boxes(); CSSPixels m_automatic_content_height { 0 }; -- cgit v1.2.3