1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

WebHitTestResult: Map position to page viewport coords

Closes #1927
This commit is contained in:
David Rosca 2016-04-06 17:22:44 +02:00
parent 9a415bf40a
commit d8682ff51d
6 changed files with 27 additions and 7 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - QtWebEngine based browser
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
* Copyright (C) 2015-2016 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -81,7 +81,8 @@ WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos)
"})()");
WebPage *p = const_cast<WebPage*>(page);
const QString &js = source.arg(pos.x()).arg(pos.y());
m_viewportPos = p->mapToViewport(m_pos);
const QString &js = source.arg(m_viewportPos.x()).arg(m_viewportPos.y());
init(page->url(), p->execJavaScript(js).toMap());
}
@ -145,6 +146,11 @@ QPoint WebHitTestResult::pos() const
return m_pos;
}
QPoint WebHitTestResult::viewportPos() const
{
return m_viewportPos;
}
QString WebHitTestResult::tagName() const
{
return m_tagName;

View File

@ -44,6 +44,7 @@ public:
bool mediaPaused() const;
bool mediaMuted() const;
QPoint pos() const;
QPoint viewportPos() const;
QString tagName() const;
private:
@ -61,6 +62,7 @@ private:
bool m_mediaPaused;
bool m_mediaMuted;
QPoint m_pos;
QPoint m_viewportPos;
QString m_tagName;
};

View File

@ -126,6 +126,11 @@ QVariant WebPage::execJavaScript(const QString &scriptSource, int timeout)
return result;
}
QPoint WebPage::mapToViewport(const QPoint &pos) const
{
return QPoint(pos.x() / zoomFactor(), pos.y() / zoomFactor());
}
WebHitTestResult WebPage::hitTestContent(const QPoint &pos) const
{
return WebHitTestResult(this, pos);

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2015 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -43,6 +43,7 @@ public:
QVariant execJavaScript(const QString &scriptSource, int timeout = 500);
QPoint mapToViewport(const QPoint &pos) const;
WebHitTestResult hitTestContent(const QPoint &pos) const;
void scroll(int x, int y);

View File

@ -222,6 +222,11 @@ void WebView::setZoomLevel(int level)
applyZoom();
}
QPoint WebView::mapToViewport(const QPoint &pos) const
{
return page()->mapToViewport(pos);
}
void WebView::restoreHistory(const QByteArray &data)
{
QDataStream stream(data);
@ -814,7 +819,6 @@ void WebView::createSelectedTextContextMenu(QMenu* menu, const WebHitTestResult
void WebView::createMediaContextMenu(QMenu *menu, const WebHitTestResult &hitTest)
{
m_clickedPos = hitTest.pos();
bool paused = hitTest.mediaPaused();
bool muted = hitTest.mediaMuted();
@ -829,10 +833,10 @@ void WebView::createMediaContextMenu(QMenu *menu, const WebHitTestResult &hitTes
void WebView::checkForForm(QAction *action, const QPoint &pos)
{
m_clickedPos = pos;
m_clickedPos = mapToViewport(pos);
QPointer<QAction> act = action;
page()->runJavaScript(Scripts::getFormData(pos), [this, act](const QVariant &res) {
page()->runJavaScript(Scripts::getFormData(m_clickedPos), [this, act](const QVariant &res) {
const QVariantMap &map = res.toMap();
if (!act || map.isEmpty())
return;

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -55,6 +55,8 @@ public:
int zoomLevel() const;
void setZoomLevel(int level);
QPoint mapToViewport(const QPoint &pos) const;
void restoreHistory(const QByteArray &data);
void addNotification(QWidget* notif);