Skip to content

Truly independent web browser

LibWeb: Don’t clamp an abspos table’s height to its containing block

sideshowbarker03aacf3138a5
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 9a87677e740..d4f5556c06f 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -3795,18 +3795,6 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
) -> TableWrapperBlockSizes {
let wrapper = sized.node;
// The table wrapper block size should equal the block size of the table box it contains.
-
- let style = self.style(wrapper);
- let containing_block_inline_size = available_space.inline_size.to_px_or_zero();
- let containing_block_block_size = available_space.block_size.to_px_or_zero();
-
- // If 'margin-top', or 'margin-bottom' are computed as 'auto', their used value is '0'.
- let margin_top = style.margin_top().to_px(containing_block_inline_size);
- let margin_bottom = style.margin_bottom().to_px(containing_block_inline_size);
-
- // table-wrapper can't have borders or paddings but it might have margin taken from table-root.
- let available_block_size = containing_block_block_size - margin_top - margin_bottom;
-
let wrapper_inner_space = sized
.metrics()
.available_inner_space_or_constraints_from(available_space);
@@ -3830,14 +3818,12 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
),
);
- let table_used_block_size = wrapper_outputs
+ // NB: A table is as tall as its rows and its specified height make it, even when that's taller than the space
+ // available to it, which it then overflows.
+ // https://drafts.csswg.org/css-tables-3/#computing-the-table-height
+ let table_box_border_box_block_size = wrapper_outputs
.table_box_in_wrapper_border_box_block_size
.expect("a table wrapper's measurement run lays out the table box inside it");
- let table_box_border_box_block_size = if matches!(available_space.block_size, AvailableSize::Definite(_)) {
- table_used_block_size.min(available_block_size)
- } else {
- table_used_block_size
- };
TableWrapperBlockSizes {
table_box_border_box_block_size,
wrapper_content_block_size: wrapper_outputs.automatic_content_block_size,
diff --git a/Tests/LibWeb/Text/expected/abspos-table-height-overflows-containing-block.txt b/Tests/LibWeb/Text/expected/abspos-table-height-overflows-containing-block.txt
new file mode 100644
index 00000000000..4100ca5e936
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/abspos-table-height-overflows-containing-block.txt
@@ -0,0 +1,8 @@
+a: offsetHeight=24 rect.height=24
+b: offsetHeight=24 rect.height=24
+c: offsetHeight=16 rect.height=16
+d: offsetHeight=24 rect.height=24
+e: offsetHeight=24 rect.height=24
+f: offsetHeight=16 rect.height=16
+g: offsetHeight=200 rect.height=200
+h: offsetHeight=16 rect.height=16
diff --git a/Tests/LibWeb/Text/input/abspos-table-height-overflows-containing-block.html b/Tests/LibWeb/Text/input/abspos-table-height-overflows-containing-block.html
new file mode 100644
index 00000000000..7eafcc5dcc0
--- /dev/null
+++ b/Tests/LibWeb/Text/input/abspos-table-height-overflows-containing-block.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<!-- An absolutely positioned table is as tall as its rows and its specified height make it: never clamped to its
+ containing block, and not stretched by its insets. -->
+<style>
+ .cb { position: relative; width: 400px; }
+ .t { top: 8px; left: 10px; width: 200px; table-layout: fixed; }
+ .cell { display: table-cell; background: #ccc; }
+</style>
+<div class="cb" style="height: 1px"><div id="a" class="t" style="position: absolute; display: table; height: 24px"><div class="cell">cell</div></div></div>
+<div class="cb"><div id="b" class="t" style="position: absolute; display: table; height: 24px"><div class="cell">cell</div></div></div>
+<div class="cb" style="height: 1px"><div id="c" class="t" style="position: absolute; display: table"><div class="cell">cell</div></div></div>
+<div class="cb" style="height: 1px"><div id="d" class="t" style="position: absolute; display: block; height: 24px"><div class="cell">cell</div></div></div>
+<div class="cb" style="height: 1px; margin-bottom: 40px"><div id="e" class="t" style="position: relative; display: table; height: 24px"><div class="cell">cell</div></div></div>
+<div class="cb" style="height: 100px"><div id="f" class="t" style="position: absolute; display: table; top: 0; bottom: 0"><div class="cell">cell</div></div></div>
+<div class="cb" style="height: 100px"><div id="g" class="t" style="position: absolute; display: table; height: 200px"><div class="cell">cell</div></div></div>
+<div class="cb" style="height: 100px; margin-bottom: 120px"><div id="h" class="t" style="position: absolute; display: table; top: 0; bottom: 0; height: 5px"><div class="cell">cell</div></div></div>
+<script>
+ test(() => {
+ for (const id of ["a", "b", "c", "d", "e", "f", "g", "h"]) {
+ const el = document.getElementById(id);
+ const r = el.getBoundingClientRect();
+ println(`${id}: offsetHeight=${el.offsetHeight} rect.height=${r.height}`);
+ }
+ });
+</script>