Skip to content

Commit

Permalink
fix(browser): use button release for forward/back navigation
Browse files Browse the repository at this point in the history
Also check if mouse pointer is within the webview

Fixes #1564.
  • Loading branch information
trollixx committed Jul 22, 2024
1 parent b8066c5 commit 76187dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/libs/browser/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<QMouseEvent *>(event))) {
case QEvent::MouseButtonRelease:
if (handleMouseReleaseEvent(static_cast<QMouseEvent *>(event))) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/browser/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public slots:
void contextMenuEvent(QContextMenuEvent *event) override;

private:
bool handleMousePressEvent(QMouseEvent *event);
bool handleMouseReleaseEvent(QMouseEvent *event);
bool handleWheelEvent(QWheelEvent *event);

QMenu *m_contextMenu = nullptr;
Expand Down

0 comments on commit 76187dc

Please sign in to comment.