Commit 42a5c006 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 366652 - Drag and drop attachments in Kmail has stopped working

Fix Bug 368378 - Regression in kMail 5.3.x: Drag and drop of attachments from a received mail into the composer does not work any more

FIXED-IN: 5.4.0
BUG: 366652
BUG: 368378
parent a2478015
......@@ -1072,8 +1072,6 @@ void ViewerPrivate::showVCard(KMime::Content *msgPart)
void ViewerPrivate::initHtmlWidget()
{
mViewer->installEventFilter(this);
if (!htmlWriter()) {
mPartHtmlWriter = new WebEnginePartHtmlWriter(mViewer, 0);
#ifdef MESSAGEVIEWER_READER_HTML_DEBUG
......@@ -1100,47 +1098,6 @@ void ViewerPrivate::initHtmlWidget()
connect(mViewer, &MailWebEngineView::pageIsScrolledToBottom, this, &ViewerPrivate::pageIsScrolledToBottom);
}
bool ViewerPrivate::eventFilter(QObject *, QEvent *e)
{
if (e->type() == QEvent::MouseButtonPress) {
QMouseEvent *me = static_cast<QMouseEvent *>(e);
if (me->button() == Qt::LeftButton && (me->modifiers() & Qt::ShiftModifier)) {
// special processing for shift+click
URLHandlerManager::instance()->handleShiftClick(mHoveredUrl, this);
return true;
}
if (me->button() == Qt::LeftButton) {
mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(mHoveredUrl, this);
mLastClickPosition = me->pos();
}
} else if (e->type() == QEvent::MouseButtonRelease) {
mCanStartDrag = false;
} else if (e->type() == QEvent::MouseMove) {
QMouseEvent *me = static_cast<QMouseEvent *>(e);
// First, update the hovered URL
mHoveredUrl = mViewer->linkOrImageUrlAt(me->globalPos());
// If we are potentially handling a drag, deal with that.
if (mCanStartDrag && me->buttons() & Qt::LeftButton) {
if ((mLastClickPosition - me->pos()).manhattanLength() > QApplication::startDragDistance()) {
if (URLHandlerManager::instance()->handleDrag(mHoveredUrl, this)) {
// If the URL handler manager started a drag, don't handle this in the future
mCanStartDrag = false;
}
}
// Don't tell WebKit about this mouse move event, or it might start its own drag!
return true;
}
}
// standard event processing
return false;
}
void ViewerPrivate::slotWheelZoomChanged(int numSteps)
{
if (mZoomActionMenu) {
......@@ -1525,6 +1482,7 @@ void ViewerPrivate::createWidgets()
readerBoxVBoxLayout->addWidget(mTextToSpeechWidget);
mViewer = new MailWebEngineView(mActionCollection, readerBox);
mViewer->setViewer(this);
readerBoxVBoxLayout->addWidget(mViewer);
mViewer->setObjectName(QStringLiteral("mViewer"));
......@@ -2060,7 +2018,6 @@ void ViewerPrivate::slotUrlOn(const QString &link)
// The "link" we get here is not URL-encoded, and therefore there is no way QUrl could
// parse it correctly. To workaround that, we use QWebFrame::hitTestContent() on the mouse position
// to get the URL before WebKit managed to mangle it.
//TODO
QUrl url(link);
const QString protocol = url.scheme();
if (protocol == QLatin1String("kmail") ||
......@@ -2072,6 +2029,7 @@ void ViewerPrivate::slotUrlOn(const QString &link)
mViewer->setAcceptDrops(true);
}
mViewer->setLinkHovered(url);
if (link.trimmed().isEmpty()) {
KPIM::BroadcastStatus::instance()->reset();
Q_EMIT showStatusBarMessage(QString());
......
......@@ -291,9 +291,6 @@ private:
void initHtmlWidget();
void createOpenWithMenu(QMenu *topMenu, const QString &contentTypeStr, bool fromCurrentContent);
public:
/** Event filter */
bool eventFilter(QObject *obj, QEvent *ev) Q_DECL_OVERRIDE;
/** Read settings from app's config file. */
void readConfig();
......
......@@ -22,6 +22,7 @@
#include "webengineviewer/webenginescript.h"
#include "mailwebenginescript.h"
#include "messageviewer/messageviewersettings.h"
#include "../urlhandlermanager.h"
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
#include "blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h"
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
......@@ -66,15 +67,21 @@ public:
mWebViewAccessKey(Q_NULLPTR),
mExternalReference(Q_NULLPTR),
mPageEngine(Q_NULLPTR),
mNetworkAccessManager(Q_NULLPTR)
mNetworkAccessManager(Q_NULLPTR),
mViewer(Q_NULLPTR),
mCanStartDrag(false)
{
}
QUrl mHoveredUrl;
QPoint mLastClickPosition;
ScamDetectionWebEngine *mScamDetection;
WebEngineViewer::WebEngineAccessKey *mWebViewAccessKey;
MessageViewer::LoadExternalReferencesUrlInterceptor *mExternalReference;
MailWebEnginePage *mPageEngine;
WebEngineViewer::InterceptorManager *mNetworkAccessManager;
MessageViewer::ViewerPrivate *mViewer;
bool mCanStartDrag;
};
MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent)
......@@ -113,6 +120,11 @@ MailWebEngineView::~MailWebEngineView()
delete d;
}
void MailWebEngineView::setLinkHovered(const QUrl &url)
{
d->mHoveredUrl = url;
}
void MailWebEngineView::runJavaScriptInWordId(const QString &script)
{
#if QT_VERSION >= 0x050700
......@@ -122,6 +134,11 @@ void MailWebEngineView::runJavaScriptInWordId(const QString &script)
#endif
}
void MailWebEngineView::setViewer(MessageViewer::ViewerPrivate *viewer)
{
d->mViewer = viewer;
}
void MailWebEngineView::initializeScripts()
{
initializeJQueryScript();
......@@ -177,20 +194,42 @@ void MailWebEngineView::forwardKeyReleaseEvent(QKeyEvent *e)
void MailWebEngineView::forwardMousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event);
//qDebug()<<" void MailWebEngineView::forwardMousePressEvent(QMouseEvent *event)";
if (d->mViewer) {
if (event->button() == Qt::LeftButton && (event->modifiers() & Qt::ShiftModifier)) {
// special processing for shift+click
URLHandlerManager::instance()->handleShiftClick(d->mHoveredUrl, d->mViewer);
event->accept();
return;
}
if (event->button() == Qt::LeftButton) {
d->mCanStartDrag = URLHandlerManager::instance()->willHandleDrag(d->mHoveredUrl, d->mViewer);
d->mLastClickPosition = event->pos();
}
}
}
void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event)
{
Q_UNUSED(event);
//qDebug() << "void MailWebEngineView::forwardMouseMoveEvent(QMouseEvent *event)";
if (d->mViewer) {
// If we are potentially handling a drag, deal with that.
if (d->mCanStartDrag && event->buttons() & Qt::LeftButton) {
if ((d->mLastClickPosition - event->pos()).manhattanLength() > QApplication::startDragDistance()) {
if (URLHandlerManager::instance()->handleDrag(d->mHoveredUrl, d->mViewer)) {
// If the URL handler manager started a drag, don't handle this in the future
d->mCanStartDrag = false;
}
}
event->accept();
}
}
}
void MailWebEngineView::forwardMouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
//qDebug() << "void MailWebEngineView::forwardMouseReleaseEvent(QMouseEvent *event)";
d->mCanStartDrag = false;
}
void MailWebEngineView::forwardKeyPressEvent(QKeyEvent *e)
......@@ -372,13 +411,6 @@ void MailWebEngineView::scrollToRelativePosition(qreal pos)
runJavaScriptInWordId(WebEngineViewer::WebEngineScript::scrollToRelativePosition(pos));
}
QUrl MailWebEngineView::linkOrImageUrlAt(const QPoint &global) const
{
Q_UNUSED(global);
//TODO
return {};
}
void MailWebEngineView::setAllowExternalContent(bool b)
{
if (d->mExternalReference->allowExternalContent() != b) {
......@@ -397,25 +429,6 @@ void MailWebEngineView::slotLoadFinished()
scamCheck();
}
void MailWebEngineView::dragEnterEvent(QDragEnterEvent *event)
{
Q_UNUSED(event);
qDebug() << " void MailWebEngineView::dragEnterEvent(QDragEnterEvent *event)";
}
void MailWebEngineView::dragMoveEvent(QDragMoveEvent *e)
{
qDebug() << " void MailWebEngineView::dragMoveEvent(QDragMoveEvent *e)";
WebEngineViewer::WebEngineView::dragMoveEvent(e);
//TODO
}
void MailWebEngineView::dropEvent(QDropEvent *e)
{
Q_UNUSED(e);
qDebug() << " MailWebEngineView::dropEvent";
}
void MailWebEngineView::setPrintElementBackground(bool printElementBackground)
{
d->mPageEngine->setPrintElementBackground(printElementBackground);
......
......@@ -29,6 +29,7 @@ class WebHitTestResult;
}
namespace MessageViewer
{
class ViewerPrivate;
class MailWebEngineViewPrivate;
class MESSAGEVIEWER_EXPORT MailWebEngineView : public WebEngineViewer::WebEngineView
{
......@@ -59,7 +60,6 @@ public:
bool hasVerticalScrollBar() const;
bool isAttachmentInjectionPoint(const QPoint &globalPos) const;
void scrollToRelativePosition(qreal pos);
QUrl linkOrImageUrlAt(const QPoint &global) const;
void setAllowExternalContent(bool b);
......@@ -71,6 +71,8 @@ public:
void executeHideShowAttachmentsScripts(bool hide);
void executeHideShowToAddressScripts(bool hide);
void executeHideShowCcAddressScripts(bool hide);
void setLinkHovered(const QUrl &url);
void setViewer(MessageViewer::ViewerPrivate *viewer);
public Q_SLOTS:
void slotZoomChanged(qreal zoom);
void slotShowDetails();
......@@ -86,9 +88,6 @@ protected:
void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE;
void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE;
void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;
Q_SIGNALS:
void wheelZoomChanged(int numSteps);
void openUrl(const QUrl &url);
......
......@@ -108,6 +108,7 @@ void WebEngineView::forwardKeyReleaseEvent(QKeyEvent *event)
void WebEngineView::forwardMousePressEvent(QMouseEvent *event)
{
qDebug()<<" void WebEngineView::forwardMousePressEvent(QMouseEvent *event)";
Q_UNUSED(event);
}
......@@ -122,30 +123,6 @@ void WebEngineView::forwardMouseReleaseEvent(QMouseEvent *event)
Q_UNUSED(event);
}
void WebEngineView::dragMoveEvent(QDragMoveEvent *e)
{
qDebug() << " void WebEngineView::dragMoveEvent(QDragMoveEvent *e)";
QWebEngineView::dragMoveEvent(e);
}
void WebEngineView::dragEnterEvent(QDragEnterEvent *e)
{
qDebug() << " void WebEngineView::dragEnterEvent(QDragEnterEvent *event)";
QWebEngineView::dragEnterEvent(e);
}
void WebEngineView::dropEvent(QDropEvent *e)
{
qDebug() << " WebEngineView::dropEvent ";
QWebEngineView::dropEvent(e);
}
void WebEngineView::dragLeaveEvent(QDragLeaveEvent *e)
{
qDebug() << " WebEngineView::dragLeaveEvent ";
QWebEngineView::dragLeaveEvent(e);
}
bool WebEngineView::eventFilter(QObject *obj, QEvent *event)
{
// Hack to find widget that receives input events
......
......@@ -42,6 +42,7 @@ public:
void initializeJQueryScript();
WebEngineManageScript *webEngineManagerScript() const;
void setLinkHovered(const QUrl &url);
protected:
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
......@@ -53,11 +54,6 @@ protected:
virtual void forwardMousePressEvent(QMouseEvent *event);
virtual void forwardMouseMoveEvent(QMouseEvent *event);
virtual void forwardMouseReleaseEvent(QMouseEvent *event);
void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;
void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;
private:
WebEngineViewPrivate *const d;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment