From 76187dc7d201428fc6e7d978ff9e328c3d0f2ffb Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Sun, 21 Jul 2024 20:48:54 -0400 Subject: [PATCH] fix(browser): use button release for forward/back navigation Also check if mouse pointer is within the webview Fixes #1564. --- src/libs/browser/webview.cpp | 17 ++++++++++++----- src/libs/browser/webview.h | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libs/browser/webview.cpp b/src/libs/browser/webview.cpp index a1751d9..f0c76d2 100644 --- a/src/libs/browser/webview.cpp +++ b/src/libs/browser/webview.cpp @@ -206,16 +206,23 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) m_contextMenu->popup(event->globalPos()); } -bool WebView::handleMousePressEvent(QMouseEvent *event) +bool WebView::handleMouseReleaseEvent(QMouseEvent *event) { switch (event->button()) { case Qt::BackButton: - back(); + // Check if cursor is still inside webview. + if (rect().contains(event->pos())) { + back(); + } + event->accept(); return true; case Qt::ForwardButton: - forward(); + if (rect().contains(event->pos())) { + forward(); + } + event->accept(); return true; @@ -251,8 +258,8 @@ bool WebView::eventFilter(QObject *watched, QEvent *event) { if (watched->parent() == this) { switch (event->type()) { - case QEvent::MouseButtonPress: - if (handleMousePressEvent(static_cast(event))) { + case QEvent::MouseButtonRelease: + if (handleMouseReleaseEvent(static_cast(event))) { return true; } diff --git a/src/libs/browser/webview.h b/src/libs/browser/webview.h index fd49012..862fc72 100644 --- a/src/libs/browser/webview.h +++ b/src/libs/browser/webview.h @@ -57,7 +57,7 @@ protected: void contextMenuEvent(QContextMenuEvent *event) override; private: - bool handleMousePressEvent(QMouseEvent *event); + bool handleMouseReleaseEvent(QMouseEvent *event); bool handleWheelEvent(QWheelEvent *event); QMenu *m_contextMenu = nullptr;