Skip to content

Truly independent web browser

LibWeb: Don't take a table's box record for a table's style

Andreas Kling7e22af4eef10
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
index c5574ef5cbb..609ef9d4c02 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
@@ -786,14 +786,18 @@ impl Record {
/// Whether `other` holds the computed values this record does.
fn holds_the_same_values_as(&self, other: &Record) -> bool {
let (mine, theirs) = (self.value_groups(), other.value_groups());
- mine.iter()
- .zip(theirs.iter())
- .enumerate()
- .all(|(group, (mine, theirs))| {
- mine.as_ptr() == theirs.as_ptr()
+ // NB: The groups a derived record answers from are its source's, whose bits can differ from its own: a table's box
+ // holds none of the outer properties the table computes.
+ mine.reset_bits() == theirs.reset_bits()
+ && mine
+ .iter()
+ .zip(theirs.iter())
+ .enumerate()
+ .all(|(group, (mine, theirs))| {
+ mine.as_ptr() == theirs.as_ptr()
// SAFETY: Both records hold a reference to each of their value groups.
|| unsafe { crate::css::computed_values::hold_the_same_values(group, mine.as_ptr(), theirs.as_ptr()) }
- })
+ })
}
/// Whether `other` holds the custom declarations this record does: the element's own, which
diff --git a/Tests/LibWeb/Text/expected/Layout/table-outer-properties-after-a-style-change.txt b/Tests/LibWeb/Text/expected/Layout/table-outer-properties-after-a-style-change.txt
new file mode 100644
index 00000000000..f48926806d3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Layout/table-outer-properties-after-a-style-change.txt
@@ -0,0 +1,15 @@
+table, float left to none: none, matches a full rebuild
+table, float none to left: left, matches a full rebuild
+table, position absolute to static: static, matches a full rebuild
+table, position static to absolute: absolute, matches a full rebuild
+table, position fixed to relative: relative, matches a full rebuild
+display: table, float left to none: none, matches a full rebuild
+display: table, float none to left: left, matches a full rebuild
+display: table, position absolute to static: static, matches a full rebuild
+display: table, position static to absolute: absolute, matches a full rebuild
+display: table, position fixed to relative: relative, matches a full rebuild
+inline-table, float left to none: none, matches a full rebuild
+inline-table, float none to left: left, matches a full rebuild
+inline-table, position absolute to static: static, matches a full rebuild
+inline-table, position static to absolute: absolute, matches a full rebuild
+inline-table, position fixed to relative: relative, matches a full rebuild
diff --git a/Tests/LibWeb/Text/input/Layout/table-outer-properties-after-a-style-change.html b/Tests/LibWeb/Text/input/Layout/table-outer-properties-after-a-style-change.html
new file mode 100644
index 00000000000..42fc40651df
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Layout/table-outer-properties-after-a-style-change.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<body>
+<script>
+ function check(label, html, property, from, to) {
+ const host = document.createElement("div");
+ host.innerHTML = html;
+ document.body.append(host);
+ const target = host.querySelector("#t");
+ target.style.setProperty(property, from);
+ document.body.offsetWidth;
+ target.style.setProperty(property, to);
+ const value = getComputedStyle(target).getPropertyValue(property);
+ document.body.offsetWidth;
+ const comparison = internals.compareLayoutTreeWithFullRebuild();
+ println(`${label}, ${property} ${from} to ${to}: ${value}, ${comparison.matches ? "matches a full rebuild" : "differs from a full rebuild"}`);
+ host.remove();
+ }
+
+ test(() => {
+ const table = "<table id=t><tr><td>a</td></tr></table>";
+ const displayTable = "<div id=t style='display: table'>a</div>";
+ const inlineTable = "<table id=t style='display: inline-table'><tr><td>a</td></tr></table>";
+ for (const [label, html] of [["table", table], ["display: table", displayTable], ["inline-table", inlineTable]]) {
+ check(label, html, "float", "left", "none");
+ check(label, html, "float", "none", "left");
+ check(label, html, "position", "absolute", "static");
+ check(label, html, "position", "static", "absolute");
+ check(label, html, "position", "fixed", "relative");
+ }
+ });
+</script>