Truly independent web browser
LibWeb: Restyle an element assigned out of a hidden slot
sideshowbarkerc51cc8acd41c
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/allocation_tests.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/allocation_tests.rsindex 1b9ccc5c4a1..9cf58a38dbf 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/allocation_tests.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/allocation_tests.rs@@ -203,6 +203,13 @@ fn a_class_flip_of_a_rule_that_loses_computes_nothing() {);add_class(&mut engine, nodes[1], "winner");start_live(&mut engine, nodes[0]);+ // The host holds the styles the engine installed as it took the document. A flip that leaves the element's record+ // as it was then installs nothing.+ let mut installation = engine.take_installation();+ installation.note_held_by_the_host(&mut engine.retained);+ for record in installation.pinned_records {+ engine.unpin_layout_style_record(record);+ }let (root, element) = (nodes[0], nodes[1]);let mut round = || {add_class(&mut engine, element, "loser");diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rsindex 8fc9a2fdf21..17b1b823b53 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs@@ -2311,14 +2311,14 @@ impl Live {state.live_counters.is_tracing(),);// NB: A record holding what the one it replaces does gives way to it where that one is- // installed, which it is not for an element that arrived in the place of another.- self.uninstalled.extend(- statistics- .styled- .iter()- .copied()- .filter(|&node| state.computed_group_sets.assigned_style_record(node).is_none()),- );+ // installed, which it is not for an element that arrived in the place of another. Nor+ // is it for one whose style the host cleared below an undisplayed element, and which a+ // move in the flat tree, such as to another slot, displays again with that record.+ self.uninstalled+ .extend(statistics.styled.iter().copied().filter(|&node| {+ state.computed_group_sets.assigned_style_record(node).is_none()+ || !state.held_style_records.contains(node)+ }));// NB: An element moved out from below an undisplayed one may hold what it held before it moved there.if !self.installed_as_undisplayed.is_empty() {for node in &statistics.styled {diff --git a/Tests/LibWeb/Text/expected/css/style-engine/slotted-subtree-assigned-out-of-a-hidden-slot-gets-style.txt b/Tests/LibWeb/Text/expected/css/style-engine/slotted-subtree-assigned-out-of-a-hidden-slot-gets-style.txtnew file mode 100644index 00000000000..61188e6beb5--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/style-engine/slotted-subtree-assigned-out-of-a-hidden-slot-gets-style.txt@@ -0,0 +1,3 @@+slot attribute: offsetParent: body, display: block+slot name: offsetParent: body, display: block+manual assignment: offsetParent: body, display: blockdiff --git a/Tests/LibWeb/Text/input/css/style-engine/slotted-subtree-assigned-out-of-a-hidden-slot-gets-style.html b/Tests/LibWeb/Text/input/css/style-engine/slotted-subtree-assigned-out-of-a-hidden-slot-gets-style.htmlnew file mode 100644index 00000000000..2f6b1134c39--- /dev/null+++ b/Tests/LibWeb/Text/input/css/style-engine/slotted-subtree-assigned-out-of-a-hidden-slot-gets-style.html@@ -0,0 +1,41 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script>+ // An element assigned to a slot in a hidden subtree holds no style, and gets it back once it's assigned to a+ // displayed slot, though the style it gets is the one it had before.+ async function check(name, slotAssignment, assignToShownSlot) {+ const host = document.createElement("x-host");+ host.innerHTML = `<div slot="a"><div>x</div></div>`;+ document.body.append(host);+ const slotted = host.firstElementChild;+ const inner = slotted.firstElementChild;+ const root = host.attachShadow({ mode: "open", slotAssignment });+ root.innerHTML = `<div><slot name="a"></slot></div><slot name="b"></slot>`;+ const wrapper = root.firstElementChild;+ const [hiddenSlot, shownSlot] = root.querySelectorAll("slot");+ if (slotAssignment === "manual")+ hiddenSlot.assign(slotted);+ void inner.offsetTop;++ wrapper.style.display = "none";+ void host.offsetHeight;+ assignToShownSlot(slotted, hiddenSlot, shownSlot);++ println(`${name}: offsetParent: ${inner.offsetParent.localName}, display: ${getComputedStyle(slotted).display}`);+ host.remove();+ }++ asyncTest(async done => {+ await check("slot attribute", "named", slotted => {+ slotted.slot = "b";+ });+ await check("slot name", "named", (slotted, hiddenSlot, shownSlot) => {+ hiddenSlot.name = "c";+ shownSlot.name = "a";+ });+ await check("manual assignment", "manual", (slotted, hiddenSlot, shownSlot) => {+ shownSlot.assign(slotted);+ });+ done();+ });+</script>