[pim/messagelib/release/26.08] /: Fix the "Open Attachment" dialogue appearing after an attachment drag
Allen Winter <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 263875410c8a4aa15e176581c1d5719435c457b6 by Allen Winter. Committed on 17/07/2026 at 19:00. Pushed by winterz into branch 'release/26.08'. Fix the "Open Attachment" dialogue appearing after an attachment drag The problem was that MailWebEngineView::forwardMousePressEvent() would check that a drag could potentially be started, but not accept the event. So the click would also be seen and the attachment URL opened by WebEnginePage::acceptNavigationRequest(). To fix the problem, if a drag event could potentially start then the mouse press event is accepted so that it does not have any further effect. If a drag event does start (within the acceptable drag distance and time), then forwardMouseMoveEvent() sets a new flag mStartedDrag to note that a drag has started. When the mouse button is released, whether just after a click or at the end of a drag, the flag is checked to see whether a drag really did start. If a drag did start then there is no more to do, but if there was no drag then the attachment is opened as if it was clicked. When handling "kmail:loadExternal", unconditionally set the display flag in KMailProtocolURLHandler::handleClick(). There is no user interface to turn the option off again, and multiple clicks (for example one delivered through forwardMouseReleaseEvent() and then another through acceptNavigationRequest() afterwards) can toggle the option multiple times. BUG: 506314 (cherry picked from commit 97c05097792bd848df0cdee073dee4211aad1acb) Co-authored-by: Jonathan Marten <[email protected]> M +1 -1 messageviewer/src/viewer/urlhandlermanager.cpp M +19 -0 messageviewer/src/viewer/webengine/mailwebengineview.cpp M +10 -0 webengineviewer/src/webenginepage.cpp https://invent.kde.org/pim/messagelib/-/commit/263875410c8a4aa15e176581c1d5719435c457b6 diff --git a/messageviewer/src/viewer/urlhandlermanager.cpp b/messageviewer/src/viewer/urlhandlermanager.cpp index 9f75856bf..c1027609a 100644 --- a/messageviewer/src/viewer/urlhandlermanager.cpp +++ b/messageviewer/src/viewer/urlhandlermanager.cpp @@ -373,7 +373,7 @@ bool KMailProtocolURLHandler::handleClick(const QUrl &url, ViewerPrivate *w) con w->goResourceOnline(); return true; } else if (urlPath == QLatin1StringView("loadExternal")) { - w->setHtmlLoadExtOverride(!w->htmlLoadExtOverride()); + w->setHtmlLoadExtOverride(true); w->update(MimeTreeParser::Force); return true; } else if (urlPath == QLatin1StringView("decryptMessage")) { diff --git a/messageviewer/src/viewer/webengine/mailwebengineview.cpp b/messageviewer/src/viewer/webengine/mailwebengineview.cpp index a81302ec4..d457153f3 100644 --- a/messageviewer/src/viewer/webengine/mailwebengineview.cpp +++ b/messageviewer/src/viewer/webengine/mailwebengineview.cpp @@ -21,6 +21,7 @@ #include <QWebEngineProfile> #include <WebEngineViewer/WebHitTest> +#include <QElapsedTimer> #include <QPainter> #include <QWebEngineUrlScheme> @@ -60,6 +61,8 @@ public: MessageViewer::ViewerPrivate *mViewer = nullptr; WebEngineViewer::BlockTrackingUrlInterceptor *mBlockMailTrackingUrl = nullptr; bool mCanStartDrag = false; + bool mStartedDrag = false; + QElapsedTimer *mStartDragTimer = nullptr; }; MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent) @@ -180,6 +183,14 @@ void MailWebEngineView::forwardMousePressEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { d->mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(d->mHoveredUrl, d->mViewer); d->mLastClickPosition = event->pos(); + + d->mStartedDrag = false; + if (d->mCanStartDrag) { + if (d->mStartDragTimer == nullptr) + d->mStartDragTimer = new QElapsedTimer; + d->mStartDragTimer->start(); + event->accept(); + } } } } @@ -191,6 +202,10 @@ void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event) if (d->mCanStartDrag && (event->buttons() & Qt::LeftButton)) { if ((d->mLastClickPosition - event->pos()).manhattanLength() > QApplication::startDragDistance()) { if (URLHandlerManager::instance()->handleDrag(d->mHoveredUrl, d->mViewer)) { + if (d->mCanStartDrag && d->mStartDragTimer != nullptr) { + if (d->mStartDragTimer->elapsed() > QApplication::startDragTime()) + d->mStartedDrag = true; + } // If the URL handler manager started a drag, don't handle this in the future d->mCanStartDrag = false; } @@ -203,6 +218,10 @@ void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event) void MailWebEngineView::forwardMouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event) + + if (!d->mStartedDrag && d->mHoveredUrl.isValid()) + d->mPageEngine->urlClicked(d->mHoveredUrl); + d->mStartedDrag = false; d->mCanStartDrag = false; } diff --git a/webengineviewer/src/webenginepage.cpp b/webengineviewer/src/webenginepage.cpp index 0c405d14e..fae572dba 100644 --- a/webengineviewer/src/webenginepage.cpp +++ b/webengineviewer/src/webenginepage.cpp @@ -162,7 +162,17 @@ void WebEnginePage::saveHtml(QWebEngineDownloadRequest *download) bool WebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) { + const QString sch = url.scheme(); + qDebug() << "type" << type << "isMainFrame" << isMainFrame << "scheme" << sch; + if (sch != QStringLiteral("data")) + qDebug() << "url" << url; + if (isMainFrame && type == NavigationTypeLinkClicked) { + // Schemes other than these will have been sent directly + // to MailWebEnginePage::urlClicked() and handled there. + if (sch != QStringLiteral("kmail") && sch != QStringLiteral("data")) + return false; + Q_EMIT urlClicked(url); return false; }