summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/web_contents_adapter_client.h6
-rw-r--r--src/core/web_contents_view_qt.cpp4
-rw-r--r--src/webenginewidgets/api/qwebenginecontextmenudata.cpp220
-rw-r--r--src/webenginewidgets/api/qwebenginecontextmenudata.h97
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp119
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h4
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h3
-rw-r--r--src/webenginewidgets/webenginewidgets.pro4
8 files changed, 398 insertions, 59 deletions
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 9d2054859..559898411 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -79,8 +79,8 @@ public:
: mediaType(MediaTypeNone)
, hasImageContent(false)
, mediaFlags(0)
-#if defined(ENABLE_SPELLCHECK)
, isEditable(false)
+#if defined(ENABLE_SPELLCHECK)
, isSpellCheckerEnabled(false)
#endif
{
@@ -128,8 +128,8 @@ public:
bool hasImageContent;
uint mediaFlags;
QString suggestedFileName;
-#if defined(ENABLE_SPELLCHECK)
bool isEditable;
+#if defined(ENABLE_SPELLCHECK)
bool isSpellCheckerEnabled;
QString misspelledWord;
QStringList spellCheckerSuggestions;
@@ -226,7 +226,7 @@ public:
virtual bool isBeingAdopted() = 0;
virtual void close() = 0;
virtual void windowCloseRejected() = 0;
- virtual bool contextMenuRequested(const WebEngineContextMenuData&) = 0;
+ virtual bool contextMenuRequested(const WebEngineContextMenuData &) = 0;
virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) = 0;
virtual void requestFullScreenMode(const QUrl &origin, bool fullscreen) = 0;
virtual bool isFullScreenMode() const = 0;
diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp
index 370f1e78f..1d39d8af8 100644
--- a/src/core/web_contents_view_qt.cpp
+++ b/src/core/web_contents_view_qt.cpp
@@ -150,7 +150,7 @@ ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaControls, blink::WebContextMen
ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanPrint, blink::WebContextMenuData::MediaCanPrint)
ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanRotate, blink::WebContextMenuData::MediaCanRotate)
-static WebEngineContextMenuData fromParams(const content::ContextMenuParams &params)
+static inline WebEngineContextMenuData fromParams(const content::ContextMenuParams &params)
{
WebEngineContextMenuData ret;
ret.pos = QPoint(params.x, params.y);
@@ -162,8 +162,8 @@ static WebEngineContextMenuData fromParams(const content::ContextMenuParams &par
ret.hasImageContent = params.has_image_contents;
ret.mediaFlags = params.media_flags;
ret.suggestedFileName = toQt(params.suggested_filename.data());
-#if defined(ENABLE_SPELLCHECK)
ret.isEditable = params.is_editable;
+#if defined(ENABLE_SPELLCHECK)
ret.misspelledWord = toQt(params.misspelled_word);
ret.spellCheckerSuggestions = fromVector(params.dictionary_suggestions);
#endif
diff --git a/src/webenginewidgets/api/qwebenginecontextmenudata.cpp b/src/webenginewidgets/api/qwebenginecontextmenudata.cpp
new file mode 100644
index 000000000..1c5b53701
--- /dev/null
+++ b/src/webenginewidgets/api/qwebenginecontextmenudata.cpp
@@ -0,0 +1,220 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwebenginecontextmenudata.h"
+
+#include "web_contents_adapter_client.h"
+
+QT_BEGIN_NAMESPACE
+
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeNone, QWebEngineContextMenuData::MediaTypeNone)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeImage, QWebEngineContextMenuData::MediaTypeImage)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeAudio, QWebEngineContextMenuData::MediaTypeAudio)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeVideo, QWebEngineContextMenuData::MediaTypeVideo)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeCanvas, QWebEngineContextMenuData::MediaTypeCanvas)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypeFile, QWebEngineContextMenuData::MediaTypeFile)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebEngineContextMenuData::MediaTypePlugin, QWebEngineContextMenuData::MediaTypePlugin)
+
+/*!
+ \class QWebEngineContextMenuData
+ \since 5.7
+ \brief The QWebEngineContextMenuData class provides context data for populating or extending a context menu with actions.
+
+ \inmodule QtWebEngine
+
+ QWebEngineContextMenuData is returned by QWebEnginePage::contextMenuData() after a context menu event,
+ and contains information about where the context menu event took place. This is also in the context
+ in which any context specific QWebEnginePage::WebAction will be performed.
+*/
+
+/*!
+ \enum QWebEngineContextMenuData::MediaType
+
+ This enum describes the media type of the context if any.
+
+ \value MediaTypeNone The context is not a media type.
+ \value MediaTypeImage The context is an image element.
+ \value MediaTypeVideo The context is a video element.
+ \value MediaTypeAudio The context is an audio element.
+ \value MediaTypeCanvas The context is a canvas element.
+ \value MediaTypeFile The context is a file.
+ \value MediaTypePlugin The context is a plugin element.
+*/
+
+/*!
+ Constructs null context menu data.
+*/
+QWebEngineContextMenuData::QWebEngineContextMenuData() : d(nullptr)
+{
+}
+
+/*!
+ Constructs context menu data from \a other.
+*/
+QWebEngineContextMenuData::QWebEngineContextMenuData(const QWebEngineContextMenuData &other)
+{
+ d = new QtWebEngineCore::WebEngineContextMenuData(*other.d);
+}
+
+/*!
+ Assigns the \a other context menu data to this.
+*/
+QWebEngineContextMenuData &QWebEngineContextMenuData::operator=(const QWebEngineContextMenuData &other)
+{
+ delete d;
+ d = new QtWebEngineCore::WebEngineContextMenuData(*other.d);
+ return *this;
+}
+
+/*!
+ Destroys the context menu data.
+*/
+QWebEngineContextMenuData::~QWebEngineContextMenuData()
+{
+ delete d;
+}
+
+/*!
+ Returns \c true if the context data is valid; otherwise returns \c false.
+*/
+bool QWebEngineContextMenuData::isValid() const
+{
+ return d;
+}
+
+/*!
+ Resets the context data, making it invalid.
+
+ \sa isValid()
+*/
+void QWebEngineContextMenuData::reset()
+{
+ delete d;
+ d = nullptr;
+}
+
+/*!
+ Returns the position of the context, usually the mouse position where the context menu event was triggered.
+*/
+QPoint QWebEngineContextMenuData::pos() const
+{
+ return d ? d->pos : QPoint();
+}
+
+/*!
+ Returns the text of a link if the context is a link.
+*/
+QString QWebEngineContextMenuData::linkText() const
+{
+ return d ? d->linkText : QString();
+}
+
+/*!
+ Returns the URL of a link if the context is a link.
+*/
+QUrl QWebEngineContextMenuData::linkUrl() const
+{
+ return d ? d->linkUrl : QUrl();
+}
+
+/*!
+ Returns the selected text of the context.
+*/
+QString QWebEngineContextMenuData::selectedText() const
+{
+ return d ? d->selectedText : QString();
+}
+
+/*!
+ If the context is a media element, returns the URL of that media.
+*/
+QUrl QWebEngineContextMenuData::mediaUrl() const
+{
+ return d ? d->mediaUrl : QUrl();
+}
+
+/*!
+ Returns the type of the media element or \c MediaTypeNone if the context is not a media element.
+*/
+QWebEngineContextMenuData::MediaType QWebEngineContextMenuData::mediaType() const
+{
+ return d ? static_cast<QWebEngineContextMenuData::MediaType>(d->mediaType) : MediaTypeNone;
+}
+
+/*!
+ Returns \c true if the content is editable by the user; otherwise returns \c false.
+*/
+bool QWebEngineContextMenuData::isContentEditable() const
+{
+ return d ? d->isEditable : false;
+}
+
+#if !defined(QT_NO_SPELLCHECK)
+/*!
+ If the context is a word considered misspelled by the spell-checker, returns the misspelled word.
+*/
+QString QWebEngineContextMenuData::misspelledWord() const
+{
+ if (d)
+ return d->misspelledWord;
+ return QString();
+}
+
+/*!
+ If the context is a word considered misspelled by the spell-checker, returns a list of suggested replacements.
+*/
+QStringList QWebEngineContextMenuData::spellCheckerSuggestions() const
+{
+ if (d)
+ return d->spellCheckerSuggestions;
+ return QStringList();
+}
+#endif
+
+/*!
+ \internal
+*/
+QWebEngineContextMenuData &QWebEngineContextMenuData::operator=(const QWebEngineContextDataPrivate &priv)
+{
+ delete d;
+ d = new QtWebEngineCore::WebEngineContextMenuData(priv);
+ return *this;
+}
+
+QT_END_NAMESPACE
diff --git a/src/webenginewidgets/api/qwebenginecontextmenudata.h b/src/webenginewidgets/api/qwebenginecontextmenudata.h
new file mode 100644
index 000000000..751ad9753
--- /dev/null
+++ b/src/webenginewidgets/api/qwebenginecontextmenudata.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWEBENGINECONTEXTDATA_H
+#define QWEBENGINECONTEXTDATA_H
+
+#include <qtwebenginewidgetsglobal.h>
+#include <QtCore/QPoint>
+#include <QtCore/QString>
+#include <QtCore/QUrl>
+
+namespace QtWebEngineCore {
+class WebEngineContextMenuData;
+}
+
+QT_BEGIN_NAMESPACE
+
+class QWEBENGINEWIDGETS_EXPORT QWebEngineContextMenuData {
+public:
+ QWebEngineContextMenuData();
+ QWebEngineContextMenuData(const QWebEngineContextMenuData &other);
+ QWebEngineContextMenuData &operator=(const QWebEngineContextMenuData &other);
+ ~QWebEngineContextMenuData();
+
+ enum MediaType {
+ MediaTypeNone,
+ MediaTypeImage,
+ MediaTypeVideo,
+ MediaTypeAudio,
+ MediaTypeCanvas,
+ MediaTypeFile,
+ MediaTypePlugin
+ };
+ bool isValid() const;
+ void reset();
+
+ QPoint pos() const;
+ QString selectedText() const;
+ QString linkText() const;
+ QUrl linkUrl() const;
+ QUrl mediaUrl() const;
+ MediaType mediaType() const;
+ bool isContentEditable() const;
+
+#if !defined(QT_NO_SPELLCHECK)
+ QString misspelledWord() const;
+ QStringList spellCheckerSuggestions() const;
+#endif
+
+private:
+ typedef QtWebEngineCore::WebEngineContextMenuData QWebEngineContextDataPrivate;
+ QWebEngineContextMenuData &operator=(const QWebEngineContextDataPrivate &priv);
+ const QWebEngineContextDataPrivate *d;
+
+ friend class QWebEnginePagePrivate;
+ friend class QWebEnginePage;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWEBENGINECONTEXTDATA_H
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 7f7cba431..cb0359195 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -896,6 +896,7 @@ QAction *QWebEnginePage::action(WebAction action) const
void QWebEnginePage::triggerAction(WebAction action, bool)
{
Q_D(QWebEnginePage);
+ const QtWebEngineCore::WebEngineContextMenuData &menuData = *d->contextData.d;
switch (action) {
case Back:
d->adapter->navigateToOffset(-1);
@@ -937,122 +938,122 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
d->adapter->unselect();
break;
case OpenLinkInThisWindow:
- if (d->m_menuData.linkUrl.isValid())
- setUrl(d->m_menuData.linkUrl);
+ if (menuData.linkUrl.isValid())
+ setUrl(menuData.linkUrl);
break;
case OpenLinkInNewWindow:
- if (d->m_menuData.linkUrl.isValid()) {
+ if (menuData.linkUrl.isValid()) {
QWebEnginePage *newPage = createWindow(WebBrowserWindow);
if (newPage)
- newPage->setUrl(d->m_menuData.linkUrl);
+ newPage->setUrl(menuData.linkUrl);
}
break;
case OpenLinkInNewTab:
- if (d->m_menuData.linkUrl.isValid()) {
+ if (menuData.linkUrl.isValid()) {
QWebEnginePage *newPage = createWindow(WebBrowserTab);
if (newPage)
- newPage->setUrl(d->m_menuData.linkUrl);
+ newPage->setUrl(menuData.linkUrl);
}
break;
case OpenLinkInNewBackgroundTab:
- if (d->m_menuData.linkUrl.isValid()) {
+ if (menuData.linkUrl.isValid()) {
QWebEnginePage *newPage = createWindow(WebBrowserBackgroundTab);
if (newPage)
- newPage->setUrl(d->m_menuData.linkUrl);
+ newPage->setUrl(menuData.linkUrl);
}
break;
case CopyLinkToClipboard:
- if (d->m_menuData.linkUrl.isValid()) {
- QString urlString = d->m_menuData.linkUrl.toString(QUrl::FullyEncoded);
- QString title = d->m_menuData.linkText.toHtmlEscaped();
+ if (menuData.linkUrl.isValid()) {
+ QString urlString = menuData.linkUrl.toString(QUrl::FullyEncoded);
+ QString title = menuData.linkText.toHtmlEscaped();
QMimeData *data = new QMimeData();
data->setText(urlString);
QString html = QStringLiteral("<a href=\"") + urlString + QStringLiteral("\">") + title + QStringLiteral("</a>");
data->setHtml(html);
- data->setUrls(QList<QUrl>() << d->m_menuData.linkUrl);
+ data->setUrls(QList<QUrl>() << menuData.linkUrl);
qApp->clipboard()->setMimeData(data);
}
break;
case DownloadLinkToDisk:
- if (d->m_menuData.linkUrl.isValid())
- d->adapter->download(d->m_menuData.linkUrl, d->m_menuData.suggestedFileName);
+ if (menuData.linkUrl.isValid())
+ d->adapter->download(menuData.linkUrl, menuData.suggestedFileName);
break;
case CopyImageToClipboard:
- if (d->m_menuData.hasImageContent &&
- (d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeImage ||
- d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeCanvas))
+ if (menuData.hasImageContent &&
+ (menuData.mediaType == WebEngineContextMenuData::MediaTypeImage ||
+ menuData.mediaType == WebEngineContextMenuData::MediaTypeCanvas))
{
- d->adapter->copyImageAt(d->m_menuData.pos);
+ d->adapter->copyImageAt(menuData.pos);
}
break;
case CopyImageUrlToClipboard:
- if (d->m_menuData.mediaUrl.isValid() && d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeImage) {
- QString urlString = d->m_menuData.mediaUrl.toString(QUrl::FullyEncoded);
- QString title = d->m_menuData.linkText;
+ if (menuData.mediaUrl.isValid() && menuData.mediaType == WebEngineContextMenuData::MediaTypeImage) {
+ QString urlString = menuData.mediaUrl.toString(QUrl::FullyEncoded);
+ QString title = menuData.linkText;
if (!title.isEmpty())
title = QStringLiteral(" alt=\"%1\"").arg(title.toHtmlEscaped());
QMimeData *data = new QMimeData();
data->setText(urlString);
QString html = QStringLiteral("<img src=\"") + urlString + QStringLiteral("\"") + title + QStringLiteral("></img>");
data->setHtml(html);
- data->setUrls(QList<QUrl>() << d->m_menuData.mediaUrl);
+ data->setUrls(QList<QUrl>() << menuData.mediaUrl);
qApp->clipboard()->setMimeData(data);
}
break;
case DownloadImageToDisk:
case DownloadMediaToDisk:
- if (d->m_menuData.mediaUrl.isValid())
- d->adapter->download(d->m_menuData.mediaUrl, d->m_menuData.suggestedFileName);
+ if (menuData.mediaUrl.isValid())
+ d->adapter->download(menuData.mediaUrl, menuData.suggestedFileName);
break;
case CopyMediaUrlToClipboard:
- if (d->m_menuData.mediaUrl.isValid() &&
- (d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio ||
- d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeVideo))
+ if (menuData.mediaUrl.isValid() &&
+ (menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio ||
+ menuData.mediaType == WebEngineContextMenuData::MediaTypeVideo))
{
- QString urlString = d->m_menuData.mediaUrl.toString(QUrl::FullyEncoded);
+ QString urlString = menuData.mediaUrl.toString(QUrl::FullyEncoded);
QMimeData *data = new QMimeData();
data->setText(urlString);
- if (d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio)
+ if (menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio)
data->setHtml(QStringLiteral("<audio src=\"") + urlString + QStringLiteral("\"></audio>"));
else
data->setHtml(QStringLiteral("<video src=\"") + urlString + QStringLiteral("\"></video>"));
- data->setUrls(QList<QUrl>() << d->m_menuData.mediaUrl);
+ data->setUrls(QList<QUrl>() << menuData.mediaUrl);
qApp->clipboard()->setMimeData(data);
}
break;
case ToggleMediaControls:
- if (d->m_menuData.mediaUrl.isValid() && d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaCanToggleControls) {
- bool enable = !(d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaControls);
- d->adapter->executeMediaPlayerActionAt(d->m_menuData.pos, WebContentsAdapter::MediaPlayerControls, enable);
+ if (menuData.mediaUrl.isValid() && menuData.mediaFlags & WebEngineContextMenuData::MediaCanToggleControls) {
+ bool enable = !(menuData.mediaFlags & WebEngineContextMenuData::MediaControls);
+ d->adapter->executeMediaPlayerActionAt(menuData.pos, WebContentsAdapter::MediaPlayerControls, enable);
}
break;
case ToggleMediaLoop:
- if (d->m_menuData.mediaUrl.isValid() &&
- (d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio ||
- d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeVideo))
+ if (menuData.mediaUrl.isValid() &&
+ (menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio ||
+ menuData.mediaType == WebEngineContextMenuData::MediaTypeVideo))
{
- bool enable = !(d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaLoop);
- d->adapter->executeMediaPlayerActionAt(d->m_menuData.pos, WebContentsAdapter::MediaPlayerLoop, enable);
+ bool enable = !(menuData.mediaFlags & WebEngineContextMenuData::MediaLoop);
+ d->adapter->executeMediaPlayerActionAt(menuData.pos, WebContentsAdapter::MediaPlayerLoop, enable);
}
break;
case ToggleMediaPlayPause:
- if (d->m_menuData.mediaUrl.isValid() &&
- (d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio ||
- d->m_menuData.mediaType == WebEngineContextMenuData::MediaTypeVideo))
+ if (menuData.mediaUrl.isValid() &&
+ (menuData.mediaType == WebEngineContextMenuData::MediaTypeAudio ||
+ menuData.mediaType == WebEngineContextMenuData::MediaTypeVideo))
{
- bool enable = (d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaPaused);
- d->adapter->executeMediaPlayerActionAt(d->m_menuData.pos, WebContentsAdapter::MediaPlayerPlay, enable);
+ bool enable = (menuData.mediaFlags & WebEngineContextMenuData::MediaPaused);
+ d->adapter->executeMediaPlayerActionAt(menuData.pos, WebContentsAdapter::MediaPlayerPlay, enable);
}
break;
case ToggleMediaMute:
- if (d->m_menuData.mediaUrl.isValid() && d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaHasAudio) {
+ if (menuData.mediaUrl.isValid() && menuData.mediaFlags & WebEngineContextMenuData::MediaHasAudio) {
// Make sure to negate the value, so that toggling actually works.
- bool enable = !(d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaMuted);
- d->adapter->executeMediaPlayerActionAt(d->m_menuData.pos, WebContentsAdapter::MediaPlayerMute, enable);
+ bool enable = !(menuData.mediaFlags & WebEngineContextMenuData::MediaMuted);
+ d->adapter->executeMediaPlayerActionAt(menuData.pos, WebContentsAdapter::MediaPlayerMute, enable);
}
break;
case InspectElement:
- d->adapter->inspectElementAt(d->m_menuData.pos);
+ d->adapter->inspectElementAt(menuData.pos);
break;
case ExitFullScreen:
d->adapter->exitFullScreen();
@@ -1114,13 +1115,13 @@ bool QWebEnginePagePrivate::contextMenuRequested(const WebEngineContextMenuData
if (!view || !view->d_func()->m_pendingContextMenuEvent)
return false;
- m_menuData = WebEngineContextMenuData();
+ contextData.reset();
QContextMenuEvent event(QContextMenuEvent::Mouse, data.pos, view->mapToGlobal(data.pos));
switch (view->contextMenuPolicy()) {
case Qt::PreventContextMenu:
return false;
case Qt::DefaultContextMenu:
- m_menuData = data;
+ contextData = data;
view->contextMenuEvent(&event);
break;
case Qt::CustomContextMenu:
@@ -1258,7 +1259,7 @@ QMenu *QWebEnginePage::createStandardContextMenu()
Q_D(QWebEnginePage);
QMenu *menu = new QMenu(d->view);
QAction *action = 0;
- WebEngineContextMenuData contextMenuData(d->m_menuData);
+ const WebEngineContextMenuData &contextMenuData = *d->contextData.d;
#if !defined(QT_NO_SPELLCHECK)
if (contextMenuData.isEditable && !contextMenuData.spellCheckerSuggestions.isEmpty()) {
@@ -1319,9 +1320,9 @@ QMenu *QWebEnginePage::createStandardContextMenu()
menu->addAction(QWebEnginePage::action(CopyMediaUrlToClipboard));
menu->addAction(QWebEnginePage::action(ToggleMediaPlayPause));
menu->addAction(QWebEnginePage::action(ToggleMediaLoop));
- if (d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaHasAudio)
+ if (contextMenuData.mediaFlags & WebEngineContextMenuData::MediaHasAudio)
menu->addAction(QWebEnginePage::action(ToggleMediaMute));
- if (d->m_menuData.mediaFlags & WebEngineContextMenuData::MediaCanToggleControls)
+ if (contextMenuData.mediaFlags & WebEngineContextMenuData::MediaCanToggleControls)
menu->addAction(QWebEnginePage::action(ToggleMediaControls));
break;
default:
@@ -1672,6 +1673,20 @@ void QWebEnginePage::printToPdf(const QPageLayout &pageLayout, const QWebEngineC
d->m_callbacks.registerCallback(requestId, resultCallback);
}
+/*!
+ \since 5.7
+
+ Returns additional data about the current context menu. It is only guaranteed to be valid during the call to the QWebEngineView::contextMenuEvent()
+ handler of the associated QWebEngineView.
+
+ \sa createStandardContextMenu()
+*/
+const QWebEngineContextMenuData &QWebEnginePage::contextMenuData() const
+{
+ Q_D(const QWebEnginePage);
+ return d->contextData;
+}
+
QT_END_NAMESPACE
#include "moc_qwebenginepage.cpp"
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index 8d6da4459..6ca79e946 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -54,6 +54,7 @@
QT_BEGIN_NAMESPACE
class QMenu;
class QWebChannel;
+class QWebEngineContextMenuData;
class QWebEngineFullScreenRequest;
class QWebEngineHistory;
class QWebEnginePage;
@@ -274,6 +275,9 @@ public:
#else
void printToPdf(const QPageLayout &layout, const QWebEngineCallback<const QByteArray&> &resultCallback);
#endif
+
+ const QWebEngineContextMenuData &contextMenuData() const;
+
Q_SIGNALS:
void loadStarted();
void loadProgress(int progress);
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index b08c19821..de7d35354 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -54,6 +54,7 @@
#include "qwebenginepage.h"
#include "qwebenginecallback_p.h"
+#include "qwebenginecontextmenudata.h"
#include "qwebenginescriptcollection.h"
#include "web_contents_adapter_client.h"
#include <QtCore/qcompilerdetection.h>
@@ -156,7 +157,7 @@ public:
QWebEngineSettings *settings;
QWebEngineView *view;
QUrl explicitUrl;
- QtWebEngineCore::WebEngineContextMenuData m_menuData;
+ QWebEngineContextMenuData contextData;
bool isLoading;
QWebEngineScriptCollection scriptCollection;
bool m_isBeingAdopted;
diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro
index 3b6b843b6..e3f02433c 100644
--- a/src/webenginewidgets/webenginewidgets.pro
+++ b/src/webenginewidgets/webenginewidgets.pro
@@ -11,6 +11,7 @@ INCLUDEPATH += $$PWD api ../core ../core/api ../webengine/api
SOURCES = \
api/qtwebenginewidgetsglobal.cpp \
api/qwebenginecertificateerror.cpp \
+ api/qwebenginecontextmenudata.cpp \
api/qwebenginedownloaditem.cpp \
api/qwebenginefullscreenrequest.cpp \
api/qwebenginehistory.cpp \
@@ -24,9 +25,10 @@ SOURCES = \
HEADERS = \
api/qtwebenginewidgetsglobal.h \
+ api/qwebenginecertificateerror.h \
+ api/qwebenginecontextmenudata.h \
api/qwebenginedownloaditem.h \
api/qwebenginedownloaditem_p.h \
- api/qwebenginecertificateerror.h \
api/qwebenginefullscreenrequest.h \
api/qwebenginehistory.h \
api/qwebenginepage.h \