From 6871fbce9f93a7b4bb9f6e3e553aa1befbafe855 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Dec 2022 13:35:20 +0100 Subject: [PATCH] LibWeb: Implement the "top-level traversable" of a browsing context --- Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp | 11 +++++++++++ Userland/Libraries/LibWeb/HTML/BrowsingContext.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 84ccc211ed..c42fdfa3b1 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -290,6 +291,16 @@ void BrowsingContext::visit_edges(Cell::Visitor& visitor) visitor.visit(m_previous_sibling); } +// https://html.spec.whatwg.org/multipage/document-sequences.html#bc-traversable +JS::NonnullGCPtr BrowsingContext::top_level_traversable() const +{ + // A browsing context's top-level traversable is its active document's node navigable's top-level traversable. + auto traversable = active_document()->navigable()->top_level_traversable(); + VERIFY(traversable); + VERIFY(traversable->is_top_level_traversable()); + return *traversable; +} + void BrowsingContext::did_edit(Badge) { reset_cursor_blink_cycle(); diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h index 833039a300..b65a0e45b1 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.h @@ -42,6 +42,8 @@ public: virtual ~BrowsingContext() override; + JS::NonnullGCPtr top_level_traversable() const; + JS::GCPtr parent() const { return m_parent; } void append_child(JS::NonnullGCPtr); void remove_child(JS::NonnullGCPtr);