Skip to content

Truly independent web browser

LibWeb: Don't detach a legend's box in place

Andreas Klinge4b0e0480aeb
diff --git a/Libraries/LibWeb/Rust/src/layout/box_removal.rs b/Libraries/LibWeb/Rust/src/layout/box_removal.rs
index d347e6c689b..e4ebe206603 100644
--- a/Libraries/LibWeb/Rust/src/layout/box_removal.rs
+++ b/Libraries/LibWeb/Rust/src/layout/box_removal.rs
@@ -173,6 +173,11 @@ impl LayoutNodeArena {
return true;
}
+ // A rendered legend decides whether its fieldset has an anonymous content box, and which legend is rendered.
+ if child_data.kind.get() == NodeKind::LegendBox {
+ return false;
+ }
+
let child_style = self.node_style_if_live(child);
if child_data.parent.get() != parent || node_facts::node_is_out_of_flow(child_data, child_style) {
return false;
diff --git a/Tests/LibWeb/Text/expected/HTML/fieldset-legend-removed-rebuilds-box.txt b/Tests/LibWeb/Text/expected/HTML/fieldset-legend-removed-rebuilds-box.txt
new file mode 100644
index 00000000000..98186b27a00
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/fieldset-legend-removed-rebuilds-box.txt
@@ -0,0 +1,3 @@
+two legends: the tree matches a full rebuild: true
+the rendered legend removed, another takes its place: the tree matches a full rebuild: true
+no legend: the tree matches a full rebuild: true
diff --git a/Tests/LibWeb/Text/input/HTML/fieldset-legend-removed-rebuilds-box.html b/Tests/LibWeb/Text/input/HTML/fieldset-legend-removed-rebuilds-box.html
new file mode 100644
index 00000000000..6e9493df4c1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/fieldset-legend-removed-rebuilds-box.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<body>
+<fieldset id="fieldset"><legend>first</legend><legend>second</legend>content</fieldset>
+<script>
+ test(() => {
+ const report = label => println(`${label}: the tree matches a full rebuild: ${internals.compareLayoutTreeWithFullRebuild().matches}`);
+ report("two legends");
+ fieldset.firstElementChild.remove();
+ report("the rendered legend removed, another takes its place");
+ fieldset.firstElementChild.remove();
+ report("no legend");
+ });
+</script>