Ladybird/WebView: Apply viewport scroll offset to mouse event coordinate

This commit is contained in:
Andreas Kling 2022-07-04 15:20:32 +02:00 committed by Andrew Kaster
parent 96170a4f24
commit 874e73e0c9
Notes: sideshowbarker 2024-07-18 02:13:10 +09:00
2 changed files with 11 additions and 3 deletions

View file

@ -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)

View file

@ -10,6 +10,7 @@
#include <AK/OwnPtr.h>
#include <AK/String.h>
#include <LibGfx/Forward.h>
#include <QAbstractScrollArea>
class HeadlessBrowserPageClient;
@ -35,5 +36,7 @@ signals:
void title_changed(QString);
private:
Gfx::IntPoint to_content(Gfx::IntPoint) const;
OwnPtr<HeadlessBrowserPageClient> m_page_client;
};