diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 30e385ef9a..cccc9fda1a 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1029,8 +1029,10 @@ void Element::set_scroll_left(double x) // 8. If the element is the root element invoke scroll() on window with x as first argument and scrollY on window as second argument, and terminate these steps. if (document.document_element() == this) { // FIXME: Implement this in terms of invoking scroll() on window. - if (auto* page = document.page()) - page->client().page_did_request_scroll_to({ static_cast(x), static_cast(window->scroll_y()) }); + if (auto* page = document.page()) { + if (document.browsing_context() == &page->top_level_browsing_context()) + page->client().page_did_request_scroll_to({ static_cast(x), static_cast(window->scroll_y()) }); + } return; } @@ -1038,8 +1040,10 @@ void Element::set_scroll_left(double x) // 9. If the element is the body element, document is in quirks mode, and the element is not potentially scrollable, invoke scroll() on window with x as first argument and scrollY on window as second argument, and terminate these steps. if (document.body() == this && document.in_quirks_mode() && !is_potentially_scrollable()) { // FIXME: Implement this in terms of invoking scroll() on window. - if (auto* page = document.page()) - page->client().page_did_request_scroll_to({ static_cast(x), static_cast(window->scroll_y()) }); + if (auto* page = document.page()) { + if (document.browsing_context() == &page->top_level_browsing_context()) + page->client().page_did_request_scroll_to({ static_cast(x), static_cast(window->scroll_y()) }); + } return; } @@ -1093,8 +1097,10 @@ void Element::set_scroll_top(double y) // 8. If the element is the root element invoke scroll() on window with scrollX on window as first argument and y as second argument, and terminate these steps. if (document.document_element() == this) { // FIXME: Implement this in terms of invoking scroll() on window. - if (auto* page = document.page()) - page->client().page_did_request_scroll_to({ static_cast(window->scroll_x()), static_cast(y) }); + if (auto* page = document.page()) { + if (document.browsing_context() == &page->top_level_browsing_context()) + page->client().page_did_request_scroll_to({ static_cast(window->scroll_x()), static_cast(y) }); + } return; } @@ -1102,8 +1108,10 @@ void Element::set_scroll_top(double y) // 9. If the element is the body element, document is in quirks mode, and the element is not potentially scrollable, invoke scroll() on window with scrollX as first argument and y as second argument, and terminate these steps. if (document.body() == this && document.in_quirks_mode() && !is_potentially_scrollable()) { // FIXME: Implement this in terms of invoking scroll() on window. - if (auto* page = document.page()) - page->client().page_did_request_scroll_to({ static_cast(window->scroll_x()), static_cast(y) }); + if (auto* page = document.page()) { + if (document.browsing_context() == &page->top_level_browsing_context()) + page->client().page_did_request_scroll_to({ static_cast(window->scroll_x()), static_cast(y) }); + } return; } @@ -1390,7 +1398,8 @@ static ErrorOr scroll_an_element_into_view(DOM::Element& element, Bindings if (!layout_node) return Error::from_string_view("Element has no parent layout node that is a box."sv); - page->client().page_did_request_scroll_into_view(verify_cast(*layout_node).paintable_box()->absolute_padding_box_rect()); + if (element.document().browsing_context() == &page->top_level_browsing_context()) + page->client().page_did_request_scroll_into_view(verify_cast(*layout_node).paintable_box()->absolute_padding_box_rect()); return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 89da6c1e2d..50785f8235 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -621,7 +621,7 @@ void BrowsingContext::scroll_to(CSSPixelPoint position) active_document()->update_layout(); } - if (m_page) + if (m_page && this == &m_page->top_level_browsing_context()) m_page->client().page_did_request_scroll_to(position); } @@ -659,7 +659,7 @@ void BrowsingContext::scroll_to_anchor(DeprecatedString const& fragment) target_rect.translate_by(-padding_box.left, -padding_box.top); } - if (m_page) + if (m_page && this == &m_page->top_level_browsing_context()) m_page->client().page_did_request_scroll_into_view(target_rect); } diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 4fff7039ba..c39610ad48 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -193,7 +193,8 @@ bool EventHandler::handle_mousewheel(CSSPixelPoint position, unsigned button, un auto offset = compute_mouse_event_offset(position, *layout_node); if (node->dispatch_event(UIEvents::WheelEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::wheel, offset.x(), offset.y(), position.x(), position.y(), wheel_delta_x, wheel_delta_y, buttons, button).release_value_but_fixme_should_propagate_errors())) { if (auto* page = m_browsing_context->page()) { - page->client().page_did_request_scroll(wheel_delta_x * 20, wheel_delta_y * 20); + if (m_browsing_context == &page->top_level_browsing_context()) + page->client().page_did_request_scroll(wheel_delta_x * 20, wheel_delta_y * 20); } }