From 874e73e0c9ded2383a96b94266020a8279bc9a44 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Jul 2022 15:20:32 +0200 Subject: [PATCH] Ladybird/WebView: Apply viewport scroll offset to mouse event coordinate --- Ladybird/WebView.cpp | 11 ++++++++--- Ladybird/WebView.h | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Ladybird/WebView.cpp b/Ladybird/WebView.cpp index 5084ff84232..9f0b2f36fb0 100644 --- a/Ladybird/WebView.cpp +++ b/Ladybird/WebView.cpp @@ -337,7 +337,7 @@ void WebView::mouseMoveEvent(QMouseEvent* event) Gfx::IntPoint position(event->x(), event->y()); auto buttons = get_buttons_from_qt_event(*event); auto modifiers = get_modifiers_from_qt_event(*event); - m_page_client->page().handle_mousemove(position, buttons, modifiers); + m_page_client->page().handle_mousemove(to_content(position), buttons, modifiers); } void WebView::mousePressEvent(QMouseEvent* event) @@ -345,7 +345,7 @@ void WebView::mousePressEvent(QMouseEvent* event) Gfx::IntPoint position(event->x(), event->y()); auto button = get_button_from_qt_event(*event); auto modifiers = get_modifiers_from_qt_event(*event); - m_page_client->page().handle_mousedown(position, button, modifiers); + m_page_client->page().handle_mousedown(to_content(position), button, modifiers); } void WebView::mouseReleaseEvent(QMouseEvent* event) @@ -353,7 +353,12 @@ void WebView::mouseReleaseEvent(QMouseEvent* event) Gfx::IntPoint position(event->x(), event->y()); auto button = get_button_from_qt_event(*event); auto modifiers = get_modifiers_from_qt_event(*event); - m_page_client->page().handle_mouseup(position, button, modifiers); + m_page_client->page().handle_mouseup(to_content(position), button, modifiers); +} + +Gfx::IntPoint WebView::to_content(Gfx::IntPoint viewport_position) const +{ + return viewport_position.translated(horizontalScrollBar()->value(), verticalScrollBar()->value()); } void WebView::paintEvent(QPaintEvent* event) diff --git a/Ladybird/WebView.h b/Ladybird/WebView.h index 418b1bbe94b..d325cc74354 100644 --- a/Ladybird/WebView.h +++ b/Ladybird/WebView.h @@ -10,6 +10,7 @@ #include #include +#include #include class HeadlessBrowserPageClient; @@ -35,5 +36,7 @@ signals: void title_changed(QString); private: + Gfx::IntPoint to_content(Gfx::IntPoint) const; + OwnPtr m_page_client; };