/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020, the SerenityOS developers. |
3 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <AK/Variant.h> |
11 | | #include <AK/Vector.h> |
12 | | #include <LibJS/Heap/Handle.h> |
13 | | #include <LibWeb/DOM/Slot.h> |
14 | | #include <LibWeb/DOM/Slottable.h> |
15 | | #include <LibWeb/HTML/HTMLElement.h> |
16 | | |
17 | | namespace Web::HTML { |
18 | | |
19 | | struct AssignedNodesOptions { |
20 | | bool flatten { false }; |
21 | | }; |
22 | | |
23 | | class HTMLSlotElement final |
24 | | : public HTMLElement |
25 | | , public DOM::Slot { |
26 | | WEB_PLATFORM_OBJECT(HTMLSlotElement, HTMLElement); |
27 | | JS_DECLARE_ALLOCATOR(HTMLSlotElement); |
28 | | |
29 | | public: |
30 | | virtual ~HTMLSlotElement() override; |
31 | | |
32 | | Vector<JS::Handle<DOM::Node>> assigned_nodes(AssignedNodesOptions options = {}) const; |
33 | | Vector<JS::Handle<DOM::Element>> assigned_elements(AssignedNodesOptions options = {}) const; |
34 | | |
35 | | using SlottableHandle = Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Text>>; |
36 | | void assign(Vector<SlottableHandle> nodes); |
37 | | |
38 | 0 | ReadonlySpan<DOM::Slottable> manually_assigned_nodes() const { return m_manually_assigned_nodes; } |
39 | | |
40 | | private: |
41 | | HTMLSlotElement(DOM::Document&, DOM::QualifiedName); |
42 | | |
43 | 0 | virtual bool is_html_slot_element() const override { return true; } |
44 | | |
45 | | virtual void initialize(JS::Realm&) override; |
46 | | virtual void visit_edges(JS::Cell::Visitor&) override; |
47 | | |
48 | | virtual void attribute_change_steps(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override; |
49 | | |
50 | | // https://html.spec.whatwg.org/multipage/scripting.html#manually-assigned-nodes |
51 | | Vector<DOM::Slottable> m_manually_assigned_nodes; |
52 | | }; |
53 | | |
54 | | } |
55 | | |
56 | | namespace Web::DOM { |
57 | | |
58 | | template<> |
59 | 0 | inline bool Node::fast_is<HTML::HTMLSlotElement>() const { return is_html_slot_element(); } |
60 | | |
61 | | } |