ladybird/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

48 lines
1.2 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOMParsing/InnerHTML.h>
#include <LibWeb/Layout/BlockContainer.h>
namespace Web::DOM {
ShadowRoot::ShadowRoot(Document& document, Element& host)
: DocumentFragment(document)
{
set_host(&host);
}
// https://dom.spec.whatwg.org/#ref-for-get-the-parent%E2%91%A6
EventTarget* ShadowRoot::get_parent(Event const& event)
{
if (!event.composed()) {
auto& events_first_invocation_target = verify_cast<Node>(*event.path().first().invocation_target);
if (&events_first_invocation_target.root() == this)
return nullptr;
}
return host();
}
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
WebIDL::ExceptionOr<DeprecatedString> ShadowRoot::inner_html() const
{
return serialize_fragment(DOMParsing::RequireWellFormed::Yes);
}
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(DeprecatedString const& markup)
{
TRY(DOMParsing::inner_html_setter(*this, markup));
set_needs_style_update(true);
return {};
}
}