mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-28 18:40:29 +00:00
LibWeb: Add Element.getHTML() and ShadowRoot.getHTML()
This commit is contained in:
parent
0c47b3ff97
commit
fb9f3f10f3
Notes:
sideshowbarker
2024-07-17 07:14:09 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/fb9f3f10f3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/278 Reviewed-by: https://github.com/mattco98 Reviewed-by: https://github.com/nico
7 changed files with 32 additions and 2 deletions
|
@ -80,6 +80,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,
|
||||||
|
|
|
@ -2583,4 +2583,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