Truly independent web browser
LibWeb: Don't key table cell measurements on the cell's own width
Aliaksandr Kalenikc7cd24f755aa
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 5724add561f..81186a5e5d3 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -1435,6 +1435,9 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {if facts.is_anonymous() || facts.is_replaced_box() || facts.has_auto_content_box_size() {return true;}+ if facts.is_table_cell() {+ return Self::box_edges_contain_percentage(self.style(node));+ }Self::own_box_resolves_percentage_against_inline_basis(self.style(node))}diff --git a/Tests/LibWeb/Text/expected/table-cell-percentage-width-measurement-reuse.txt b/Tests/LibWeb/Text/expected/table-cell-percentage-width-measurement-reuse.txtnew file mode 100644index 00000000000..cd11f9f145f--- /dev/null+++ b/Tests/LibWeb/Text/expected/table-cell-percentage-width-measurement-reuse.txt@@ -0,0 +1,2 @@+number cell measurements missed: 0+geometry matches a fresh layout: truediff --git a/Tests/LibWeb/Text/input/table-cell-percentage-width-measurement-reuse.html b/Tests/LibWeb/Text/input/table-cell-percentage-width-measurement-reuse.htmlnew file mode 100644index 00000000000..ce1e9b89f46--- /dev/null+++ b/Tests/LibWeb/Text/input/table-cell-percentage-width-measurement-reuse.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<script src="include.js"></script>+<style>+ body { margin: 0; font: 16px/20px monospace; }+ .container { width: 600px; }+ .number { width: 1%; min-width: 30px; padding: 0 8px; text-align: right; }+ .indented { width: 10%; text-indent: 50%; }+ .half { width: 50%; }+</style>+<div class="container" id="container"></div>+<script>+ // A table cell's own percentage width resolves against the table, so it does not make the measurement of the+ // cell's content depend on the table's containing block: that measurement is reused when only the width changes.+ test(() => {+ let rows = "";+ for (let index = 0; index < 20; ++index)+ rows += `<tr><td class="number">${index}</td><td class="indented">indented text ${index}</td><td><div class="half">some longer line of code ${index}</div></td></tr>`;+ container.innerHTML = `<table>${rows}</table>`;+ document.body.offsetHeight;++ internals.beginLayoutTrace();+ container.style.width = "700px";+ document.body.offsetHeight;+ const misses = internals.takeLayoutTrace().split("\n").filter(line => line.includes("<TD>.number MEASURE") && line.includes("cache=miss"));+ println(`number cell measurements missed: ${misses.length}`);++ const fresh = container.cloneNode(true);+ fresh.id = "";+ document.body.appendChild(fresh);+ const geometry = root => Array.from(root.querySelectorAll("td, div")).map(element => {+ const rect = element.getBoundingClientRect();+ const rootRect = root.getBoundingClientRect();+ return `${rect.left - rootRect.left},${rect.top - rootRect.top},${rect.width},${rect.height}`;+ }).join(" ");+ println(`geometry matches a fresh layout: ${geometry(container) === geometry(fresh)}`);+ });+</script>