summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Navigable.cpp14
-rw-r--r--Userland/Libraries/LibWeb/HTML/Navigable.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp
index e1a464592e..5fab6968c6 100644
--- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp
@@ -95,4 +95,18 @@ JS::GCPtr<TraversableNavigable> Navigable::traversable_navigable()
return static_cast<TraversableNavigable*>(navigable);
}
+// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-top
+JS::GCPtr<TraversableNavigable> Navigable::top_level_traversable()
+{
+ // 1. Let navigable be inputNavigable.
+ auto navigable = this;
+
+ // 2. While navigable's parent is not null, set navigable to navigable's parent.
+ while (navigable->parent())
+ navigable = navigable->parent();
+
+ // 3. Return navigable.
+ return verify_cast<TraversableNavigable>(navigable);
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.h b/Userland/Libraries/LibWeb/HTML/Navigable.h
index 553ae256e0..dc896e0d98 100644
--- a/Userland/Libraries/LibWeb/HTML/Navigable.h
+++ b/Userland/Libraries/LibWeb/HTML/Navigable.h
@@ -41,6 +41,7 @@ public:
void set_container(JS::GCPtr<NavigableContainer>);
JS::GCPtr<TraversableNavigable> traversable_navigable();
+ JS::GCPtr<TraversableNavigable> top_level_traversable();
protected:
Navigable();