Implement declarative shadow dom (#34964)

* Implement declarative shadow dom

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Set allowDeclarativeShadowRoots false for innerHTML

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Enable allowDeclarativeShadowRoots for Document

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Expose HTMLTemplateElement to js

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Implemenet setHTMLUnsafe and add more test cases

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Declarative shadow dom: minor updates and expected test result update

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Shadow-dom: add more test cases

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Update comments according to the spec

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

* Bump html5ever version

Signed-off-by: batu_hoang <longvatrong111@gmail.com>

---------

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-03-17 17:41:34 +08:00 committed by GitHub
parent f483a3d34b
commit 28c8c1df0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 360 additions and 1965 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use html5ever::{LocalName, Prefix, namespace_url};
use js::rust::HandleObject;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
@ -11,6 +11,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTem
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::documentfragment::DocumentFragment;
use crate::dom::htmlelement::HTMLElement;
@ -58,9 +59,44 @@ impl HTMLTemplateElement {
n.upcast::<Node>().set_weird_parser_insertion_mode();
n
}
pub(crate) fn set_contents(&self, document_fragment: Option<&DocumentFragment>) {
self.contents.set(document_fragment);
}
}
#[allow(unused_doc_comments)]
impl HTMLTemplateElementMethods<crate::DomTypeHolder> for HTMLTemplateElement {
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootmode>
make_enumerated_getter!(
ShadowRootMode,
"shadowrootmode",
"open" | "closed",
missing => "",
invalid => ""
);
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootmode>
make_atomic_setter!(SetShadowRootMode, "shadowrootmode");
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootdelegatesfocus>
make_bool_getter!(ShadowRootDelegatesFocus, "shadowrootdelegatesfocus");
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootdelegatesfocus>
make_bool_setter!(SetShadowRootDelegatesFocus, "shadowrootdelegatesfocus");
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootclonable>
make_bool_getter!(ShadowRootClonable, "shadowrootclonable");
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootclonable>
make_bool_setter!(SetShadowRootClonable, "shadowrootclonable");
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootserializable>
make_bool_getter!(ShadowRootSerializable, "shadowrootserializable");
/// <https://html.spec.whatwg.org/multipage/#dom-template-shadowrootserializable>
make_bool_setter!(SetShadowRootSerializable, "shadowrootserializable");
/// <https://html.spec.whatwg.org/multipage/#dom-template-content>
fn Content(&self, can_gc: CanGc) -> DomRoot<DocumentFragment> {
self.contents.or_init(|| {