Skip to content

Truly independent web browser

LibWeb: Restore scroll positions after intercepted traversals

Andreas Kling39a521877312
diff --git a/Libraries/LibWeb/HTML/NavigateEvent.cpp b/Libraries/LibWeb/HTML/NavigateEvent.cpp
index 64f1e708138..9012801215f 100644
--- a/Libraries/LibWeb/HTML/NavigateEvent.cpp
+++ b/Libraries/LibWeb/HTML/NavigateEvent.cpp
@@ -246,10 +246,13 @@ void NavigateEvent::process_scroll_behavior()
// 2. Set event's interception state to "scrolled".
m_interception_state = InterceptionState::Scrolled;
- // FIXME: 3. If event's navigationType was initialized to "traverse" or "reload", then restore scroll position data
- // given event's relevant global object's navigable's active session history entry.
- if (m_navigation_type == NavigationType::Traverse || m_navigation_type == NavigationType::Reload) {
- dbgln("FIXME: restore scroll position data after traversal or reload navigation");
+ // 3. If event's navigationType was initialized to "traverse", then restore scroll position data given event's
+ // relevant global object's navigable's active session history entry.
+ if (m_navigation_type == NavigationType::Traverse) {
+ if (auto navigable = m_relevant_window->navigable()) {
+ if (auto entry = navigable->active_session_history_entry())
+ navigable->restore_scroll_position_data(*entry);
+ }
}
// 4. Otherwise:
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-basic.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-basic.txt
index 90ab27e696d..b9ece301cbb 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-basic.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-basic.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition should scroll when back completes
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition should scroll when back completes
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.txt
index cf86bfb5f8e..8d062db528e 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-explicit-scroll.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: scroll() should preempt after-transition
\ No newline at end of file
+1 Pass
+Pass scroll: scroll() should preempt after-transition
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.txt
index 83dd010b762..a986781224c 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-intercept-handler-modifies.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: state should be saved before intercept handlers run
\ No newline at end of file
+1 Pass
+Pass scroll: state should be saved before intercept handlers run
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.txt
index a4a6057f688..71c60d23300 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-after-traverse.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition on a reload of a traversed-to fragment entry scrolls to the fragment
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition on a reload of a traversed-to fragment entry scrolls to the fragment
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.txt
index de7fb6a207a..80661030ccd 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-fragment.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition on a reload without a fragment scrolls to the beginning of the document
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition on a reload without a fragment scrolls to the beginning of the document
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.txt
index 7b28123096d..753678e73f2 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-reload-no-scroll-anchoring.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition should work on a reload navigation
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition should work on a reload navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-timing.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-timing.txt
index e47a3715cc5..3ef61367600 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-timing.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-timing.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition should scroll when back completes, just before navigatesuccess
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition should scroll when back completes, just before navigatesuccess
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.txt
index d76a9df4d5f..531c2f27ee6 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-no-fragment.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition on a traverse to an entry without a fragment restores the scroll position
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition on a traverse to an entry without a fragment restores the scroll position
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.txt
index 3b3ba53dff9..bab3b890791 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-traverse-to-fragment.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition on a traverse to an entry with a fragment restores the scroll position
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition on a traverse to an entry with a fragment restores the scroll position
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.txt
index e67bf158ad8..b6a8d0bb644 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-reload-no-scroll-anchoring.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: scroll() should work on a reload navigation
\ No newline at end of file
+1 Pass
+Pass scroll: scroll() should work on a reload navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.txt
index a30450775d4..b955cc83be6 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-repeated.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: scroll() should throw if called a second time
\ No newline at end of file
+1 Pass
+Pass scroll: scroll() should throw if called a second time
\ No newline at end of file