Commit 9d32ddd9 authored by Laurent Montel's avatar Laurent Montel 😁

Fix async method

parent 5802ea2c
......@@ -18,7 +18,7 @@ include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
set(MESSAGELIB_LIB_VERSION "5.1.76")
set(MESSAGELIB_LIB_VERSION "5.1.77")
set(KF5_VERSION "5.19.0")
set(KDEPIMLIBS_LIB_VERSION "5.1.42")
......
......@@ -54,23 +54,27 @@ TestWebEngineView::TestWebEngineView(QWidget *parent)
setContextMenuPolicy(Qt::DefaultContextMenu);
}
void TestWebEngineView::slotHitTestFinished(const MessageViewer::WebHitTestResult &result)
{
qDebug() << " alternateText" << result.alternateText();
qDebug() << " boundingRect" << result.boundingRect();
qDebug() << " imageUrl" << result.imageUrl();
qDebug() << " isContentEditable" << result.isContentEditable();
qDebug() << " isContentSelected" << result.isContentSelected();
qDebug() << " isNull" << result.isNull();
qDebug() << " linkTitle" << result.linkTitle();
qDebug() << " linkUrl" << result.linkUrl();
qDebug() << " mediaUrl" << result.mediaUrl();
qDebug() << " mediaPaused" << result.mediaPaused();
qDebug() << " mediaMuted" << result.mediaMuted();
qDebug() << " pos" << result.pos();
qDebug() << " tagName" << result.tagName();
}
void TestWebEngineView::contextMenuEvent(QContextMenuEvent *e)
{
qDebug() << " void TestWebEngine::contextMenuEvent(QContextMenuEvent *e)";
MessageViewer::WebHitTestResult *webHit = static_cast<MessageViewer::WebEnginePage *>(page())->hitTestContent(e->pos());
qDebug() << " alternateText" << webHit->alternateText();
qDebug() << " boundingRect" << webHit->boundingRect();
qDebug() << " imageUrl" << webHit->imageUrl();
qDebug() << " isContentEditable" << webHit->isContentEditable();
qDebug() << " isContentSelected" << webHit->isContentSelected();
qDebug() << " isNull" << webHit->isNull();
qDebug() << " linkTitle" << webHit->linkTitle();
qDebug() << " linkUrl" << webHit->linkUrl();
qDebug() << " mediaUrl" << webHit->mediaUrl();
qDebug() << " mediaPaused" << webHit->mediaPaused();
qDebug() << " mediaMuted" << webHit->mediaMuted();
qDebug() << " pos" << webHit->pos();
qDebug() << " tagName" << webHit->tagName();
delete webHit;
MessageViewer::WebHitTest *webHit = static_cast<MessageViewer::WebEnginePage *>(page())->hitTestContent(e->pos());
connect(webHit, &MessageViewer::WebHitTest::finished, this, &TestWebEngineView::slotHitTestFinished);
}
......@@ -23,6 +23,7 @@
namespace MessageViewer
{
class WebEnginePage;
class WebHitTestResult;
}
class TestWebEngineView : public QWebEngineView
......@@ -32,6 +33,8 @@ public:
explicit TestWebEngineView(QWidget *parent = Q_NULLPTR);
protected:
void contextMenuEvent(QContextMenuEvent *e);
private Q_SLOTS:
void slotHitTestFinished(const MessageViewer::WebHitTestResult &result);
};
class TestWebEngine : public QWidget
......
......@@ -45,9 +45,9 @@ WebEnginePage::~WebEnginePage()
delete d;
}
MessageViewer::WebHitTestResult *WebEnginePage::hitTestContent(const QPoint &pos)
MessageViewer::WebHitTest *WebEnginePage::hitTestContent(const QPoint &pos)
{
return new WebHitTestResult(this, pos);
return new WebHitTest(this, pos);
}
QVariant WebEnginePage::execJavaScript(const QString &scriptSource, int timeout)
......
......@@ -23,6 +23,7 @@
#include <QVariant>
namespace MessageViewer
{
class WebHitTest;
class WebHitTestResult;
class WebEnginePagePrivate;
class MESSAGEVIEWER_EXPORT WebEnginePage : public QWebEnginePage
......@@ -31,7 +32,7 @@ class MESSAGEVIEWER_EXPORT WebEnginePage : public QWebEnginePage
public:
explicit WebEnginePage(QObject *parent = Q_NULLPTR);
~WebEnginePage();
WebHitTestResult *hitTestContent(const QPoint &pos);
MessageViewer::WebHitTest *hitTestContent(const QPoint &pos);
QVariant execJavaScript(const QString &scriptSource, int timeout = 500);
private:
......
......@@ -33,7 +33,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "webhittestresult.h"
#include "webenginepage.h"
#include <QWebEnginePage>
using namespace MessageViewer;
......@@ -57,13 +56,8 @@ InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFunction)(Arg))
return wrapper;
}
WebHitTestResult::WebHitTestResult(WebEnginePage *page, const QPoint &pos, QObject *parent)
WebHitTest::WebHitTest(QWebEnginePage *page, const QPoint &pos, QObject *parent)
: QObject(parent),
m_isNull(true),
m_isContentEditable(false),
m_isContentSelected(false),
m_mediaPaused(false),
m_mediaMuted(false),
m_pos(pos)
{
QString source = QStringLiteral("(function() {"
......@@ -121,19 +115,31 @@ WebHitTestResult::WebHitTestResult(WebEnginePage *page, const QPoint &pos, QObje
"})()");
const QString &js = source.arg(pos.x()).arg(pos.y());
//init(page->url(), page->execJavaScript(js).toMap());
m_pageUrl = page->url();
page->runJavaScript(js, invoke(this, &WebHitTestResult::handleHitTest));
page->runJavaScript(js, invoke(this, &WebHitTest::handleHitTest));
}
WebHitTest::~WebHitTest()
{
}
WebHitTestResult::~WebHitTestResult()
void WebHitTest::handleHitTest(const QVariant &result)
{
const WebHitTestResult webHitResult(m_pos, m_pageUrl, result);
Q_EMIT finished(webHitResult);
deleteLater();
}
void WebHitTestResult::handleHitTest(const QVariant &result)
WebHitTestResult::WebHitTestResult(const QPoint &pos, const QUrl &url, const QVariant &result)
: m_isNull(true),
m_isContentEditable(false),
m_isContentSelected(false),
m_mediaPaused(false),
m_mediaMuted(false),
m_pos(pos),
m_pageUrl(url)
{
qDebug()<<" result" <<result.toMap();
//init(result.toMap());
init(result.toMap());
}
QString WebHitTestResult::alternateText() const
......@@ -206,7 +212,7 @@ void WebHitTestResult::init(const QVariantMap &map)
if (map.isEmpty()) {
return;
}
qDebug()<<" void WebHitTestResult::init(const QVariantMap &map)"<<map;
m_alternateText = map.value(QStringLiteral("alternateText")).toString();
m_imageUrl = map.value(QStringLiteral("imageUrl")).toUrl();
m_isContentEditable = map.value(QStringLiteral("contentEditable")).toBool();
......@@ -223,9 +229,11 @@ void WebHitTestResult::init(const QVariantMap &map)
m_boundingRect = QRect(rect.at(0).toInt(), rect.at(1).toInt(), rect.at(2).toInt(), rect.at(3).toInt());
}
qDebug()<<" m_imageUrl"<<m_imageUrl;
if (!m_imageUrl.isEmpty()) {
m_imageUrl = m_pageUrl.resolved(m_imageUrl);
}
qDebug()<<" after "<< m_imageUrl;
if (!m_linkUrl.isEmpty()) {
m_linkUrl = m_pageUrl.resolved(m_linkUrl);
}
......
......@@ -41,16 +41,15 @@
#include <QRect>
#include <QString>
#include <QVariantMap>
class QWebEnginePage;
namespace MessageViewer
{
class WebEnginePage;
class MESSAGEVIEWER_EXPORT WebHitTestResult : public QObject
class MESSAGEVIEWER_EXPORT WebHitTestResult
{
Q_OBJECT
public:
explicit WebHitTestResult(MessageViewer::WebEnginePage *page, const QPoint &pos, QObject *parent = Q_NULLPTR);
~WebHitTestResult();
WebHitTestResult(const QPoint &pos, const QUrl &url, const QVariant &result);
QString alternateText() const;
QRect boundingRect() const;
QUrl imageUrl() const;
......@@ -65,11 +64,6 @@ public:
QPoint pos() const;
QString tagName() const;
Q_SIGNALS:
void finished(WebHitTestResult *);
private Q_SLOTS:
void handleHitTest(const QVariant &result);
private:
void init(const QVariantMap &map);
......@@ -87,6 +81,24 @@ private:
QPoint m_pos;
QString m_tagName;
QUrl m_pageUrl;
};
class MESSAGEVIEWER_EXPORT WebHitTest : public QObject
{
Q_OBJECT
public:
explicit WebHitTest(QWebEnginePage *page, const QPoint &pos, QObject *parent = Q_NULLPTR);
~WebHitTest();
Q_SIGNALS:
void finished(const WebHitTestResult &result);
private Q_SLOTS:
void handleHitTest(const QVariant &result);
private:
QPoint m_pos;
QUrl m_pageUrl;
};
}
#endif // WEBHITTESTRESULT_H
Markdown is supported
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