diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 1d50fd98d2..cdda74a11e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2594,6 +2594,31 @@ Vector> Document::inclusive_ancestor_navigables() return navigables; } +// https://html.spec.whatwg.org/multipage/document-sequences.html#document-tree-child-navigables +Vector> Document::document_tree_child_navigables() +{ + // 1. If document's node navigable is null, then return the empty list. + if (!navigable()) + return {}; + + // 2. Let navigables be new list. + Vector> navigables; + + // 3. Let navigableContainers be a list of all descendants of document that are navigable containers, in tree order. + // 4. For each navigableContainer of navigableContainers: + for_each_in_subtree_of_type([&](HTML::NavigableContainer& navigable_container) { + // 1. If navigableContainer's content navigable is null, then continue. + if (!navigable_container.content_navigable()) + return IterationDecision::Continue; + // 2. Append navigableContainer's content navigable to navigables. + navigables.append(*navigable_container.content_navigable()); + return IterationDecision::Continue; + }); + + // 5. Return navigables. + return navigables; +} + // https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts Vector> Document::list_of_descendant_browsing_contexts() const { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 14d49b9ac2..a283172fdb 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -465,6 +465,7 @@ public: Vector> inclusive_descendant_navigables(); Vector> ancestor_navigables(); Vector> inclusive_ancestor_navigables(); + Vector> document_tree_child_navigables(); void destroy();