Skip to content

Commit 7af0948

Browse files
committed
LibWeb: Implement getting "descendant navigables" of a document
1 parent 21e383c commit 7af0948

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Userland/Libraries/LibWeb/DOM/Document.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,45 @@ HTML::PolicyContainer Document::policy_container() const
23162316
return m_policy_container;
23172317
}
23182318

2319+
// https://html.spec.whatwg.org/multipage/document-sequences.html#descendant-navigables
2320+
Vector<JS::Handle<HTML::Navigable>> Document::descendant_navigables()
2321+
{
2322+
// 1. Let navigables be new list.
2323+
Vector<JS::Handle<HTML::Navigable>> navigables;
2324+
2325+
// 2. Let navigableContainers be a list of all shadow-including descendants of document that are navigable containers, in shadow-including tree order.
2326+
// 3. For each navigableContainer of navigableContainers:
2327+
for_each_shadow_including_descendant([&](DOM::Node& node) {
2328+
if (is<HTML::NavigableContainer>(node)) {
2329+
auto& navigable_container = static_cast<HTML::NavigableContainer&>(node);
2330+
// 1. If navigableContainer's content navigable is null, then continue.
2331+
if (!navigable_container.content_navigable())
2332+
return IterationDecision::Continue;
2333+
2334+
// 2. Extend navigables with navigableContainer's content navigable's active document's inclusive descendant navigables.
2335+
navigables.extend(navigable_container.content_navigable()->active_document()->inclusive_descendant_navigables());
2336+
}
2337+
return IterationDecision::Continue;
2338+
});
2339+
2340+
// 4. Return navigables.
2341+
return navigables;
2342+
}
2343+
2344+
// https://html.spec.whatwg.org/multipage/document-sequences.html#inclusive-descendant-navigables
2345+
Vector<JS::Handle<HTML::Navigable>> Document::inclusive_descendant_navigables()
2346+
{
2347+
// 1. Let navigables be « document's node navigable ».
2348+
Vector<JS::Handle<HTML::Navigable>> navigables;
2349+
navigables.append(*navigable());
2350+
2351+
// 2. Extend navigables with document's descendant navigables.
2352+
navigables.extend(descendant_navigables());
2353+
2354+
// 3. Return navigables.
2355+
return navigables;
2356+
}
2357+
23192358
// https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts
23202359
Vector<JS::Handle<HTML::BrowsingContext>> Document::list_of_descendant_browsing_contexts() const
23212360
{

Userland/Libraries/LibWeb/DOM/Document.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ class Document
445445
// https://html.spec.whatwg.org/multipage/browsers.html#list-of-the-descendant-browsing-contexts
446446
Vector<JS::Handle<HTML::BrowsingContext>> list_of_descendant_browsing_contexts() const;
447447

448+
Vector<JS::Handle<HTML::Navigable>> descendant_navigables();
449+
Vector<JS::Handle<HTML::Navigable>> inclusive_descendant_navigables();
450+
448451
// https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document
449452
void discard();
450453

0 commit comments

Comments
 (0)