Skip to content

Truly independent web browser

LibWeb: Count a hidden slot among the ancestors of its slottables

Andreas Kling59b7354aa722
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index 734981f24b7..bbef0e6562b 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -4965,12 +4965,16 @@ bool Node::has_inclusive_ancestor_with_display_none_ignoring_animations() const
{
// NB: Only each ancestor's display matters here, so read it out of the record's box group
// payload instead of materializing a full style record view.
- for (auto const* ancestor = this; ancestor; ancestor = ancestor->parent_or_shadow_host()) {
+ // NB: A slottable is below the slot it is assigned to, which is not among its ancestors in the DOM.
+ for (auto const* ancestor = this; ancestor;) {
auto const* ancestor_element = as_if<Element>(ancestor);
- if (!ancestor_element)
+ if (!ancestor_element) {
+ ancestor = ancestor->parent_or_shadow_host();
continue;
+ }
if (ancestor_element->installed_style().display_is_none())
return true;
+ ancestor = ancestor_element->element_to_inherit_style_from({}).ptr();
}
return false;
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
index a777622f570..1e576527538 100644
--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
@@ -637,10 +637,15 @@ impl RetainedState {
/// the record stood before any animation was layered on it: the host's
/// `has_inclusive_ancestor_with_display_none_ignoring_animations()`. A node that holds no
/// record, a shadow root or one style has not reached yet, is passed over, as the host passes
- /// over a node that is not an element.
+ /// over a node that is not an element. A slottable is below the slot it is assigned to.
#[must_use]
pub(crate) fn has_inclusive_ancestor_with_display_none_ignoring_animations(&self, node: StyleNodeID) -> bool {
- std::iter::successors(Some(node), |&current| self.projection.parent_or_shadow_host(current)).any(|ancestor| {
+ std::iter::successors(Some(node), |&current| {
+ self.projection
+ .assigned_slot_of(current)
+ .or_else(|| self.projection.parent_or_shadow_host(current))
+ })
+ .any(|ancestor| {
self.computed_group_sets
.assigned_style_record(ancestor)
.and_then(|record| self.computed_group_sets.style_record_view(record.raw()))
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/read-of-a-slottable-below-a-hidden-slot.txt b/Tests/LibWeb/Text/expected/css/style-engine/read-of-a-slottable-below-a-hidden-slot.txt
new file mode 100644
index 00000000000..1836d5d9f44
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-engine/read-of-a-slottable-below-a-hidden-slot.txt
@@ -0,0 +1,12 @@
+shown slot into the root, assigned: --inherited "1", color rgb(1, 2, 3)
+shown slot into the root, moved away: --inherited "", color rgb(0, 0, 0)
+shown slot into the root, moved back: --inherited "1", color rgb(1, 2, 3)
+shown slot into a child, assigned: --inherited "1", color rgb(1, 2, 3)
+shown slot into a child, moved away: --inherited "", color rgb(0, 0, 0)
+shown slot into a child, moved back: --inherited "1", color rgb(1, 2, 3)
+hidden slot into the root, assigned: --inherited "1", color rgb(1, 2, 3)
+hidden slot into the root, moved away: --inherited "", color rgb(0, 0, 0)
+hidden slot into the root, moved back: --inherited "1", color rgb(1, 2, 3)
+hidden slot into a child, assigned: --inherited "1", color rgb(1, 2, 3)
+hidden slot into a child, moved away: --inherited "", color rgb(0, 0, 0)
+hidden slot into a child, moved back: --inherited "1", color rgb(1, 2, 3)
diff --git a/Tests/LibWeb/Text/input/css/style-engine/read-of-a-slottable-below-a-hidden-slot.html b/Tests/LibWeb/Text/input/css/style-engine/read-of-a-slottable-below-a-hidden-slot.html
new file mode 100644
index 00000000000..53be087c086
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-engine/read-of-a-slottable-below-a-hidden-slot.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script>
+ // A slottable inherits from its slot. A slot moved back into its shadow tree takes the slottable in again, and where
+ // the slot is hidden no style update reaches the slottable, so a read has to answer for it. The slot is not among
+ // the slottable's ancestors in the DOM.
+ asyncTest(async done => {
+ const frames = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ for (const [hidden, into] of [[false, "the root"], [false, "a child"], [true, "the root"], [true, "a child"]]) {
+ const host = document.createElement("div");
+ const slottable = document.createElement("div");
+ host.append(slottable);
+ document.body.append(host);
+ const root = host.attachShadow({ mode: "open" });
+ const slot = document.createElement("slot");
+ const style = document.createElement("style");
+ const child = document.createElement("div");
+ style.textContent = "* { --inherited: 1; color: rgb(1, 2, 3); }";
+ root.append(style, slot, child);
+ const report = label => {
+ const computed = getComputedStyle(slottable);
+ println(`${hidden ? "hidden" : "shown"} slot into ${into}, ${label}: --inherited "${computed.getPropertyValue("--inherited")}", color ${computed.color}`);
+ };
+
+ await frames();
+ report("assigned");
+ slot.hidden = hidden;
+ await frames();
+ slottable.before(slot);
+ internals.updateStyle();
+ await frames();
+ report("moved away");
+ (into === "the root" ? root : child).append(slot);
+ await frames();
+ report("moved back");
+ host.remove();
+ }
+ done();
+ });
+</script>