Implement ShadowRoot.clonable attribute (#34514)

* Implement ShadowRoot clonable attribute

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

* Update WPT expectations

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

* Update WPT expectations

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

* ./mach test-tidy fixes

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

* fix clippy warnings

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 2024-12-07 15:24:18 +01:00 committed by GitHub
parent 8ebb77ab76
commit 97e9841d47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 81 additions and 27 deletions

View file

@ -55,11 +55,19 @@ pub struct ShadowRoot {
/// <https://dom.spec.whatwg.org/#dom-shadowroot-mode>
mode: ShadowRootMode,
/// <https://dom.spec.whatwg.org/#dom-shadowroot-clonable>
clonable: bool,
}
impl ShadowRoot {
#[allow(crown::unrooted_must_root)]
fn new_inherited(host: &Element, document: &Document, mode: ShadowRootMode) -> ShadowRoot {
fn new_inherited(
host: &Element,
document: &Document,
mode: ShadowRootMode,
clonable: bool,
) -> ShadowRoot {
let document_fragment = DocumentFragment::new_inherited(document);
let node = document_fragment.upcast::<Node>();
node.set_flag(NodeFlags::IS_IN_SHADOW_TREE, true);
@ -77,12 +85,18 @@ impl ShadowRoot {
stylesheet_list: MutNullableDom::new(None),
window: Dom::from_ref(document.window()),
mode,
clonable,
}
}
pub fn new(host: &Element, document: &Document, mode: ShadowRootMode) -> DomRoot<ShadowRoot> {
pub fn new(
host: &Element,
document: &Document,
mode: ShadowRootMode,
clonable: bool,
) -> DomRoot<ShadowRoot> {
reflect_dom_object(
Box::new(ShadowRoot::new_inherited(host, document, mode)),
Box::new(ShadowRoot::new_inherited(host, document, mode, clonable)),
document.window(),
)
}
@ -238,6 +252,11 @@ impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot {
self.mode
}
/// <https://dom.spec.whatwg.org/#dom-shadowroot-clonable>
fn Clonable(&self) -> bool {
self.clonable
}
/// <https://dom.spec.whatwg.org/#dom-shadowroot-host>
fn Host(&self) -> DomRoot<Element> {
let host = self.host.get();