2020-08-01 03:07:00 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2023-09-05 14:49:30 -04:00
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
2020-08-01 03:07:00 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:07:00 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-09-05 15:05:46 -04:00
|
|
|
#include <AK/Variant.h>
|
|
|
|
#include <AK/Vector.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Root.h>
|
2023-09-05 14:49:30 -04:00
|
|
|
#include <LibWeb/DOM/Slot.h>
|
2023-09-05 15:05:46 -04:00
|
|
|
#include <LibWeb/DOM/Slottable.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2023-09-05 15:05:46 -04:00
|
|
|
struct AssignedNodesOptions {
|
|
|
|
bool flatten { false };
|
|
|
|
};
|
|
|
|
|
2023-09-05 14:49:30 -04:00
|
|
|
class HTMLSlotElement final
|
|
|
|
: public HTMLElement
|
|
|
|
, public DOM::Slot {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLSlotElement, HTMLElement);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLSlotElement);
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2020-08-01 03:07:00 +01:00
|
|
|
public:
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual ~HTMLSlotElement() override;
|
2020-08-01 03:07:00 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Root<DOM::Node>> assigned_nodes(AssignedNodesOptions options = {}) const;
|
|
|
|
Vector<GC::Root<DOM::Element>> assigned_elements(AssignedNodesOptions options = {}) const;
|
2023-09-05 15:05:46 -04:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
using SlottableHandle = Variant<GC::Root<DOM::Element>, GC::Root<DOM::Text>>;
|
2023-09-05 15:05:46 -04:00
|
|
|
void assign(Vector<SlottableHandle> nodes);
|
|
|
|
|
|
|
|
ReadonlySpan<DOM::Slottable> manually_assigned_nodes() const { return m_manually_assigned_nodes; }
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
private:
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLSlotElement(DOM::Document&, DOM::QualifiedName);
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-09-23 13:03:59 +02:00
|
|
|
virtual bool is_html_slot_element() const override { return true; }
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-09-05 14:49:30 -04:00
|
|
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
2023-09-05 15:05:46 -04:00
|
|
|
|
2024-11-14 08:14:16 -05:00
|
|
|
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
2023-11-19 21:28:18 +01:00
|
|
|
|
2023-09-05 15:05:46 -04:00
|
|
|
// https://html.spec.whatwg.org/multipage/scripting.html#manually-assigned-nodes
|
|
|
|
Vector<DOM::Slottable> m_manually_assigned_nodes;
|
2020-08-01 03:07:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2023-09-23 13:03:59 +02:00
|
|
|
|
|
|
|
namespace Web::DOM {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline bool Node::fast_is<HTML::HTMLSlotElement>() const { return is_html_slot_element(); }
|
|
|
|
|
|
|
|
}
|