瀏覽代碼

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.
Aliaksandr Kalenik 1 年之前
父節點
當前提交
607e4cab0a
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      Userland/Libraries/LibWeb/HTML/Window.cpp

+ 6 - 2
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,
     // 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.
     // 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
 // 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,
     // 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.
     // 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
 // https://w3c.github.io/csswg-drafts/cssom-view/#perform-a-scroll