1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibWeb/HTML: Use find flattened slots in assignedElements/assignedNodes

This is very awkward, and should be improved, but this improves
our support for slots :^)
This commit is contained in:
Shannon Booth 2025-05-10 10:30:56 +12:00 committed by Shannon Booth
parent 2d6b11c8cb
commit 14d5c638eb
Notes: github-actions[bot] 2025-05-19 11:27:11 +00:00
5 changed files with 54 additions and 37 deletions

View file

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2020, the SerenityOS developers. * Copyright (c) 2020, the SerenityOS developers.
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -54,8 +55,17 @@ Vector<GC::Root<DOM::Node>> HTMLSlotElement::assigned_nodes(AssignedNodesOptions
return assigned_nodes; return assigned_nodes;
} }
// FIXME: 2. Return the result of finding flattened slottables with this. // 2. Return the result of finding flattened slottables with this.
return {}; // FIXME: Make this a lot less awkward!
auto nodes = DOM::find_flattened_slottables(const_cast<HTMLSlotElement&>(*this));
Vector<GC::Root<DOM::Node>> assigned_nodes;
assigned_nodes.ensure_capacity(nodes.size());
for (auto const& node : nodes) {
node.visit([&](auto const& slottable) {
assigned_nodes.unchecked_append(*slottable);
});
}
return assigned_nodes;
} }
// https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignedelements // https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignedelements
@ -73,8 +83,14 @@ Vector<GC::Root<DOM::Element>> HTMLSlotElement::assigned_elements(AssignedNodesO
return assigned_nodes; return assigned_nodes;
} }
// FIXME: 2. Return the result of finding flattened slottables with this, filtered to contain only Element nodes. // 2. Return the result of finding flattened slottables with this, filtered to contain only Element nodes.
return {}; auto result = DOM::find_flattened_slottables(const_cast<HTMLSlotElement&>(*this));
Vector<GC::Root<DOM::Element>> assigned_nodes;
for (auto const& node : result) {
if (auto const* element = node.get_pointer<GC::Ref<DOM::Element>>())
assigned_nodes.append(*element);
}
return assigned_nodes;
} }
// https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assign // https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assign

View file

@ -2,6 +2,6 @@ Harness status: OK
Found 2 tests Found 2 tests
2 Fail 2 Pass
Fail Children of a slot in a document tree should not be counted in flattened assigned nodes. Pass Children of a slot in a document tree should not be counted in flattened assigned nodes.
Fail Slot fallback content in shadow tree should be counted in flattened assigned nodes. Pass Slot fallback content in shadow tree should be counted in flattened assigned nodes.

View file

@ -2,17 +2,18 @@ Harness status: OK
Found 13 tests Found 13 tests
13 Fail 12 Pass
Fail Slots fallback: Basic. 1 Fail
Fail Slots fallback: Basic, elements only. Pass Slots fallback: Basic.
Fail Slots fallback: Slots in Slots. Pass Slots fallback: Basic, elements only.
Fail Slots fallback: Slots in Slots, elements only. Pass Slots fallback: Slots in Slots.
Fail Slots fallback: Fallback contents should not be used if a node is assigned. Pass Slots fallback: Slots in Slots, elements only.
Fail Slots fallback: Slots in Slots: Assigned nodes should be used as fallback contents of another slot Pass Slots fallback: Fallback contents should not be used if a node is assigned.
Fail Slots fallback: Complex case. Pass Slots fallback: Slots in Slots: Assigned nodes should be used as fallback contents of another slot
Fail Slots fallback: Complex case, elements only. Pass Slots fallback: Complex case.
Fail Slots fallback: Mutation. Append fallback contents. Pass Slots fallback: Complex case, elements only.
Fail Slots fallback: Mutation. Remove fallback contents. Pass Slots fallback: Mutation. Append fallback contents.
Fail Slots fallback: Mutation. Assign a node to a slot so that fallback contens are no longer used. Pass Slots fallback: Mutation. Remove fallback contents.
Fail Slots fallback: Mutation. Remove an assigned node from a slot so that fallback contens will be used. Pass Slots fallback: Mutation. Assign a node to a slot so that fallback contens are no longer used.
Pass Slots fallback: Mutation. Remove an assigned node from a slot so that fallback contens will be used.
Fail Slots fallback: Mutation. Remove a slot which is a fallback content of another slot. Fail Slots fallback: Mutation. Remove a slot which is a fallback content of another slot.

View file

@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests Found 1 tests
1 Fail 1 Pass
Fail Light DOM slot element should be in flattened assignedNodes Pass Light DOM slot element should be in flattened assignedNodes

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 26 tests Found 26 tests
12 Pass 25 Pass
14 Fail 1 Fail
Pass Slots: Basic. Pass Slots: Basic.
Pass Slots: Basic, elements only. Pass Slots: Basic, elements only.
Pass Slots: Slots in closed. Pass Slots: Slots in closed.
@ -15,18 +15,18 @@ Pass Slots: Name matching
Pass Slots: No direct host child. Pass Slots: No direct host child.
Pass Slots: Default Slot. Pass Slots: Default Slot.
Pass Slots: Slot in Slot does not matter in assignment. Pass Slots: Slot in Slot does not matter in assignment.
Fail Slots: Slot is assigned to another slot Pass Slots: Slot is assigned to another slot
Fail Slots: Open > Closed. Pass Slots: Open > Closed.
Fail Slots: Closed > Closed. Pass Slots: Closed > Closed.
Fail Slots: Closed > Open. Pass Slots: Closed > Open.
Fail Slots: Complex case: Basi line. Pass Slots: Complex case: Basi line.
Fail Slots: Mutation: appendChild. Pass Slots: Mutation: appendChild.
Fail Slots: Mutation: Change slot= attribute 1. Pass Slots: Mutation: Change slot= attribute 1.
Fail Slots: Mutation: Change slot= attribute 2. Pass Slots: Mutation: Change slot= attribute 2.
Fail Slots: Mutation: Change slot= attribute 3. Pass Slots: Mutation: Change slot= attribute 3.
Fail Slots: Mutation: Remove a child. Pass Slots: Mutation: Remove a child.
Pass Slots: Mutation: Add a slot: after. Pass Slots: Mutation: Add a slot: after.
Fail Slots: Mutation: Add a slot: before. Pass Slots: Mutation: Add a slot: before.
Fail Slots: Mutation: Remove a slot. Fail Slots: Mutation: Remove a slot.
Fail Slots: Mutation: Change slot name= attribute. Pass Slots: Mutation: Change slot name= attribute.
Fail Slots: Mutation: Change slot slot= attribute. Pass Slots: Mutation: Change slot slot= attribute.