Skip to content

Truly independent web browser

LibWeb: Update :focus-within as a shadow root attaches to its host

Andreas Kling8025bb7a094a
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index 2fa6dba265b..84e1c9bfb46 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -2337,6 +2337,10 @@ WebIDL::ExceptionOr<void> Element::attach_a_shadow_root(ShadowRootMode mode, boo
// 12. Set shadow’s custom element registry to registry.
shadow->set_custom_element_registry(registry);
+ // NB: A shadow root with no slots yet takes the host's children out of the flat tree, and with them any chain of a
+ // state that propagates along it.
+ bool const holds_a_propagating_state_source = CSS::Invalidation::descendants_hold_a_propagating_state_source(*this);
+
// 13. Set element’s shadow root to shadow.
set_shadow_root(shadow);
@@ -2345,6 +2349,8 @@ WebIDL::ExceptionOr<void> Element::attach_a_shadow_root(ShadowRootMode mode, boo
document().note_element_assigned_slot_changed(child);
return IterationDecision::Continue;
});
+ if (holds_a_propagating_state_source)
+ CSS::Invalidation::invalidate_style_after_subtree_holding_a_state_source_left(*this, nullptr);
return {};
}
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/focus-within-of-a-host-as-its-shadow-root-attaches.txt b/Tests/LibWeb/Text/expected/css/style-engine/focus-within-of-a-host-as-its-shadow-root-attaches.txt
index 16fc5993b4c..51357bbc824 100644
--- a/Tests/LibWeb/Text/expected/css/style-engine/focus-within-of-a-host-as-its-shadow-root-attaches.txt
+++ b/Tests/LibWeb/Text/expected/css/style-engine/focus-within-of-a-host-as-its-shadow-root-attaches.txt
@@ -2,8 +2,8 @@ Focused: outer true rgb(1, 2, 3)
Focused: host true rgb(1, 2, 3)
Focused: child true rgb(1, 2, 3)
Focused: button true rgb(1, 2, 3)
-Attached: outer false rgb(1, 2, 3)
-Attached: host false rgb(1, 2, 3)
+Attached: outer false rgb(0, 0, 0)
+Attached: host false rgb(0, 0, 0)
Attached: child true rgb(1, 2, 3)
Attached: button true rgb(1, 2, 3)
Slotted: outer true rgb(1, 2, 3)