diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 48cae944da..e45f8f6d8d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -79,6 +79,7 @@ static bool is_platform_object(Type const& type) "Request"sv, "Selection"sv, "SVGTransform"sv, + "ShadowRoot"sv, "Table"sv, "Text"sv, "TextMetrics"sv, diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index b46fe5b828..f0ae57fd4a 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -2591,4 +2591,16 @@ CSS::StyleSheetList& Element::document_or_shadow_root_style_sheets() return document().style_sheets(); } +// https://html.spec.whatwg.org/#dom-element-gethtml +WebIDL::ExceptionOr Element::get_html(GetHTMLOptions const& options) const +{ + // Element's getHTML(options) method steps are to return the result + // of HTML fragment serialization algorithm with this, + // options["serializableShadowRoots"], and options["shadowRoots"]. + return HTML::HTMLParser::serialize_html_fragment( + *this, + options.serializable_shadow_roots ? HTML::HTMLParser::SerializableShadowRoots::Yes : HTML::HTMLParser::SerializableShadowRoots::No, + options.shadow_roots); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 75e93c703f..2a5e612a40 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -187,6 +187,8 @@ public: WebIDL::ExceptionOr inner_html() const; WebIDL::ExceptionOr set_inner_html(StringView); + WebIDL::ExceptionOr get_html(GetHTMLOptions const&) const; + WebIDL::ExceptionOr insert_adjacent_html(String const& position, String const&); WebIDL::ExceptionOr outer_html() const; diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index e122ee1b08..3c92805b98 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -95,7 +95,7 @@ interface Element : Node { // https://html.spec.whatwg.org/#dom-parsing-and-serialization [FIXME, CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html); - [FIXME] DOMString getHTML(optional GetHTMLOptions options = {}); + DOMString getHTML(optional GetHTMLOptions options = {}); // FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML; [CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML; diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp index 8fb538280c..3d75a909b7 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace Web::DOM { @@ -75,6 +76,18 @@ WebIDL::ExceptionOr ShadowRoot::set_inner_html(StringView markup) return {}; } +// https://html.spec.whatwg.org/#dom-element-gethtml +WebIDL::ExceptionOr ShadowRoot::get_html(GetHTMLOptions const& options) const +{ + // ShadowRoot's getHTML(options) method steps are to return the result + // of HTML fragment serialization algorithm with this, + // options["serializableShadowRoots"], and options["shadowRoots"]. + return HTML::HTMLParser::serialize_html_fragment( + *this, + options.serializable_shadow_roots ? HTML::HTMLParser::SerializableShadowRoots::Yes : HTML::HTMLParser::SerializableShadowRoots::No, + options.shadow_roots); +} + CSS::StyleSheetList& ShadowRoot::style_sheets() { if (!m_style_sheets) diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h index e7a86a7116..ca01e56cdf 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h @@ -46,6 +46,8 @@ public: WebIDL::ExceptionOr inner_html() const; WebIDL::ExceptionOr set_inner_html(StringView); + WebIDL::ExceptionOr get_html(GetHTMLOptions const&) const; + CSS::StyleSheetList& style_sheets(); CSS::StyleSheetList const& style_sheets() const; diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.idl b/Userland/Libraries/LibWeb/DOM/ShadowRoot.idl index 1b0d373fb1..12fde61da1 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.idl +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.idl @@ -16,7 +16,7 @@ interface ShadowRoot : DocumentFragment { // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization [FIXME, CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html); - [FIXME] DOMString getHTML(optional GetHTMLOptions options = {}); + DOMString getHTML(optional GetHTMLOptions options = {}); // FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML; [CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML;