2020-11-21 18:32:39 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-21 18:32:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-01-28 20:31:56 +01:00
|
|
|
#include <LibWeb/Bindings/ShadowRootPrototype.h>
|
2020-11-21 18:32:39 +00:00
|
|
|
#include <LibWeb/DOM/DocumentFragment.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
|
|
class ShadowRoot final : public DocumentFragment {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(ShadowRoot, DocumentFragment);
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DECLARE_ALLOCATOR(ShadowRoot);
|
2020-11-21 18:32:39 +00:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2023-01-28 20:31:56 +01:00
|
|
|
Bindings::ShadowRootMode mode() const { return m_mode; }
|
2020-11-21 18:32:39 +00:00
|
|
|
|
2023-09-01 07:25:40 -04:00
|
|
|
Bindings::SlotAssignmentMode slot_assignment() const { return m_slot_assignment; }
|
|
|
|
|
void set_slot_assignment(Bindings::SlotAssignmentMode slot_assignment) { m_slot_assignment = slot_assignment; }
|
|
|
|
|
|
2020-11-21 18:32:39 +00:00
|
|
|
bool delegates_focus() const { return m_delegates_focus; }
|
|
|
|
|
void set_delegates_focus(bool delegates_focus) { m_delegates_focus = delegates_focus; }
|
|
|
|
|
|
|
|
|
|
bool available_to_element_internals() const { return m_available_to_element_internals; }
|
|
|
|
|
void set_available_to_element_internals(bool available_to_element_internals) { m_available_to_element_internals = available_to_element_internals; }
|
|
|
|
|
|
|
|
|
|
// ^EventTarget
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual EventTarget* get_parent(Event const&) override;
|
2020-11-21 18:32:39 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
WebIDL::ExceptionOr<DeprecatedString> inner_html() const;
|
2023-09-06 14:52:53 +12:00
|
|
|
WebIDL::ExceptionOr<void> set_inner_html(StringView);
|
2021-09-13 22:42:57 +01:00
|
|
|
|
2020-11-21 18:32:39 +00:00
|
|
|
private:
|
2023-01-28 20:36:58 +01:00
|
|
|
ShadowRoot(Document&, Element& host, Bindings::ShadowRootMode);
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2021-02-10 18:23:52 +01:00
|
|
|
// ^Node
|
2023-09-17 10:51:43 +12:00
|
|
|
virtual FlyString node_name() const override { return "#shadow-root"_fly_string; }
|
2022-03-13 17:21:27 +01:00
|
|
|
virtual bool is_shadow_root() const final { return true; }
|
2021-02-10 18:23:52 +01:00
|
|
|
|
2023-09-01 07:25:40 -04:00
|
|
|
// NOTE: The specification doesn't seem to specify a default value for mode. Assuming closed for now.
|
2023-01-28 20:31:56 +01:00
|
|
|
Bindings::ShadowRootMode m_mode { Bindings::ShadowRootMode::Closed };
|
2023-09-01 07:25:40 -04:00
|
|
|
Bindings::SlotAssignmentMode m_slot_assignment { Bindings::SlotAssignmentMode::Named };
|
2020-11-21 18:32:39 +00:00
|
|
|
bool m_delegates_focus { false };
|
|
|
|
|
bool m_available_to_element_internals { false };
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-13 17:21:27 +01:00
|
|
|
template<>
|
2023-11-02 15:21:30 +01:00
|
|
|
inline bool Node::fast_is<ShadowRoot>() const { return node_type() == to_underlying(NodeType::DOCUMENT_FRAGMENT_NODE) && is_shadow_root(); }
|
2022-03-13 17:21:27 +01:00
|
|
|
|
2022-07-12 23:13:57 +02:00
|
|
|
template<typename Callback>
|
2023-03-29 23:46:18 +01:00
|
|
|
inline IterationDecision Node::for_each_shadow_including_inclusive_descendant(Callback callback)
|
2022-07-12 23:13:57 +02:00
|
|
|
{
|
|
|
|
|
if (callback(*this) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
|
|
|
|
if (child->is_element()) {
|
2023-01-28 20:22:52 +01:00
|
|
|
if (JS::GCPtr<ShadowRoot> shadow_root = static_cast<Element*>(child)->shadow_root_internal()) {
|
2023-03-29 23:46:18 +01:00
|
|
|
if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (child->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break)
|
|
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Callback>
|
|
|
|
|
inline IterationDecision Node::for_each_shadow_including_descendant(Callback callback)
|
|
|
|
|
{
|
|
|
|
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
|
|
|
|
if (child->is_element()) {
|
|
|
|
|
if (JS::GCPtr<ShadowRoot> shadow_root = static_cast<Element*>(child)->shadow_root()) {
|
|
|
|
|
if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break)
|
2022-07-12 23:13:57 +02:00
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-29 23:46:18 +01:00
|
|
|
if (child->for_each_shadow_including_inclusive_descendant(callback) == IterationDecision::Break)
|
2022-07-12 23:13:57 +02:00
|
|
|
return IterationDecision::Break;
|
|
|
|
|
}
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-21 18:32:39 +00:00
|
|
|
}
|