/* * Copyright (c) 2020, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include namespace Web::DOM { JS_DEFINE_ALLOCATOR(ShadowRoot); ShadowRoot::ShadowRoot(Document& document, Element& host, Bindings::ShadowRootMode mode) : DocumentFragment(document) , m_mode(mode) { document.register_shadow_root({}, *this); set_host(&host); } void ShadowRoot::finalize() { Base::finalize(); document().unregister_shadow_root({}, *this); } void ShadowRoot::initialize(JS::Realm& realm) { Base::initialize(realm); WEB_SET_PROTOTYPE_FOR_INTERFACE(ShadowRoot); } // https://dom.spec.whatwg.org/#dom-shadowroot-onslotchange void ShadowRoot::set_onslotchange(WebIDL::CallbackType* event_handler) { set_event_handler_attribute(HTML::EventNames::slotchange, event_handler); } // https://dom.spec.whatwg.org/#dom-shadowroot-onslotchange WebIDL::CallbackType* ShadowRoot::onslotchange() { return event_handler_attribute(HTML::EventNames::slotchange); } // 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(*event.path().first().invocation_target); if (&events_first_invocation_target.root() == this) return nullptr; } return host(); } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml WebIDL::ExceptionOr ShadowRoot::inner_html() const { return serialize_fragment(DOMParsing::RequireWellFormed::Yes); } // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml WebIDL::ExceptionOr ShadowRoot::set_inner_html(StringView value) { // FIXME: 1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm with TrustedHTML, this's relevant global object, the given value, "ShadowRoot innerHTML", and "script". // 2. Let context be this's host. auto context = this->host(); // 3. Let fragment be the result of invoking the fragment parsing algorithm steps with context and compliantString. FIXME: Use compliantString instead of markup. auto fragment = TRY(verify_cast(*context).parse_fragment(value)); // 4. Replace all with fragment within this. this->replace_all(fragment); // NOTE: We don't invalidate style & layout for