summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML
diff options
context:
space:
mode:
authorAliaksandr Kalenik <kalenik.aliaksandr@gmail.com>2023-04-06 23:30:02 +0300
committerAndreas Kling <kling@serenityos.org>2023-04-28 18:11:44 +0200
commit6ec88b36b9e4aabfc4c6c79ffcd23ad75b8101c5 (patch)
treec493bd6fde931aacfd612b0e9cbad246f0619814 /Userland/Libraries/LibWeb/HTML
parentd9d88963809300893cbc2a532265a2c31fb90686 (diff)
downloadserenity-6ec88b36b9e4aabfc4c6c79ffcd23ad75b8101c5.zip
LibWeb: Implement "get the target history entry" for navigables
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Navigable.cpp20
-rw-r--r--Userland/Libraries/LibWeb/HTML/Navigable.h2
2 files changed, 22 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp
index 60702bd518..18a7a0286f 100644
--- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp
@@ -77,6 +77,26 @@ ErrorOr<void> Navigable::initialize_navigable(JS::NonnullGCPtr<DocumentState> do
return {};
}
+// https://html.spec.whatwg.org/multipage/browsing-the-web.html#getting-the-target-history-entry
+JS::GCPtr<SessionHistoryEntry> Navigable::get_the_target_history_entry(int target_step) const
+{
+ // 1. Let entries be the result of getting session history entries for navigable.
+ auto& entries = get_session_history_entries();
+
+ // 2. Return the item in entries that has the greatest step less than or equal to step.
+ JS::GCPtr<SessionHistoryEntry> result = nullptr;
+ for (auto& entry : entries) {
+ auto entry_step = entry->step.get<int>();
+ if (entry_step <= target_step) {
+ if (!result || result->step.get<int>() < entry_step) {
+ result = entry;
+ }
+ }
+ }
+
+ return result;
+}
+
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-document
JS::GCPtr<DOM::Document> Navigable::active_document()
{
diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.h b/Userland/Libraries/LibWeb/HTML/Navigable.h
index 61c1d9d7f8..6340f18acf 100644
--- a/Userland/Libraries/LibWeb/HTML/Navigable.h
+++ b/Userland/Libraries/LibWeb/HTML/Navigable.h
@@ -42,6 +42,8 @@ public:
JS::GCPtr<WindowProxy> active_window_proxy();
JS::GCPtr<Window> active_window();
+ JS::GCPtr<SessionHistoryEntry> get_the_target_history_entry(int target_step) const;
+
String target_name() const;
JS::GCPtr<NavigableContainer> container() const;