2020-11-21 21:32:39 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-21 21:32:39 +03:00
|
|
|
*/
|
|
|
|
|
2021-09-14 00:42:57 +03:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-11-21 21:32:39 +03:00
|
|
|
#include <LibWeb/DOM/Event.h>
|
|
|
|
#include <LibWeb/DOM/ShadowRoot.h>
|
2021-09-14 00:42:57 +03:00
|
|
|
#include <LibWeb/DOMParsing/InnerHTML.h>
|
2021-10-06 21:02:41 +03:00
|
|
|
#include <LibWeb/Layout/BlockContainer.h>
|
2020-11-21 21:32:39 +03:00
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
2023-01-28 22:36:58 +03:00
|
|
|
ShadowRoot::ShadowRoot(Document& document, Element& host, Bindings::ShadowRootMode mode)
|
2020-11-21 21:32:39 +03:00
|
|
|
: DocumentFragment(document)
|
2023-01-28 22:36:58 +03:00
|
|
|
, m_mode(mode)
|
2020-11-21 21:32:39 +03:00
|
|
|
{
|
2022-03-16 02:26:40 +03:00
|
|
|
set_host(&host);
|
2020-11-21 21:32:39 +03:00
|
|
|
}
|
|
|
|
|
2023-01-28 22:26:01 +03:00
|
|
|
JS::ThrowCompletionOr<void> ShadowRoot::initialize(JS::Realm& realm)
|
|
|
|
{
|
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::ShadowRootPrototype>(realm, "ShadowRoot"));
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-09-02 21:27:42 +03:00
|
|
|
// https://dom.spec.whatwg.org/#ref-for-get-the-parent%E2%91%A6
|
2022-04-01 20:58:27 +03:00
|
|
|
EventTarget* ShadowRoot::get_parent(Event const& event)
|
2020-11-21 21:32:39 +03:00
|
|
|
{
|
|
|
|
if (!event.composed()) {
|
2021-06-24 20:53:42 +03:00
|
|
|
auto& events_first_invocation_target = verify_cast<Node>(*event.path().first().invocation_target);
|
2021-09-02 21:27:42 +03:00
|
|
|
if (&events_first_invocation_target.root() == this)
|
2020-11-21 21:32:39 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return host();
|
|
|
|
}
|
|
|
|
|
2021-09-14 00:42:57 +03:00
|
|
|
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
|
2022-12-04 21:02:33 +03:00
|
|
|
WebIDL::ExceptionOr<DeprecatedString> ShadowRoot::inner_html() const
|
2021-09-14 00:42:57 +03:00
|
|
|
{
|
2022-11-03 02:14:27 +03:00
|
|
|
return serialize_fragment(DOMParsing::RequireWellFormed::Yes);
|
2021-09-14 00:42:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
|
2022-12-04 21:02:33 +03:00
|
|
|
WebIDL::ExceptionOr<void> ShadowRoot::set_inner_html(DeprecatedString const& markup)
|
2021-09-14 00:42:57 +03:00
|
|
|
{
|
2022-03-22 15:40:10 +03:00
|
|
|
TRY(DOMParsing::inner_html_setter(*this, markup));
|
2021-09-14 00:42:57 +03:00
|
|
|
|
|
|
|
set_needs_style_update(true);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-11-21 21:32:39 +03:00
|
|
|
}
|