diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 50bce6a782..f9b6e028aa 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2316,6 +2316,45 @@ HTML::PolicyContainer Document::policy_container() const return m_policy_container; } +// https://html.spec.whatwg.org/multipage/document-sequences.html#descendant-navigables +Vector> Document::descendant_navigables() +{ + // 1. Let navigables be new list. + Vector> navigables; + + // 2. Let navigableContainers be a list of all shadow-including descendants of document that are navigable containers, in shadow-including tree order. + // 3. For each navigableContainer of navigableContainers: + for_each_shadow_including_descendant([&](DOM::Node& node) { + if (is(node)) { + auto& navigable_container = static_cast(node); + // 1. If navigableContainer's content navigable is null, then continue. + if (!navigable_container.content_navigable()) + return IterationDecision::Continue; + + // 2. Extend navigables with navigableContainer's content navigable's active document's inclusive descendant navigables. + navigables.extend(navigable_container.content_navigable()->active_document()->inclusive_descendant_navigables()); + } + return IterationDecision::Continue; + }); + + // 4. Return navigables. + return navigables; +} + +// https://html.spec.whatwg.org/multipage/document-sequences.html#inclusive-descendant-navigables +Vector> Document::inclusive_descendant_navigables() +{ + // 1. Let navigables be « document's node navigable ». + Vector> navigables; + navigables.append(*navigable()); + + // 2. Extend navigables with document's descendant navigables. + navigables.extend(descendant_navigables()); + + // 3. 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 da6c63997d..ab75d88fea 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -445,6 +445,9 @@ public: // https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts Vector> list_of_descendant_browsing_contexts() const; + Vector> descendant_navigables(); + Vector> inclusive_descendant_navigables(); + // https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document void discard();