Skip to content

Truly independent web browser

LibWeb: Fix up tables after a build that replaces the viewport

sideshowbarker8ffb819f5c40
diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
index 6d48e2ae6de..7ee060dcb1e 100644
--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs
@@ -1498,8 +1498,9 @@ impl TreeBuildJob {
document_needs_full_layout_tree_update: host.arena().needs_full_layout_tree_update(),
..Default::default()
};
- // Whether the document already had a viewport, read before the build replaces it.
- let document_had_layout_node = !host.arena().layout_root().is_invalid();
+ // The document's viewport, read before the build replaces it.
+ let prior_document_layout_node = host.arena().layout_root();
+ let document_had_layout_node = !prior_document_layout_node.is_invalid();
if document_had_layout_node && !context.document_needs_full_layout_tree_update {
state.quote_depth_cursor = Some(QuoteDepthCursor::new(host.arena(), document_identity));
}
@@ -1516,9 +1517,11 @@ impl TreeBuildJob {
let document_layout_node = host.arena().layout_root();
// NB: A build that escaped its rebuild roots still skipped every clean subtree, so it did not build the
- // whole tree again.
+ // whole tree again. A build that gave the document a new viewport did, though it recorded no rebuild root.
let rebuilt_whole_tree = !document_layout_node.is_invalid()
- && (context.document_needs_full_layout_tree_update || !document_had_layout_node);
+ && (context.document_needs_full_layout_tree_update
+ || !document_had_layout_node
+ || document_layout_node != prior_document_layout_node);
let rebuilt_subtrees_were_updated_individually = !document_layout_node.is_invalid()
&& !rebuilt_whole_tree
&& !state.layout_tree_update_escaped_rebuild_roots;
diff --git a/Tests/LibWeb/Text/expected/layout-tree-update/comment-after-html-keeps-anonymous-table-boxes.txt b/Tests/LibWeb/Text/expected/layout-tree-update/comment-after-html-keeps-anonymous-table-boxes.txt
new file mode 100644
index 00000000000..194f91490f3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/layout-tree-update/comment-after-html-keeps-anonymous-table-boxes.txt
@@ -0,0 +1,3 @@
+cell in a table: unchanged
+lone cell: unchanged
+cell in a row in a float: unchanged
diff --git a/Tests/LibWeb/Text/input/layout-tree-update/comment-after-html-keeps-anonymous-table-boxes.html b/Tests/LibWeb/Text/input/layout-tree-update/comment-after-html-keeps-anonymous-table-boxes.html
new file mode 100644
index 00000000000..51174b8e938
--- /dev/null
+++ b/Tests/LibWeb/Text/input/layout-tree-update/comment-after-html-keeps-anonymous-table-boxes.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<div style="display: table"><div id="cell" style="display: table-cell; padding: 10px">one</div><div style="display: table-cell; padding: 10px">two</div></div>
+<div id="lone-cell" style="display: table-cell">lone</div>
+<div style="float: left"><div style="display: table-row"><div id="row-cell" style="display: table-cell; padding: 10px">cell</div></div></div>
+<script src="../include.js"></script>
+<script>
+ const size = id => {
+ const rect = document.getElementById(id).getBoundingClientRect();
+ return `${Math.round(rect.width)}x${Math.round(rect.height)}`;
+ };
+ const cases = [
+ ["cell in a table", "cell"],
+ ["lone cell", "lone-cell"],
+ ["cell in a row in a float", "row-cell"],
+ ];
+
+ promiseTest(async () => {
+ const before = cases.map(([, id]) => size(id));
+ document.appendChild(document.createComment("after html"));
+ await animationFrame();
+ cases.forEach(([name, id], index) => {
+ const after = size(id);
+ println(`${name}: ${after === before[index] ? "unchanged" : `${before[index]} became ${after}`}`);
+ });
+ });
+</script>