diff options
author | Andreas Kling <kling@serenityos.org> | 2022-12-12 12:17:46 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-23 14:18:57 +0200 |
commit | 54e01824c7ad38b8cf289cbf4f153aca88073fb0 (patch) | |
tree | 095d77fc9385f5ed342dfe6021f31255aeca14b5 /Userland/Libraries | |
parent | 05dc1da3215372f44f4ab130eab10bfa51a51638 (diff) | |
download | serenity-54e01824c7ad38b8cf289cbf4f153aca88073fb0.zip |
LibWeb: Implement getting the top-level traversable of a navigable
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Navigable.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/Navigable.h | 1 |
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(); |