diff options
author | Valentin Fokin <fokinv@inf.u-szeged.hu> | 2018-05-30 14:46:15 +0200 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2018-08-02 14:17:17 +0000 |
commit | 1481e8d87fe89d9e27d9de593767b55a0e84a31f (patch) | |
tree | 7ff04c22c4c880ec8d0951255772ce8b2c49bf3a /src/webengine/api | |
parent | 6a5f8d69fc1d090326fa92a0b24bd494369c2d0d (diff) |
Introduce WebEngineAction in Quick API
Also implement QQuickWebEngineView::action() method similar to the Widget API
to access the WebEngineActions.
[ChangeLog][QtWebEngine] Introduce WebEngineAction in Quick API
Task-number: QTBUG-56117
Change-Id: I758cd4703db4c111c1ed9187e091d4c845486c46
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'src/webengine/api')
-rw-r--r-- | src/webengine/api/qquickwebengineaction.cpp | 172 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineaction_p.h | 108 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineaction_p_p.h | 86 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview.cpp | 282 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p.h | 2 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineview_p_p.h | 2 |
6 files changed, 606 insertions, 46 deletions
diff --git a/src/webengine/api/qquickwebengineaction.cpp b/src/webengine/api/qquickwebengineaction.cpp new file mode 100644 index 000000000..ce2fe6357 --- /dev/null +++ b/src/webengine/api/qquickwebengineaction.cpp @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 "qquickwebengineaction_p.h" +#include "qquickwebengineaction_p_p.h" +#include "qquickwebengineview_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype WebEngineAction + \instantiates QQuickWebEngineAction + \inqmlmodule QtWebEngine + \since QtWebEngine 1.8 + + \brief An action that represents a \l WebEngineView::WebAction + + A WebEngineAction is returned by the \l WebEngineView::action() + method. It provides information about the action, such as + whether it is \l enabled. + + The following code uses the \l WebEngineView::action() method to check if the + the copy action is enabled: + + \code + var copyAction = webEngineView.action(WebEngineView.Copy); + if (copyAction.enabled) + console.log("Copy is enabled."); + else + console.log("Copy is disabled."); + \endcode +*/ + +QQuickWebEngineActionPrivate::QQuickWebEngineActionPrivate(const QVariant &data, const QString &text, const QString &iconText, bool enabled) + : m_data(data) + , m_text(text) + , m_iconText(iconText) + , m_enabled(enabled) +{ +} + +QQuickWebEngineActionPrivate::~QQuickWebEngineActionPrivate() +{ +} + +void QQuickWebEngineActionPrivate::setEnabled(bool enabled) +{ + Q_Q(QQuickWebEngineAction); + if (m_enabled == enabled) + return; + m_enabled = enabled; + emit q->enabledChanged(enabled); +} + +QVariant QQuickWebEngineActionPrivate::data() const +{ + return m_data; +} + +void QQuickWebEngineActionPrivate::trigger() +{ + Q_Q(QQuickWebEngineAction); + if (QQuickWebEngineView *view = static_cast<QQuickWebEngineView*>(q->parent())) { + view->triggerWebAction(static_cast<QQuickWebEngineView::WebAction>(data().toInt())); + } +} + +QQuickWebEngineAction::QQuickWebEngineAction(const QVariant &data, const QString &text, const QString &iconText, bool enabled, QObject *parent) + : QObject(parent) + , d_ptr(new QQuickWebEngineActionPrivate(data, text, iconText, enabled)) +{ + d_ptr->q_ptr = this; +} + +QQuickWebEngineAction::QQuickWebEngineAction(QObject *parent) + : QObject(parent) + , d_ptr(new QQuickWebEngineActionPrivate(-1, QStringLiteral(""), QStringLiteral(""), false)) +{ + d_ptr->q_ptr = this; +} + +QQuickWebEngineAction::~QQuickWebEngineAction() +{ +} + +/*! + \qmlproperty int WebEngineAction::text + + This property holds a textual description of the action. +*/ +QString QQuickWebEngineAction::text() const +{ + Q_D(const QQuickWebEngineAction); + return d->m_text; +} + +/*! + \qmlproperty string WebEngineAction::iconText + + This property holds the action's descriptive icon text +*/ +QString QQuickWebEngineAction::iconText() const +{ + Q_D(const QQuickWebEngineAction); + return d->m_iconText; +} + +/*! + \qmlproperty bool WebEngineAction::enabled + + This property holds whether the action is enabled. +*/ +bool QQuickWebEngineAction::isEnabled() const +{ + Q_D(const QQuickWebEngineAction); + return d->m_enabled; +} + +/*! + \qmlmethod void WebEngineAction::trigger() + + Triggers the action. +*/ +void QQuickWebEngineAction::trigger() +{ + Q_D(QQuickWebEngineAction); + if (!isEnabled()) + return; + + d->trigger(); + emit triggered(); +} + +QT_END_NAMESPACE + diff --git a/src/webengine/api/qquickwebengineaction_p.h b/src/webengine/api/qquickwebengineaction_p.h new file mode 100644 index 000000000..5296f9dd6 --- /dev/null +++ b/src/webengine/api/qquickwebengineaction_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 QQUICKWEBENGINEACTION_P_H +#define QQUICKWEBENGINEACTION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QObject> +#include <QtQml/qqml.h> +#include "qtwebengineglobal_p.h" +#include <QVariant> + +namespace QtWebEngineCore { + class UIDelegatesManager; + class UI2DelegatesManager; +} + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineActionPrivate; + +class Q_WEBENGINE_EXPORT QQuickWebEngineAction : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString text READ text CONSTANT FINAL) + Q_PROPERTY(QString iconText READ iconText CONSTANT FINAL) + Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged FINAL) + +public: + QQuickWebEngineAction(const QVariant &data, const QString &text, const QString &iconText, bool enabled, QObject *parent); + QQuickWebEngineAction(QObject *parent); + ~QQuickWebEngineAction(); + + QString text() const; + QString iconText() const; + bool isEnabled() const; + +public Q_SLOTS: + Q_INVOKABLE void trigger(); + +Q_SIGNALS: + void toggled(); + void triggered(); + void enabledChanged(const bool enabled); + +private: + Q_DECLARE_PRIVATE(QQuickWebEngineAction) + friend class QQuickWebEngineView; + friend class QQuickWebEngineViewPrivate; + friend class QtWebEngineCore::UIDelegatesManager; + friend class QtWebEngineCore::UI2DelegatesManager; + friend class QQuickContextMenuBuilder; + + QScopedPointer<QQuickWebEngineActionPrivate> d_ptr; +}; + + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickWebEngineAction) + +#endif // QQUICKWEBENGINEACTION_P_H diff --git a/src/webengine/api/qquickwebengineaction_p_p.h b/src/webengine/api/qquickwebengineaction_p_p.h new file mode 100644 index 000000000..cb1817e55 --- /dev/null +++ b/src/webengine/api/qquickwebengineaction_p_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 QQUICKWEBENGINEACTION_P_P_H +#define QQUICKWEBENGINEACTION_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QObject> +#include "qtwebengineglobal_p.h" +#include <QVariant> + +QT_BEGIN_NAMESPACE + +class QQuickWebEngineAction; + +class QQuickWebEngineActionPrivate +{ +public: + Q_DECLARE_PUBLIC(QQuickWebEngineAction) + QQuickWebEngineActionPrivate(const QVariant &data, const QString &text, const QString &iconText, bool enabled); + ~QQuickWebEngineActionPrivate(); + + void setEnabled(bool enabled); + + QVariant data() const; + + void trigger(); + +private: + QQuickWebEngineAction *q_ptr; + + QVariant m_data; + QString m_text; + QString m_iconText; + bool m_enabled; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBENGINEACTION_P_P_H diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 9c999e290..aaa8d58c5 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -45,6 +45,9 @@ #include "certificate_error_controller.h" #include "file_picker_controller.h" #include "javascript_dialog_controller.h" + +#include "qquickwebengineaction_p.h" +#include "qquickwebengineaction_p_p.h" #include "qquickwebenginehistory_p.h" #include "qquickwebenginecertificateerror_p.h" #include "qquickwebenginecontextmenurequest_p.h" @@ -126,6 +129,7 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() , m_ui2Enabled(false) { m_profile->d_ptr->addWebContentsAdapterClient(this); + memset(actions, 0, sizeof(actions)); QString platform = qApp->platformName().toLower(); if (platform == QLatin1Literal("eglfs")) m_ui2Enabled = true; @@ -803,6 +807,39 @@ void QQuickWebEngineViewPrivate::setFullScreenMode(bool fullscreen) } } +void QQuickWebEngineViewPrivate::updateAction(QQuickWebEngineView::WebAction action) const +{ + QQuickWebEngineAction *a = actions[action]; + if (!a) + return; + + bool enabled = true; + + switch (action) { + case QQuickWebEngineView::Back: + enabled = adapter->canGoBack(); + break; + case QQuickWebEngineView::Forward: + enabled = adapter->canGoForward(); + break; + case QQuickWebEngineView::Stop: + enabled = isLoading; + break; + case QQuickWebEngineView::Reload: + case QQuickWebEngineView::ReloadAndBypassCache: + enabled = !isLoading; + break; + case QQuickWebEngineView::ViewSource: + enabled = adapter->canViewSource(); + break; + default: + break; + } + + a->d_ptr->setEnabled(enabled); +} + + QUrl QQuickWebEngineView::url() const { Q_D(const QQuickWebEngineView); @@ -1650,6 +1687,170 @@ void QQuickWebEngineView::triggerWebAction(WebAction action) } } +QQuickWebEngineAction *QQuickWebEngineView::action(WebAction action) +{ + Q_D(QQuickWebEngineView); + if (action == QQuickWebEngineView::NoWebAction) + return nullptr; + if (d->actions[action]) { + d->updateAction(action); + return d->actions[action]; + } + + QString text; + QString iconText; + + switch (action) { + case Back: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Back); + iconText = QStringLiteral("go-previous"); + break; + case Forward: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Forward); + iconText = QStringLiteral("go-next"); + break; + case Stop: + text = tr("Stop"); + break; + case Reload: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Reload); + iconText = QStringLiteral("view-refresh"); + break; + case ReloadAndBypassCache: + text = tr("Reload and Bypass Cache"); + break; + case Cut: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Cut); + iconText = QStringLiteral("Cut"); + break; + case Copy: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Copy); + break; + case Paste: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Paste); + break; + case Undo: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Undo); + break; + case Redo: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::Redo); + break; + case SelectAll: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::SelectAll); + break; + case PasteAndMatchStyle: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::PasteAndMatchStyle); + break; + case OpenLinkInThisWindow: + text = tr("Open link in this window"); + break; + case OpenLinkInNewWindow: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::OpenLinkInNewWindow); + break; + case OpenLinkInNewTab: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::OpenLinkInNewTab); + break; + case CopyLinkToClipboard: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyLinkToClipboard); + break; + case DownloadLinkToDisk: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::DownloadLinkToDisk); + break; + case CopyImageToClipboard: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyImageToClipboard); + break; + case CopyImageUrlToClipboard: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyImageUrlToClipboard); + break; + case DownloadImageToDisk: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::DownloadImageToDisk); + break; + case CopyMediaUrlToClipboard: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::CopyMediaUrlToClipboard); + break; + case ToggleMediaControls: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ToggleMediaControls); + break; + case ToggleMediaLoop: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ToggleMediaLoop); + break; + case ToggleMediaPlayPause: + text = tr("Toggle Play/Pause"); + break; + case ToggleMediaMute: + text = tr("Toggle Mute"); + break; + case DownloadMediaToDisk: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::DownloadMediaToDisk); + break; + case InspectElement: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::InspectElement); + break; + case ExitFullScreen: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ExitFullScreen); + break; + case RequestClose: + text = tr("Close Page"); + break; + case Unselect: + text = tr("Unselect"); + break; + case SavePage: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::SavePage); + break; + case ViewSource: + text = RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem::ViewSource); + iconText = QStringLiteral("view-source"); + break; + case ToggleBold: + text = tr("&Bold"); + break; + case ToggleItalic: + text = tr("&Italic"); + break; + case ToggleUnderline: + text = tr("&Underline"); + break; + case ToggleStrikethrough: + text = tr("&Strikethrough"); + break; + case AlignLeft: + text = tr("Align &Left"); + break; + case AlignCenter: + text = tr("Align &Center"); + break; + case AlignRight: + text = tr("Align &Right"); + break; + case AlignJustified: + text = tr("Align &Justified"); + break; + case Indent: + text = tr("&Indent"); + break; + case Outdent: + text = tr("&Outdent"); + break; + case InsertOrderedList: + text = tr("Insert &Ordered List"); + break; + case InsertUnorderedList: + text = tr("Insert &Unordered List"); + break; + case NoWebAction: + case WebActionCount: + Q_UNREACHABLE(); + break; + } + + QQuickWebEngineAction *retVal = new QQuickWebEngineAction(action, text, iconText, false, this); + + d->actions[action] = retVal; + d->updateAction(action); + return retVal; +} + QSizeF QQuickWebEngineView::contentsSize() const { Q_D(const QQuickWebEngineView); @@ -1778,112 +1979,101 @@ bool QQuickContextMenuBuilder::isFullScreenMode() void QQuickContextMenuBuilder::addMenuItem(ContextMenuItem menuItem) { - MenuItemHandler *item = new MenuItemHandler(m_menu); - QString menuItemIcon; - QPointer<QQuickWebEngineView> thisRef(m_view); + QQuickWebEngineAction *action = nullptr; switch (menuItem) { case ContextMenuItem::Back: - QObject::connect(item, &MenuItemHandler::triggered, thisRef, &QQuickWebEngineView::goBack); - menuItemIcon = QStringLiteral("go-previous"); + action = m_view->action(QQuickWebEngineView::Back); break; case ContextMenuItem::Forward: - QObject::connect(item, &MenuItemHandler::triggered, thisRef, &QQuickWebEngineView::goForward); - menuItemIcon = QStringLiteral("go-next"); + action = m_view->action(QQuickWebEngineView::Forward); break; case ContextMenuItem::Reload: - QObject::connect(item, &MenuItemHandler::triggered, thisRef, &QQuickWebEngineView::reload); - menuItemIcon = QStringLiteral("view-refresh"); + action = m_view->action(QQuickWebEngineView::Reload); break; case ContextMenuItem::Cut: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Cut); }); - menuItemIcon = QStringLiteral("Cut"); + action = m_view->action(QQuickWebEngineView::Cut); break; case ContextMenuItem::Copy: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Copy); }); - menuItemIcon = QStringLiteral("Copy"); + action = m_view->action(QQuickWebEngineView::Copy); break; - case ContextMenuItem::Paste: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Paste); }); - menuItemIcon = QStringLiteral("Paste"); + action = m_view->action(QQuickWebEngineView::Paste); break; case ContextMenuItem::Undo: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Undo); }); - menuItemIcon = QStringLiteral("Undo"); + action = m_view->action(QQuickWebEngineView::Undo); break; case ContextMenuItem::Redo: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::Redo); }); - menuItemIcon = QStringLiteral("Redo"); + action = m_view->action(QQuickWebEngineView::Redo); break; case ContextMenuItem::SelectAll: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::SelectAll); }); - menuItemIcon = QStringLiteral("Select All"); + action = m_view->action(QQuickWebEngineView::SelectAll); break; case ContextMenuItem::PasteAndMatchStyle: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::PasteAndMatchStyle); }); - menuItemIcon = QStringLiteral("Paste And Match Style"); + action = m_view->action(QQuickWebEngineView::PasteAndMatchStyle); break; case ContextMenuItem::OpenLinkInNewWindow: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::OpenLinkInNewWindow); }); + action = m_view->action(QQuickWebEngineView::OpenLinkInNewWindow); break; case ContextMenuItem::OpenLinkInNewTab: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::OpenLinkInNewTab); }); + action = m_view->action(QQuickWebEngineView::OpenLinkInNewTab); break; case ContextMenuItem::CopyLinkToClipboard: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyLinkToClipboard); }); + action = m_view->action(QQuickWebEngineView::CopyLinkToClipboard); break; case ContextMenuItem::DownloadLinkToDisk: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::DownloadLinkToDisk); }); + action = m_view->action(QQuickWebEngineView::DownloadLinkToDisk); break; case ContextMenuItem::CopyImageToClipboard: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyImageToClipboard); }); + action = m_view->action(QQuickWebEngineView::CopyImageToClipboard); break; case ContextMenuItem::CopyImageUrlToClipboard: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyImageUrlToClipboard); }); + action = m_view->action(QQuickWebEngineView::CopyImageUrlToClipboard); break; case ContextMenuItem::DownloadImageToDisk: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::DownloadImageToDisk); }); + action = m_view->action(QQuickWebEngineView::DownloadImageToDisk); break; case ContextMenuItem::CopyMediaUrlToClipboard: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::CopyMediaUrlToClipboard); }); + action = m_view->action(QQuickWebEngineView::CopyMediaUrlToClipboard); break; case ContextMenuItem::ToggleMediaControls: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ToggleMediaControls); }); + action = m_view->action(QQuickWebEngineView::ToggleMediaControls); break; case ContextMenuItem::ToggleMediaLoop: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ToggleMediaLoop); }); + action = m_view->action(QQuickWebEngineView::ToggleMediaLoop); break; case ContextMenuItem::DownloadMediaToDisk: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::DownloadMediaToDisk); }); + action = m_view->action(QQuickWebEngineView::DownloadMediaToDisk); break; case ContextMenuItem::InspectElement: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::InspectElement); }); + action = m_view->action(QQuickWebEngineView::InspectElement); break; case ContextMenuItem::ExitFullScreen: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ExitFullScreen); }); + action = m_view->action(QQuickWebEngineView::ExitFullScreen); break; case ContextMenuItem::SavePage: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::SavePage); }); + action = m_view->action(QQuickWebEngineView::SavePage); break; case ContextMenuItem::ViewSource: - QObject::connect(item, &MenuItemHandler::triggered, [thisRef] { thisRef->triggerWebAction(QQuickWebEngineView::ViewSource); }); - menuItemIcon = QStringLiteral("view-source"); + action = m_view->action(QQuickWebEngineView::ViewSource); break; case ContextMenuItem::SpellingSuggestions: + { + QPointer<QQuickWebEngineView> thisRef(m_view); for (int i=0; i < m_contextData.spellCheckerSuggestions().count() && i < 4; i++) { - item = new MenuItemHandler(m_menu); + action = new QQuickWebEngineAction(m_menu); QString replacement = m_contextData.spellCheckerSuggestions().at(i); - QObject::connect(item, &MenuItemHandler::triggered, [thisRef, replacement] { thisRef->replaceMisspelledWord(replacement); }); - m_view->d_ptr->ui()->addMenuItem(item, replacement); + QObject::connect(action, &QQuickWebEngineAction::triggered, [thisRef, replacement] { thisRef->replaceMisspelledWord(replacement); }); + m_view->d_ptr->ui()->addMenuItem(action, m_menu); } return; + } case ContextMenuItem::Separator: - thisRef->d_ptr->ui()->addMenuSeparator(m_menu); + m_view->d_ptr->ui()->addMenuSeparator(m_menu); return; } - QString menuItemName = RenderViewContextMenuQt::getMenuItemName(menuItem); - thisRef->d_ptr->ui()->addMenuItem(item, menuItemName, menuItemIcon, isMenuItemEnabled(menuItem)); + action->d_ptr->setEnabled(isMenuItemEnabled(menuItem)); + m_view->d_ptr->ui()->addMenuItem(action, m_menu); } bool QQuickContextMenuBuilder::isMenuItemEnabled(ContextMenuItem menuItem) diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h index 0ca0c7886..d400fc75e 100644 --- a/src/webengine/api/qquickwebengineview_p.h +++ b/src/webengine/api/qquickwebengineview_p.h @@ -62,6 +62,7 @@ QT_BEGIN_NAMESPACE class QQmlWebChannel; class QQuickContextMenuBuilder; +class QQuickWebEngineAction; class QQuickWebEngineAuthenticationDialogRequest; class QQuickWebEngineCertificateError; class QQuickWebEngineColorDialogRequest; @@ -470,6 +471,7 @@ public: QQuickWebEngineHistory *navigationHistory() const; uint webChannelWorld() const; void setWebChannelWorld(uint); + Q_REVISION(8) Q_INVOKABLE QQuickWebEngineAction *action(WebAction action); bool isAudioMuted() const; void setAudioMuted(bool muted); diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 062125e70..7f52c7216 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -155,6 +155,7 @@ public: QtWebEngineCore::ProfileAdapter *profileAdapter() override; QtWebEngineCore::WebContentsAdapter *webContentsAdapter() override; + void updateAction(QQuickWebEngineView::WebAction) const; void adoptWebContents(QtWebEngineCore::WebContentsAdapter *webContents); void setProfile(QQuickWebEngineProfile *profile); void ensureContentsAdapter(); @@ -191,6 +192,7 @@ public: QPointer<QQuickWebEngineView> devToolsView; uint m_webChannelWorld; bool m_isBeingAdopted; + mutable QQuickWebEngineAction *actions[QQuickWebEngineView::WebActionCount]; private: QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager; |