/src/serenity/Userland/Libraries/LibWeb/DOM/Slottable.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/String.h> |
10 | | #include <AK/Variant.h> |
11 | | #include <LibJS/Heap/Cell.h> |
12 | | #include <LibJS/Heap/GCPtr.h> |
13 | | #include <LibWeb/Forward.h> |
14 | | |
15 | | namespace Web::DOM { |
16 | | |
17 | | // https://dom.spec.whatwg.org/#concept-slotable |
18 | | using Slottable = Variant<JS::NonnullGCPtr<Element>, JS::NonnullGCPtr<Text>>; |
19 | | |
20 | | // https://dom.spec.whatwg.org/#mixin-slotable |
21 | | class SlottableMixin { |
22 | | public: |
23 | | virtual ~SlottableMixin(); |
24 | | |
25 | 0 | String const& slottable_name() const { return m_name; } // Not called `name` to distinguish from `Element::name`. |
26 | 0 | void set_slottable_name(String name) { m_name = move(name); } |
27 | | |
28 | | JS::GCPtr<HTML::HTMLSlotElement> assigned_slot(); |
29 | | |
30 | 0 | JS::GCPtr<HTML::HTMLSlotElement> assigned_slot_internal() const { return m_assigned_slot; } |
31 | 0 | void set_assigned_slot(JS::GCPtr<HTML::HTMLSlotElement> assigned_slot) { m_assigned_slot = assigned_slot; } |
32 | | |
33 | 0 | JS::GCPtr<HTML::HTMLSlotElement> manual_slot_assignment() { return m_manual_slot_assignment; } |
34 | 0 | void set_manual_slot_assignment(JS::GCPtr<HTML::HTMLSlotElement> manual_slot_assignment) { m_manual_slot_assignment = manual_slot_assignment; } |
35 | | |
36 | | protected: |
37 | | void visit_edges(JS::Cell::Visitor&); |
38 | | |
39 | | private: |
40 | | // https://dom.spec.whatwg.org/#slotable-name |
41 | | String m_name; |
42 | | |
43 | | // https://dom.spec.whatwg.org/#slotable-assigned-slot |
44 | | JS::GCPtr<HTML::HTMLSlotElement> m_assigned_slot; |
45 | | |
46 | | // https://dom.spec.whatwg.org/#slottable-manual-slot-assignment |
47 | | JS::GCPtr<HTML::HTMLSlotElement> m_manual_slot_assignment; |
48 | | }; |
49 | | |
50 | | enum class OpenFlag { |
51 | | Set, |
52 | | Unset, |
53 | | }; |
54 | | |
55 | | JS::GCPtr<HTML::HTMLSlotElement> assigned_slot_for_node(JS::NonnullGCPtr<Node>); |
56 | | bool is_an_assigned_slottable(JS::NonnullGCPtr<Node>); |
57 | | |
58 | | JS::GCPtr<HTML::HTMLSlotElement> find_a_slot(Slottable const&, OpenFlag = OpenFlag::Unset); |
59 | | Vector<Slottable> find_slottables(JS::NonnullGCPtr<HTML::HTMLSlotElement>); |
60 | | void assign_slottables(JS::NonnullGCPtr<HTML::HTMLSlotElement>); |
61 | | void assign_slottables_for_a_tree(JS::NonnullGCPtr<Node>); |
62 | | void assign_a_slot(Slottable const&); |
63 | | void signal_a_slot_change(JS::NonnullGCPtr<HTML::HTMLSlotElement>); |
64 | | |
65 | | } |