LibWeb: Implement element slot-related attributes and settings

This implements the element's slot attribute itself, and setting the
slot assignment on the element's shadow root.
This commit is contained in:
Timothy Flynn 2023-09-01 07:25:40 -04:00 committed by Andreas Kling
parent 4e32f0d39f
commit 54b5a431a3
Notes: sideshowbarker 2024-07-16 21:34:08 +09:00
6 changed files with 12 additions and 4 deletions

View file

@ -599,7 +599,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ShadowRoot>> Element::attach_shadow(ShadowR
if (m_custom_element_state == CustomElementState::Precustomized || m_custom_element_state == CustomElementState::Custom)
shadow->set_available_to_element_internals(true);
// FIXME: 8. Set shadows slot assignment to init["slotAssignment"].
// 8. Set shadows slot assignment to init["slotAssignment"].
shadow->set_slot_assignment(init.slot_assignment);
// 9. Set thiss shadow root to shadow.
set_shadow_root(shadow);

View file

@ -30,6 +30,7 @@ namespace Web::DOM {
struct ShadowRootInit {
Bindings::ShadowRootMode mode;
bool delegates_focus = false;
Bindings::SlotAssignmentMode slot_assignment { Bindings::SlotAssignmentMode::Named };
};
// https://w3c.github.io/csswg-drafts/cssom-view-1/#dictdef-scrollintoviewoptions

View file

@ -49,6 +49,7 @@ interface Element : Node {
[Reflect, CEReactions] attribute DOMString id;
[Reflect=class, CEReactions] attribute DOMString className;
[SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
[Reflect, CEReactions, Unscopable] attribute DOMString slot;
ShadowRoot attachShadow(ShadowRootInit init);
readonly attribute ShadowRoot? shadowRoot;
@ -90,7 +91,7 @@ interface Element : Node {
dictionary ShadowRootInit {
required ShadowRootMode mode;
boolean delegatesFocus = false;
// FIXME: SlotAssignmentMode slotAssignment = "named";
SlotAssignmentMode slotAssignment = "named";
};
Element includes ParentNode;

View file

@ -17,6 +17,9 @@ class ShadowRoot final : public DocumentFragment {
public:
Bindings::ShadowRootMode mode() const { return m_mode; }
Bindings::SlotAssignmentMode slot_assignment() const { return m_slot_assignment; }
void set_slot_assignment(Bindings::SlotAssignmentMode slot_assignment) { m_slot_assignment = slot_assignment; }
bool delegates_focus() const { return m_delegates_focus; }
void set_delegates_focus(bool delegates_focus) { m_delegates_focus = delegates_focus; }
@ -37,8 +40,9 @@ private:
virtual DeprecatedFlyString node_name() const override { return "#shadow-root"; }
virtual bool is_shadow_root() const final { return true; }
// NOTE: The specification doesn't seem to specify a default value for closed. Assuming closed for now.
// NOTE: The specification doesn't seem to specify a default value for mode. Assuming closed for now.
Bindings::ShadowRootMode m_mode { Bindings::ShadowRootMode::Closed };
Bindings::SlotAssignmentMode m_slot_assignment { Bindings::SlotAssignmentMode::Named };
bool m_delegates_focus { false };
bool m_available_to_element_internals { false };
};

View file

@ -6,7 +6,7 @@
interface ShadowRoot : DocumentFragment {
readonly attribute ShadowRootMode mode;
// FIXME: readonly attribute boolean delegatesFocus;
// FIXME: readonly attribute SlotAssignmentMode slotAssignment;
readonly attribute SlotAssignmentMode slotAssignment;
readonly attribute Element host;
// FIXME: attribute EventHandler onslotchange;
};

View file

@ -214,6 +214,7 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(shape) \
__ENUMERATE_HTML_ATTRIBUTE(size) \
__ENUMERATE_HTML_ATTRIBUTE(sizes) \
__ENUMERATE_HTML_ATTRIBUTE(slot) \
__ENUMERATE_HTML_ATTRIBUTE(span) \
__ENUMERATE_HTML_ATTRIBUTE(src) \
__ENUMERATE_HTML_ATTRIBUTE(srcdoc) \