From 607e4cab0ae44c8d10bd43aeec477ae0a16499bd Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 3 Feb 2024 10:32:21 +0100 Subject: [PATCH] LibWeb: Use associated navigable in scrollX and scrollY in Window If these functions are invoked from inside an iframe, we should use the navigable associated with the iframe to get the viewport. --- Userland/Libraries/LibWeb/HTML/Window.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index e3d792300a1..28d32a09ce5 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1217,7 +1217,9 @@ double Window::scroll_x() const { // The scrollX attribute must return the x-coordinate, relative to the initial containing block origin, // of the left of the viewport, or zero if there is no viewport. - return page().top_level_traversable()->viewport_scroll_offset().x().to_double(); + if (auto const navigable = associated_document().navigable()) + return navigable->viewport_rect().x().to_double(); + return 0; } // https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-scrolly @@ -1225,7 +1227,9 @@ double Window::scroll_y() const { // The scrollY attribute must return the y-coordinate, relative to the initial containing block origin, // of the top of the viewport, or zero if there is no viewport. - return page().top_level_traversable()->viewport_scroll_offset().y().to_double(); + if (auto const navigable = associated_document().navigable()) + return navigable->viewport_rect().y().to_double(); + return 0; } // https://w3c.github.io/csswg-drafts/cssom-view/#perform-a-scroll