mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
WebHitTestResult: Use data from QWebEngineContextMenuData
Fixes handling context menus in iframes. Closes #2126
This commit is contained in:
parent
4d51b4c00c
commit
1a110c3641
@ -92,8 +92,7 @@ void PopupWebView::_contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
m_menu->clear();
|
||||
|
||||
const WebHitTestResult hitTest = page()->hitTestContent(event->pos());
|
||||
|
||||
WebHitTestResult hitTest = page()->hitTestContent(event->pos());
|
||||
createContextMenu(m_menu, hitTest);
|
||||
|
||||
if (WebInspector::isEnabled()) {
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "webhittestresult.h"
|
||||
#include "webpage.h"
|
||||
|
||||
#include <QWebEngineContextMenuData>
|
||||
|
||||
WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos)
|
||||
: m_isNull(true)
|
||||
, m_isContentEditable(false)
|
||||
@ -87,6 +89,32 @@ WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos)
|
||||
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
|
||||
{
|
||||
return m_baseUrl;
|
||||
@ -167,6 +195,7 @@ void WebHitTestResult::init(const QUrl &url, const QVariantMap &map)
|
||||
if (map.isEmpty())
|
||||
return;
|
||||
|
||||
m_isNull = false;
|
||||
m_baseUrl = map.value(QSL("baseUrl")).toUrl();
|
||||
m_alternateText = map.value(QSL("alternateText")).toString();
|
||||
m_imageUrl = map.value(QSL("imageUrl")).toUrl();
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QWebEngineContextMenuData;
|
||||
|
||||
class WebPage;
|
||||
|
||||
class QUPZILLA_EXPORT WebHitTestResult
|
||||
@ -32,6 +34,8 @@ class QUPZILLA_EXPORT WebHitTestResult
|
||||
public:
|
||||
explicit WebHitTestResult(const WebPage *page, const QPoint &pos);
|
||||
|
||||
void updateWithContextMenuData(const QWebEngineContextMenuData &data);
|
||||
|
||||
QUrl baseUrl() const;
|
||||
QString alternateText() const;
|
||||
QRect boundingRect() const;
|
||||
|
@ -609,14 +609,15 @@ void WebView::userDefinedOpenUrlInBgTab(const QUrl &url)
|
||||
userDefinedOpenUrlInNewTab(actionUrl, true);
|
||||
}
|
||||
|
||||
void WebView::createContextMenu(QMenu *menu, const WebHitTestResult &hitTest)
|
||||
void WebView::createContextMenu(QMenu *menu, WebHitTestResult &hitTest)
|
||||
{
|
||||
// cppcheck-suppress variableScope
|
||||
int spellCheckActionCount = 0;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
|
||||
const QWebEngineContextMenuData &contextMenuData = page()->contextMenuData();
|
||||
hitTest.updateWithContextMenuData(contextMenuData);
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
|
||||
if (!contextMenuData.misspelledWord().isEmpty()) {
|
||||
QFont boldFont = menu->font();
|
||||
boldFont.setBold(true);
|
||||
|
@ -152,7 +152,7 @@ protected:
|
||||
void loadRequest(const LoadRequest &req);
|
||||
void applyZoom();
|
||||
|
||||
void createContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
|
||||
void createContextMenu(QMenu *menu, WebHitTestResult &hitTest);
|
||||
void createPageContextMenu(QMenu *menu);
|
||||
void createLinkContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
|
||||
void createImageContextMenu(QMenu *menu, const WebHitTestResult &hitTest);
|
||||
|
@ -199,8 +199,7 @@ void TabbedWebView::_contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
m_menu->clear();
|
||||
|
||||
const WebHitTestResult hitTest = page()->hitTestContent(event->pos());
|
||||
|
||||
WebHitTestResult hitTest = page()->hitTestContent(event->pos());
|
||||
createContextMenu(m_menu, hitTest);
|
||||
|
||||
if (!hitTest.isContentEditable() && !hitTest.isContentSelected() && m_window) {
|
||||
|
Loading…
Reference in New Issue
Block a user