1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:47:46 +00:00

LibWeb: Introduce the slottable concept for DOM elements and text nodes

A slottable is either a DOM element or a DOM text node. They may be
assigned to slots (HTMLSlotElement) either automatically or manually.
Automatic assignment occurs by matching a slot's `name` attribute to
a slottable's `slot` attribute. Manual assignment occurs by using the
slot's (not yet implemented) `assign` API.

This commit does not perform the above assignments. It just sets up the
slottable concept via IDL and hooks the slottable mixin into the element
and text nodes.
This commit is contained in:
Timothy Flynn 2023-09-05 13:07:35 -04:00 committed by Andreas Kling
parent b85a252753
commit 45b36bd08a
12 changed files with 116 additions and 1 deletions

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <AK/Variant.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Forward.h>
namespace Web::DOM {
// https://dom.spec.whatwg.org/#concept-slotable
using Slottable = Variant<JS::NonnullGCPtr<Element>, JS::NonnullGCPtr<Text>>;
// https://dom.spec.whatwg.org/#mixin-slotable
class SlottableMixin {
public:
virtual ~SlottableMixin();
String const& slottable_name() const { return m_name; } // Not called `name` to distinguish from `Element::name`.
void set_slottable_name(String name) { m_name = move(name); }
JS::GCPtr<HTML::HTMLSlotElement> assigned_slot();
JS::GCPtr<HTML::HTMLSlotElement> assigned_slot_internal() const { return m_assigned_slot; }
void set_assigned_slot(JS::GCPtr<HTML::HTMLSlotElement> assigned_slot) { m_assigned_slot = assigned_slot; }
JS::GCPtr<HTML::HTMLSlotElement> manual_slot_assignment() { return m_manual_slot_assignment; }
void set_manual_slot_assignment(JS::GCPtr<HTML::HTMLSlotElement> manual_slot_assignment) { m_manual_slot_assignment = manual_slot_assignment; }
protected:
void visit_edges(JS::Cell::Visitor&);
private:
// https://dom.spec.whatwg.org/#slotable-name
String m_name;
// https://dom.spec.whatwg.org/#slotable-assigned-slot
JS::GCPtr<HTML::HTMLSlotElement> m_assigned_slot;
// https://dom.spec.whatwg.org/#slottable-manual-slot-assignment
JS::GCPtr<HTML::HTMLSlotElement> m_manual_slot_assignment;
};
}