Skip to content

Truly independent web browser

LibWeb: Rebuild the parent when content makes an element an image

Andreas Kling5b7a1745c9e5
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
index 374e85cfd92..63bc8f8836c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
@@ -554,6 +554,11 @@ fn property_invalidation(property: u16, old: ComputedValuesView<'_>, new: Comput
{
return StyleInvalidation::rebuild_layout_tree_from(REBUILD_ROOT_SELF);
}
+ // An element whose content is a single image generates another box than one that does not, which its parent's fixup
+ // and wrappers have to take in.
+ if property == property_id::CONTENT && old.content_is_single_image() != new.content_is_single_image() {
+ return StyleInvalidation::full();
+ }
if matches!(
property,
property_id::APPEARANCE | property_id::CONTENT | property_id::CONTENT_VISIBILITY | property_id::TEXT_TRANSFORM
diff --git a/Tests/LibWeb/Text/expected/Layout/content-image-flip-rebuilds-the-parent.txt b/Tests/LibWeb/Text/expected/Layout/content-image-flip-rebuilds-the-parent.txt
new file mode 100644
index 00000000000..3dceef99b2b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Layout/content-image-flip-rebuilds-the-parent.txt
@@ -0,0 +1,20 @@
+legend, non to url: matches a full rebuild
+legend, url to non: matches a full rebuild
+legend, nor to url: matches a full rebuild
+legend, url to nor: matches a full rebuild
+cell, non to url: matches a full rebuild
+cell, url to non: matches a full rebuild
+cell, nor to url: matches a full rebuild
+cell, url to nor: matches a full rebuild
+row, non to url: matches a full rebuild
+row, url to non: matches a full rebuild
+row, nor to url: matches a full rebuild
+row, url to nor: matches a full rebuild
+caption, non to url: matches a full rebuild
+caption, url to non: matches a full rebuild
+caption, nor to url: matches a full rebuild
+caption, url to nor: matches a full rebuild
+column group, non to url: matches a full rebuild
+column group, url to non: matches a full rebuild
+column group, nor to url: matches a full rebuild
+column group, url to nor: matches a full rebuild
diff --git a/Tests/LibWeb/Text/input/Layout/content-image-flip-rebuilds-the-parent.html b/Tests/LibWeb/Text/input/Layout/content-image-flip-rebuilds-the-parent.html
new file mode 100644
index 00000000000..adae3601f49
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Layout/content-image-flip-rebuilds-the-parent.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<body>
+<script>
+ const image = "url(data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEAAAAALAAAAAABAAEAAAIBAAA=)";
+
+ function check(label, html) {
+ for (const [from, to] of [["none", image], [image, "none"], ["normal", image], [image, "normal"]]) {
+ const host = document.createElement("div");
+ host.innerHTML = html;
+ document.body.append(host);
+ const target = host.querySelector("#t");
+ target.style.content = from;
+ document.body.offsetWidth;
+ target.style.content = to;
+ document.body.offsetWidth;
+ const comparison = internals.compareLayoutTreeWithFullRebuild();
+ println(`${label}, ${from.slice(0, 3)} to ${to.slice(0, 3)}: ${comparison.matches ? "matches a full rebuild" : "differs from a full rebuild"}`);
+ host.remove();
+ }
+ }
+
+ test(() => {
+ check("legend", "<fieldset><legend id=t>l</legend>x</fieldset>");
+ check("cell", "<table><tr><td id=t>a</td></tr></table>");
+ check("row", "<table><tr id=t><td>a</td></tr></table>");
+ check("caption", "<table><caption id=t>c</caption><tr><td>a</td></tr></table>");
+ check("column group", "<table><colgroup id=t><col></colgroup><tr><td>a</td></tr></table>");
+ });
+</script>