1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

WebHitTestResult: Use data from QWebEngineContextMenuData

Fixes handling context menus in iframes.

Closes #2126
This commit is contained in:
David Rosca 2016-12-26 17:23:52 +01:00
parent 4d51b4c00c
commit 1a110c3641
6 changed files with 39 additions and 7 deletions

View File

@ -92,8 +92,7 @@ void PopupWebView::_contextMenuEvent(QContextMenuEvent *event)
{ {
m_menu->clear(); m_menu->clear();
const WebHitTestResult hitTest = page()->hitTestContent(event->pos()); WebHitTestResult hitTest = page()->hitTestContent(event->pos());
createContextMenu(m_menu, hitTest); createContextMenu(m_menu, hitTest);
if (WebInspector::isEnabled()) { if (WebInspector::isEnabled()) {

View File

@ -18,6 +18,8 @@
#include "webhittestresult.h" #include "webhittestresult.h"
#include "webpage.h" #include "webpage.h"
#include <QWebEngineContextMenuData>
WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos) WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos)
: m_isNull(true) : m_isNull(true)
, m_isContentEditable(false) , m_isContentEditable(false)
@ -87,6 +89,32 @@ WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos)
init(p->url(), p->execJavaScript(js, WebPage::SafeJsWorld).toMap()); init(p->url(), p->execJavaScript(js, WebPage::SafeJsWorld).toMap());
} }
void WebHitTestResult::updateWithContextMenuData(const QWebEngineContextMenuData &data)
{
if (!data.isValid()) {
return;
}
m_linkTitle = data.linkText();
m_linkUrl = data.linkUrl();
m_isContentEditable = data.isContentEditable();
m_isContentSelected = !data.selectedText().isEmpty();
switch (data.mediaType()) {
case QWebEngineContextMenuData::MediaTypeImage:
m_imageUrl = data.mediaUrl();
break;
case QWebEngineContextMenuData::MediaTypeVideo:
case QWebEngineContextMenuData::MediaTypeAudio:
m_mediaUrl = data.mediaUrl();
break;
default:
break;
}
}
QUrl WebHitTestResult::baseUrl() const QUrl WebHitTestResult::baseUrl() const
{ {
return m_baseUrl; return m_baseUrl;
@ -167,6 +195,7 @@ void WebHitTestResult::init(const QUrl &url, const QVariantMap &map)
if (map.isEmpty()) if (map.isEmpty())
return; return;
m_isNull = false;
m_baseUrl = map.value(QSL("baseUrl")).toUrl(); m_baseUrl = map.value(QSL("baseUrl")).toUrl();
m_alternateText = map.value(QSL("alternateText")).toString(); m_alternateText = map.value(QSL("alternateText")).toString();
m_imageUrl = map.value(QSL("imageUrl")).toUrl(); m_imageUrl = map.value(QSL("imageUrl")).toUrl();

View File

@ -25,6 +25,8 @@
#include "qzcommon.h" #include "qzcommon.h"
class QWebEngineContextMenuData;
class WebPage; class WebPage;
class QUPZILLA_EXPORT WebHitTestResult class QUPZILLA_EXPORT WebHitTestResult
@ -32,6 +34,8 @@ class QUPZILLA_EXPORT WebHitTestResult
public: public:
explicit WebHitTestResult(const WebPage *page, const QPoint &pos); explicit WebHitTestResult(const WebPage *page, const QPoint &pos);
void updateWithContextMenuData(const QWebEngineContextMenuData &data);
QUrl baseUrl() const; QUrl baseUrl() const;
QString alternateText() const; QString alternateText() const;
QRect boundingRect() const; QRect boundingRect() const;

View File

@ -609,14 +609,15 @@ void WebView::userDefinedOpenUrlInBgTab(const QUrl &url)
userDefinedOpenUrlInNewTab(actionUrl, true); userDefinedOpenUrlInNewTab(actionUrl, true);
} }
void WebView::createContextMenu(QMenu *menu, const WebHitTestResult &hitTest) void WebView::createContextMenu(QMenu *menu, WebHitTestResult &hitTest)
{ {
// cppcheck-suppress variableScope // cppcheck-suppress variableScope
int spellCheckActionCount = 0; int spellCheckActionCount = 0;
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
const QWebEngineContextMenuData &contextMenuData = page()->contextMenuData(); const QWebEngineContextMenuData &contextMenuData = page()->contextMenuData();
hitTest.updateWithContextMenuData(contextMenuData);
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
if (!contextMenuData.misspelledWord().isEmpty()) { if (!contextMenuData.misspelledWord().isEmpty()) {
QFont boldFont = menu->font(); QFont boldFont = menu->font();
boldFont.setBold(true); boldFont.setBold(true);

View File

@ -152,7 +152,7 @@ protected:
void loadRequest(const LoadRequest &req); void loadRequest(const LoadRequest &req);
void applyZoom(); void applyZoom();
void createContextMenu(QMenu *menu, const WebHitTestResult &hitTest); void createContextMenu(QMenu *menu, WebHitTestResult &hitTest);
void createPageContextMenu(QMenu *menu); void createPageContextMenu(QMenu *menu);
void createLinkContextMenu(QMenu *menu, const WebHitTestResult &hitTest); void createLinkContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
void createImageContextMenu(QMenu *menu, const WebHitTestResult &hitTest); void createImageContextMenu(QMenu *menu, const WebHitTestResult &hitTest);

View File

@ -199,8 +199,7 @@ void TabbedWebView::_contextMenuEvent(QContextMenuEvent *event)
{ {
m_menu->clear(); m_menu->clear();
const WebHitTestResult hitTest = page()->hitTestContent(event->pos()); WebHitTestResult hitTest = page()->hitTestContent(event->pos());
createContextMenu(m_menu, hitTest); createContextMenu(m_menu, hitTest);
if (!hitTest.isContentEditable() && !hitTest.isContentSelected() && m_window) { if (!hitTest.isContentEditable() && !hitTest.isContentSelected() && m_window) {