Propagate events from slottables to their assigned slot instead of their parent (#35177)

* Propagate events from slottables to their assigned slot instead of their parent

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-01-27 16:48:24 +01:00 committed by GitHub
parent 6b04bc6263
commit 177b5b2cef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 9 deletions

View file

@ -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::<Node>() {
// FIXME: Handle slottables here
let parent = node.GetParentNode()?;
return Some(DomRoot::from_ref(parent.upcast::<EventTarget>()));
// > A nodes get the parent algorithm, given an event, returns the nodes assigned slot,
// > if node is assigned; otherwise nodes parent.
let assigned_slot = match node.type_id() {
NodeTypeId::Element(_) => {
let element = node.downcast::<Element>().unwrap();
element
.assigned_slot()
.map(|slot| DomRoot::from_ref(slot.upcast::<EventTarget>()))
},
NodeTypeId::CharacterData(CharacterDataTypeId::Text(_)) => {
let text = node.downcast::<Text>().unwrap();
text.slottable_data()
.borrow()
.assigned_slot
.as_ref()
.map(|slot| DomRoot::from_ref(slot.upcast::<EventTarget>()))
},
_ => None,
};
return assigned_slot.or_else(|| {
node.GetParentNode()
.map(|parent| DomRoot::from_ref(parent.upcast::<EventTarget>()))
});
}
None

View file

@ -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