mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-30 05:05:10 +00:00
LibWeb: Add Element.getHTML() and ShadowRoot.getHTML()
(cherry picked from commit fb9f3f10f3090cc2822d2c681bd7350dda17830e)
This commit is contained in:
parent
e4feb43e86
commit
83d0599d1c
|
@ -79,6 +79,7 @@ static bool is_platform_object(Type const& type)
|
||||||
"Request"sv,
|
"Request"sv,
|
||||||
"Selection"sv,
|
"Selection"sv,
|
||||||
"SVGTransform"sv,
|
"SVGTransform"sv,
|
||||||
|
"ShadowRoot"sv,
|
||||||
"Table"sv,
|
"Table"sv,
|
||||||
"Text"sv,
|
"Text"sv,
|
||||||
"TextMetrics"sv,
|
"TextMetrics"sv,
|
||||||
|
|
|
@ -2591,4 +2591,16 @@ CSS::StyleSheetList& Element::document_or_shadow_root_style_sheets()
|
||||||
return document().style_sheets();
|
return document().style_sheets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-element-gethtml
|
||||||
|
WebIDL::ExceptionOr<String> 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,8 @@ public:
|
||||||
WebIDL::ExceptionOr<String> inner_html() const;
|
WebIDL::ExceptionOr<String> inner_html() const;
|
||||||
WebIDL::ExceptionOr<void> set_inner_html(StringView);
|
WebIDL::ExceptionOr<void> set_inner_html(StringView);
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<String> get_html(GetHTMLOptions const&) const;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> insert_adjacent_html(String const& position, String const&);
|
WebIDL::ExceptionOr<void> insert_adjacent_html(String const& position, String const&);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> outer_html() const;
|
WebIDL::ExceptionOr<String> outer_html() const;
|
||||||
|
|
|
@ -95,7 +95,7 @@ interface Element : Node {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/#dom-parsing-and-serialization
|
// https://html.spec.whatwg.org/#dom-parsing-and-serialization
|
||||||
[FIXME, CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html);
|
[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;
|
// FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
|
||||||
[CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML;
|
[CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibWeb/DOM/Event.h>
|
#include <LibWeb/DOM/Event.h>
|
||||||
#include <LibWeb/DOM/ShadowRoot.h>
|
#include <LibWeb/DOM/ShadowRoot.h>
|
||||||
#include <LibWeb/DOMParsing/InnerHTML.h>
|
#include <LibWeb/DOMParsing/InnerHTML.h>
|
||||||
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||||
#include <LibWeb/Layout/BlockContainer.h>
|
#include <LibWeb/Layout/BlockContainer.h>
|
||||||
|
|
||||||
namespace Web::DOM {
|
namespace Web::DOM {
|
||||||
|
@ -75,6 +76,18 @@ WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(StringView markup)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/#dom-element-gethtml
|
||||||
|
WebIDL::ExceptionOr<String> 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()
|
CSS::StyleSheetList& ShadowRoot::style_sheets()
|
||||||
{
|
{
|
||||||
if (!m_style_sheets)
|
if (!m_style_sheets)
|
||||||
|
|
|
@ -46,6 +46,8 @@ public:
|
||||||
WebIDL::ExceptionOr<String> inner_html() const;
|
WebIDL::ExceptionOr<String> inner_html() const;
|
||||||
WebIDL::ExceptionOr<void> set_inner_html(StringView);
|
WebIDL::ExceptionOr<void> set_inner_html(StringView);
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<String> get_html(GetHTMLOptions const&) const;
|
||||||
|
|
||||||
CSS::StyleSheetList& style_sheets();
|
CSS::StyleSheetList& style_sheets();
|
||||||
CSS::StyleSheetList const& style_sheets() const;
|
CSS::StyleSheetList const& style_sheets() const;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ interface ShadowRoot : DocumentFragment {
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
|
||||||
|
|
||||||
[FIXME, CEReactions] undefined setHTMLUnsafe((TrustedHTML or DOMString) html);
|
[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;
|
// FIXME: [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
|
||||||
[CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML;
|
[CEReactions, LegacyNullToEmptyString] attribute DOMString innerHTML;
|
||||||
|
|
Loading…
Reference in a new issue