diff --git a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp b/Libraries/LibWeb/HTML/HTMLSlotElement.cpp index 0d846292fd6..be48da13d9a 100644 --- a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLSlotElement.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2020, the SerenityOS developers. * Copyright (c) 2023, Tim Flynn + * Copyright (c) 2025, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -54,8 +55,17 @@ Vector> HTMLSlotElement::assigned_nodes(AssignedNodesOptions return assigned_nodes; } - // FIXME: 2. Return the result of finding flattened slottables with this. - return {}; + // 2. Return the result of finding flattened slottables with this. + // FIXME: Make this a lot less awkward! + auto nodes = DOM::find_flattened_slottables(const_cast(*this)); + Vector> 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 @@ -73,8 +83,14 @@ Vector> HTMLSlotElement::assigned_elements(AssignedNodesO return assigned_nodes; } - // FIXME: 2. Return the result of finding flattened slottables with this, filtered to contain only Element nodes. - return {}; + // 2. Return the result of finding flattened slottables with this, filtered to contain only Element nodes. + auto result = DOM::find_flattened_slottables(const_cast(*this)); + Vector> assigned_nodes; + for (auto const& node : result) { + if (auto const* element = node.get_pointer>()) + assigned_nodes.append(*element); + } + return assigned_nodes; } // https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assign diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback-in-document.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback-in-document.txt index 9fed588d4df..2b1f6401e3e 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback-in-document.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback-in-document.txt @@ -2,6 +2,6 @@ Harness status: OK Found 2 tests -2 Fail -Fail 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. \ No newline at end of file +2 Pass +Pass Children of a slot in a document tree should not be counted in flattened assigned nodes. +Pass Slot fallback content in shadow tree should be counted in flattened assigned nodes. \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback.txt index ea2bc3bac9b..17ce8db3450 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-fallback.txt @@ -2,17 +2,18 @@ Harness status: OK Found 13 tests -13 Fail -Fail Slots fallback: Basic. -Fail Slots fallback: Basic, elements only. -Fail Slots fallback: Slots in Slots. -Fail Slots fallback: Slots in Slots, elements only. -Fail Slots fallback: Fallback contents should not be used if a node is assigned. -Fail Slots fallback: Slots in Slots: Assigned nodes should be used as fallback contents of another slot -Fail Slots fallback: Complex case. -Fail Slots fallback: Complex case, elements only. -Fail Slots fallback: Mutation. Append fallback contents. -Fail Slots fallback: Mutation. Remove fallback contents. -Fail Slots fallback: Mutation. Assign a node to a slot so that fallback contens are no longer used. -Fail Slots fallback: Mutation. Remove an assigned node from a slot so that fallback contens will be used. +12 Pass +1 Fail +Pass Slots fallback: Basic. +Pass Slots fallback: Basic, elements only. +Pass Slots fallback: Slots in Slots. +Pass Slots fallback: Slots in Slots, elements only. +Pass Slots fallback: Fallback contents should not be used if a node is assigned. +Pass Slots fallback: Slots in Slots: Assigned nodes should be used as fallback contents of another slot +Pass Slots fallback: Complex case. +Pass Slots fallback: Complex case, elements only. +Pass Slots fallback: Mutation. Append fallback contents. +Pass Slots fallback: Mutation. Remove fallback contents. +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. \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-outside-shadow-dom.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-outside-shadow-dom.txt index e79de39d284..4b026276b24 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-outside-shadow-dom.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots-outside-shadow-dom.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail Light DOM slot element should be in flattened assignedNodes \ No newline at end of file +1 Pass +Pass Light DOM slot element should be in flattened assignedNodes \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots.txt index 499e7f31e2d..a6a77aa42ba 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/slots.txt @@ -2,8 +2,8 @@ Harness status: OK Found 26 tests -12 Pass -14 Fail +25 Pass +1 Fail Pass Slots: Basic. Pass Slots: Basic, elements only. Pass Slots: Slots in closed. @@ -15,18 +15,18 @@ Pass Slots: Name matching Pass Slots: No direct host child. Pass Slots: Default Slot. Pass Slots: Slot in Slot does not matter in assignment. -Fail Slots: Slot is assigned to another slot -Fail Slots: Open > Closed. -Fail Slots: Closed > Closed. -Fail Slots: Closed > Open. -Fail Slots: Complex case: Basi line. -Fail Slots: Mutation: appendChild. -Fail Slots: Mutation: Change slot= attribute 1. -Fail Slots: Mutation: Change slot= attribute 2. -Fail Slots: Mutation: Change slot= attribute 3. -Fail Slots: Mutation: Remove a child. +Pass Slots: Slot is assigned to another slot +Pass Slots: Open > Closed. +Pass Slots: Closed > Closed. +Pass Slots: Closed > Open. +Pass Slots: Complex case: Basi line. +Pass Slots: Mutation: appendChild. +Pass Slots: Mutation: Change slot= attribute 1. +Pass Slots: Mutation: Change slot= attribute 2. +Pass Slots: Mutation: Change slot= attribute 3. +Pass Slots: Mutation: Remove a child. 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: Change slot name= attribute. -Fail Slots: Mutation: Change slot slot= attribute. \ No newline at end of file +Pass Slots: Mutation: Change slot name= attribute. +Pass Slots: Mutation: Change slot slot= attribute. \ No newline at end of file