summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksandr Kalenik <kalenik.aliaksandr@gmail.com>2023-04-28 02:43:48 +0300
committerAndreas Kling <kling@serenityos.org>2023-04-28 06:17:07 +0200
commit2a1e58f8cc0dfe4f1be920bed909aaeeca963a9b (patch)
tree6a97c2631e15b399128423fce96e599fc0057155
parent9b4cd0dab7d33090f398321c8dd46b9e3076b5ff (diff)
downloadserenity-2a1e58f8cc0dfe4f1be920bed909aaeeca963a9b.zip
LibWeb: Consider cell computed height in total row min height of table
Previously, the minimum height of a table row was calculated based on the automatic height of the cells inner layout. This change makes computed height of a cell boxes also be considered if it has definite value.
-rw-r--r--Tests/LibWeb/Layout/expected/css-pseudo-element-should-not-be-affected-by-presentational-hints.txt18
-rw-r--r--Tests/LibWeb/Layout/expected/table/cell-px-height.txt6
-rw-r--r--Tests/LibWeb/Layout/input/table/cell-px-height.html17
-rw-r--r--Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp12
4 files changed, 43 insertions, 10 deletions
diff --git a/Tests/LibWeb/Layout/expected/css-pseudo-element-should-not-be-affected-by-presentational-hints.txt b/Tests/LibWeb/Layout/expected/css-pseudo-element-should-not-be-affected-by-presentational-hints.txt
index 2e7686b39c..cd7d56ea0e 100644
--- a/Tests/LibWeb/Layout/expected/css-pseudo-element-should-not-be-affected-by-presentational-hints.txt
+++ b/Tests/LibWeb/Layout/expected/css-pseudo-element-should-not-be-affected-by-presentational-hints.txt
@@ -1,13 +1,13 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
- BlockContainer <html> at (1,1) content-size 798x47.835937 children: not-inline
- BlockContainer <body> at (10,10) content-size 780x29.835937 children: not-inline
- TableWrapper <(anonymous)> at (10,10) content-size 104x29.835937 children: not-inline
- TableBox <table> at (11,11) content-size 104x27.835937 children: not-inline
- TableRowGroupBox <tbody> at (11,11) content-size 104x27.835937 children: not-inline
- TableRowBox <tr> at (11,11) content-size 104x27.835937 children: not-inline
- TableCellBox <td> at (13,13) content-size 100x23.835937 children: not-inline
- BlockContainer <(anonymous)> at (14,14) content-size 98x21.835937 children: inline
+ BlockContainer <html> at (1,1) content-size 798x120 children: not-inline
+ BlockContainer <body> at (10,10) content-size 780x102 children: not-inline
+ TableWrapper <(anonymous)> at (10,10) content-size 104x102 children: not-inline
+ TableBox <table> at (11,11) content-size 104x100 children: not-inline
+ TableRowGroupBox <tbody> at (11,11) content-size 104x100 children: not-inline
+ TableRowBox <tr> at (11,11) content-size 104x100 children: not-inline
+ TableCellBox <td> at (13,49.082031) content-size 100x23.835937 children: not-inline
+ BlockContainer <(anonymous)> at (14,50.082031) content-size 98x21.835937 children: inline
line 0 width: 0, height: 21.835937, bottom: 21.835937, baseline: 16.914062
- frag 0 from TextNode start: 0, length: 0, rect: [14,14 0x21.835937]
+ frag 0 from TextNode start: 0, length: 0, rect: [14,50.082031 0x21.835937]
""
TextNode <#text>
diff --git a/Tests/LibWeb/Layout/expected/table/cell-px-height.txt b/Tests/LibWeb/Layout/expected/table/cell-px-height.txt
new file mode 100644
index 0000000000..fa68c787f0
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/table/cell-px-height.txt
@@ -0,0 +1,6 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+ BlockContainer <html> at (0,0) content-size 800x116 children: not-inline
+ TableWrapper <(anonymous)> at (8,8) content-size 102x100 children: not-inline
+ TableBox <body> at (8,8) content-size 102x100 children: not-inline
+ TableRowBox <div.row> at (8,8) content-size 102x100 children: not-inline
+ TableCellBox <div.cell> at (9,9) content-size 100x0 children: not-inline
diff --git a/Tests/LibWeb/Layout/input/table/cell-px-height.html b/Tests/LibWeb/Layout/input/table/cell-px-height.html
new file mode 100644
index 0000000000..96a9d6ae7c
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/table/cell-px-height.html
@@ -0,0 +1,17 @@
+<style>
+body {
+ display: table;
+}
+
+.row {
+ display: table-row;
+}
+
+.cell {
+ display: table-cell;
+ border: 1px solid black;
+ width: 100px;
+ height: 100px;
+}
+</style>
+<div class="row"><div class="cell"></div></div> \ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
index 4d77098045..354502fb3a 100644
--- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
@@ -388,6 +388,7 @@ void TableFormattingContext::determine_intrisic_size_of_table_container(Availabl
void TableFormattingContext::calculate_row_heights(LayoutMode layout_mode)
{
for (auto& cell : m_cells) {
+ auto& row = m_rows[cell.row_index];
auto& cell_state = m_state.get_mutable(cell.box);
CSSPixels span_width = 0;
@@ -396,6 +397,8 @@ void TableFormattingContext::calculate_row_heights(LayoutMode layout_mode)
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);
+ auto height_of_containing_block = m_state.get(*cell.box->containing_block()).content_height();
+ auto height_of_containing_block_as_length = CSS::Length::make_px(height_of_containing_block);
cell_state.padding_top = cell.box->computed_values().padding().top().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
cell_state.padding_bottom = cell.box->computed_values().padding().bottom().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
@@ -413,6 +416,14 @@ void TableFormattingContext::calculate_row_heights(LayoutMode layout_mode)
cell_state.border_left = (should_hide_borders && is_left_most_cell) ? 0 : cell.box->computed_values().border_left().width;
cell_state.border_right = (should_hide_borders && is_right_most_cell) ? 0 : cell.box->computed_values().border_right().width;
+ auto cell_computed_height = cell.box->computed_values().height();
+ if (cell_computed_height.is_length()) {
+ auto cell_used_height = cell_computed_height.resolved(cell.box, height_of_containing_block_as_length).to_px(cell.box);
+ cell_state.set_content_height(cell_used_height - cell_state.border_box_top() - cell_state.border_box_bottom());
+
+ row.used_height = max(row.used_height, cell_used_height);
+ }
+
cell_state.set_content_width((span_width - cell_state.border_box_left() - cell_state.border_box_right()));
if (auto independent_formatting_context = layout_inside(cell.box, layout_mode, cell_state.available_inner_space_or_constraints_from(*m_available_space))) {
cell_state.set_content_height(independent_formatting_context->automatic_content_height());
@@ -421,7 +432,6 @@ void TableFormattingContext::calculate_row_heights(LayoutMode layout_mode)
cell.baseline = box_baseline(m_state, cell.box);
- auto& row = m_rows[cell.row_index];
row.used_height = max(row.used_height, cell_state.border_box_height());
row.baseline = max(row.baseline, cell.baseline);
}