diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index bdd5a4b4f45..334c3c47360 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -41,6 +41,7 @@ use crate::dom::bindings::codegen::Bindings::NodeBinding::GetRootNodeOptions; use crate::dom::bindings::codegen::Bindings::NodeBinding::Node_Binding::NodeMethods; use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRoot_Binding::ShadowRootMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use crate::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId}; use crate::dom::bindings::codegen::UnionTypes::{ AddEventListenerOptionsOrBoolean, EventListenerOptionsOrBoolean, EventOrString, }; @@ -58,6 +59,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::htmlformelement::FormControlElementHelpers; use crate::dom::node::{Node, NodeTraits}; use crate::dom::shadowroot::ShadowRoot; +use crate::dom::text::Text; use crate::dom::virtualmethods::VirtualMethods; use crate::dom::window::Window; use crate::dom::workerglobalscope::WorkerGlobalScope; @@ -815,9 +817,30 @@ impl EventTarget { } if let Some(node) = self.downcast::() { - // FIXME: Handle slottables here - let parent = node.GetParentNode()?; - return Some(DomRoot::from_ref(parent.upcast::())); + // > A node’s get the parent algorithm, given an event, returns the node’s assigned slot, + // > if node is assigned; otherwise node’s parent. + let assigned_slot = match node.type_id() { + NodeTypeId::Element(_) => { + let element = node.downcast::().unwrap(); + element + .assigned_slot() + .map(|slot| DomRoot::from_ref(slot.upcast::())) + }, + NodeTypeId::CharacterData(CharacterDataTypeId::Text(_)) => { + let text = node.downcast::().unwrap(); + text.slottable_data() + .borrow() + .assigned_slot + .as_ref() + .map(|slot| DomRoot::from_ref(slot.upcast::())) + }, + _ => None, + }; + + return assigned_slot.or_else(|| { + node.GetParentNode() + .map(|parent| DomRoot::from_ref(parent.upcast::())) + }); } None diff --git a/tests/wpt/meta/shadow-dom/event-composed-path.html.ini b/tests/wpt/meta/shadow-dom/event-composed-path.html.ini index 13babc698bc..107a7c4310e 100644 --- a/tests/wpt/meta/shadow-dom/event-composed-path.html.ini +++ b/tests/wpt/meta/shadow-dom/event-composed-path.html.ini @@ -1,12 +1,6 @@ [event-composed-path.html] - [Event Path with a slot in an open Shadow Root.] - expected: FAIL - [Event Path with a slot in a closed Shadow Root.] expected: FAIL - [Event Path with slots in nested ShadowRoots: open > open.] - expected: FAIL - [Event Path with slots in nested ShadowRoots: closed > closed.] expected: FAIL