summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core_chromium.pri2
-rw-r--r--src/core/render_view_context_menu_qt.cpp224
-rw-r--r--src/core/render_view_context_menu_qt.h120
-rw-r--r--src/core/web_contents_adapter_client.h24
-rw-r--r--src/core/web_contents_view_qt.cpp12
5 files changed, 382 insertions, 0 deletions
diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri
index 7a7e3ab02..08552800d 100644
--- a/src/core/core_chromium.pri
+++ b/src/core/core_chromium.pri
@@ -79,6 +79,7 @@ SOURCES = \
qrc_protocol_handler_qt.cpp \
quota_permission_context_qt.cpp \
quota_permission_controller.cpp \
+ render_view_context_menu_qt.cpp \
render_view_observer_host_qt.cpp \
render_widget_host_view_qt.cpp \
renderer/content_renderer_client_qt.cpp \
@@ -161,6 +162,7 @@ HEADERS = \
quota_permission_context_qt.h \
quota_permission_controller.h \
quota_permission_controller_p.h \
+ render_view_context_menu_qt.h \
render_view_observer_host_qt.h \
render_widget_host_view_qt.h \
render_widget_host_view_qt_delegate.h \
diff --git a/src/core/render_view_context_menu_qt.cpp b/src/core/render_view_context_menu_qt.cpp
new file mode 100644
index 000000000..4e182973c
--- /dev/null
+++ b/src/core/render_view_context_menu_qt.cpp
@@ -0,0 +1,224 @@
+/****************************************************************************
+**
+** 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 <QtCore/QCoreApplication>
+#include "render_view_context_menu_qt.h"
+
+namespace QtWebEngineCore {
+
+ const QString RenderViewContextMenuQt::getMenuItemName(RenderViewContextMenuQt::ContextMenuItem menuItem) {
+ Q_ASSERT(menuItem <= ContextMenuItem::ViewSource);
+ static const char *names[ContextMenuItem::ViewSource + 1] = {
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Back"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Forward"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Reload"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Cut"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Copy"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Paste"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Undo"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Redo"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Select all"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Paste and match style"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Open link in new window"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Open link in new tab"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Copy link address"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Save link"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Copy image"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Copy image address"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Save image"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Copy media address"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Show controls"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Loop"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Save media"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Inspect"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Exit full screen"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "Save page"),
+ QT_TRANSLATE_NOOP("RenderViewContextMenuQt", "View page source")
+ };
+ return QCoreApplication::translate("RenderViewContextMenuQt", qUtf8Printable(names[menuItem]));
+ }
+
+ RenderViewContextMenuQt::RenderViewContextMenuQt(const WebEngineContextMenuData &data)
+ : m_contextData(data)
+ {
+ }
+
+ void RenderViewContextMenuQt::initMenu()
+ {
+ if (isFullScreenMode()) {
+ appendExitFullscreenItem();
+ appendSeparatorItem();
+ }
+
+ if (m_contextData.isEditable() && !m_contextData.spellCheckerSuggestions().isEmpty()) {
+ appendSpellingSuggestionItems();
+ appendSeparatorItem();
+ }
+
+ if (m_contextData.linkText().isEmpty() && !m_contextData.linkUrl().isValid() && !m_contextData.mediaUrl().isValid()) {
+ if (m_contextData.isEditable())
+ appendEditableItems();
+ else if (!m_contextData.selectedText().isEmpty())
+ appendCopyItem();
+ else
+ appendPageItems();
+ }
+
+ if (m_contextData.linkUrl().isValid() || !m_contextData.unfilteredLinkUrl().isEmpty() || !m_contextData.linkUrl().isEmpty())
+ appendLinkItems();
+
+ if (m_contextData.mediaUrl().isValid()) {
+ switch (m_contextData.mediaType()) {
+ case WebEngineContextMenuData::MediaTypeImage:
+ appendSeparatorItem();
+ appendImageItems();
+ break;
+ case WebEngineContextMenuData::MediaTypeCanvas:
+ Q_UNREACHABLE(); // mediaUrl is invalid for canvases
+ break;
+ case WebEngineContextMenuData::MediaTypeAudio:
+ case WebEngineContextMenuData::MediaTypeVideo:
+ appendSeparatorItem();
+ appendMediaItems();
+ break;
+ default:
+ break;
+ }
+ } else if (m_contextData.mediaType() == WebEngineContextMenuData::MediaTypeCanvas) {
+ appendSeparatorItem();
+ appendCanvasItems();
+ }
+
+ if (canViewSource() || hasInspector()) {
+ appendSeparatorItem();
+ appendDeveloperItems();
+ }
+ }
+
+ void RenderViewContextMenuQt::appendCanvasItems()
+ {
+ addMenuItem(RenderViewContextMenuQt::DownloadImageToDisk);
+ addMenuItem(RenderViewContextMenuQt::CopyImageToClipboard);
+ }
+
+ void RenderViewContextMenuQt::appendCopyItem()
+ {
+ addMenuItem(RenderViewContextMenuQt::Copy);
+ }
+
+ void RenderViewContextMenuQt::appendDeveloperItems()
+ {
+ if (canViewSource())
+ addMenuItem(RenderViewContextMenuQt::ViewSource);
+ if (hasInspector())
+ addMenuItem(RenderViewContextMenuQt::InspectElement);
+ }
+
+ void RenderViewContextMenuQt::appendEditableItems()
+ {
+ addMenuItem(RenderViewContextMenuQt::Undo);
+ addMenuItem(RenderViewContextMenuQt::Redo);
+ appendSeparatorItem();
+ addMenuItem(RenderViewContextMenuQt::Cut);
+ addMenuItem(RenderViewContextMenuQt::Copy);
+ addMenuItem(RenderViewContextMenuQt::Paste);
+ if (m_contextData.misspelledWord().isEmpty()) {
+ addMenuItem(RenderViewContextMenuQt::PasteAndMatchStyle);
+ addMenuItem(RenderViewContextMenuQt::SelectAll);
+ }
+ }
+
+ void RenderViewContextMenuQt::appendExitFullscreenItem()
+ {
+ addMenuItem(RenderViewContextMenuQt::ExitFullScreen);
+ }
+
+ void RenderViewContextMenuQt::appendImageItems()
+ {
+ addMenuItem(RenderViewContextMenuQt::DownloadImageToDisk);
+ addMenuItem(RenderViewContextMenuQt::CopyImageToClipboard);
+ addMenuItem(RenderViewContextMenuQt::CopyImageUrlToClipboard);
+ }
+
+ void RenderViewContextMenuQt::appendLinkItems()
+ {
+ addMenuItem(RenderViewContextMenuQt::OpenLinkInNewTab);
+ addMenuItem(RenderViewContextMenuQt::OpenLinkInNewWindow);
+ appendSeparatorItem();
+ addMenuItem(RenderViewContextMenuQt::DownloadLinkToDisk);
+ addMenuItem(RenderViewContextMenuQt::CopyLinkToClipboard);
+ }
+
+ void RenderViewContextMenuQt::appendMediaItems()
+ {
+ addMenuItem(RenderViewContextMenuQt::ToggleMediaLoop);
+ if (m_contextData.mediaFlags() & QtWebEngineCore::WebEngineContextMenuData::MediaCanToggleControls)
+ addMenuItem(RenderViewContextMenuQt::ToggleMediaControls);
+ addMenuItem(RenderViewContextMenuQt::DownloadMediaToDisk);
+ addMenuItem(RenderViewContextMenuQt::CopyMediaUrlToClipboard);
+ }
+
+ void RenderViewContextMenuQt::appendPageItems()
+ {
+ addMenuItem(RenderViewContextMenuQt::Back);
+ addMenuItem(RenderViewContextMenuQt::Forward);
+ addMenuItem(RenderViewContextMenuQt::Reload);
+ appendSeparatorItem();
+ addMenuItem(RenderViewContextMenuQt::SavePage);
+ }
+
+ void RenderViewContextMenuQt::appendSpellingSuggestionItems()
+ {
+ addMenuItem(RenderViewContextMenuQt::SpellingSuggestions);
+ }
+
+ void RenderViewContextMenuQt::appendSeparatorItem()
+ {
+ addMenuItem(RenderViewContextMenuQt::Separator);
+ }
+
+ bool RenderViewContextMenuQt::canViewSource()
+ {
+ return m_contextData.linkText().isEmpty()
+ && !m_contextData.linkUrl().isValid()
+ && !m_contextData.mediaUrl().isValid()
+ && !m_contextData.isEditable()
+ && m_contextData.selectedText().isEmpty();
+ }
+}
diff --git a/src/core/render_view_context_menu_qt.h b/src/core/render_view_context_menu_qt.h
new file mode 100644
index 000000000..1694f66e6
--- /dev/null
+++ b/src/core/render_view_context_menu_qt.h
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** 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 RENDER_VIEW_CONTEXT_MENU_QT_H
+#define RENDER_VIEW_CONTEXT_MENU_QT_H
+
+#include "web_contents_adapter_client.h"
+
+namespace QtWebEngineCore {
+
+class QWEBENGINE_EXPORT RenderViewContextMenuQt
+{
+public:
+ enum ContextMenuItem {
+ Back = 0,
+ Forward,
+ Reload,
+
+ Cut,
+ Copy,
+ Paste,
+
+ Undo,
+ Redo,
+ SelectAll,
+
+ PasteAndMatchStyle,
+
+ OpenLinkInNewWindow,
+ OpenLinkInNewTab,
+ CopyLinkToClipboard,
+ DownloadLinkToDisk,
+
+ CopyImageToClipboard,
+ CopyImageUrlToClipboard,
+ DownloadImageToDisk,
+
+ CopyMediaUrlToClipboard,
+ ToggleMediaControls,
+ ToggleMediaLoop,
+ DownloadMediaToDisk,
+
+ InspectElement,
+ ExitFullScreen,
+ SavePage,
+ ViewSource,
+
+ SpellingSuggestions,
+
+ Separator
+ };
+
+ static const QString getMenuItemName(RenderViewContextMenuQt::ContextMenuItem menuItem);
+
+ RenderViewContextMenuQt(const WebEngineContextMenuData &data);
+ void initMenu();
+
+protected:
+ virtual bool hasInspector() = 0;
+ virtual bool isFullScreenMode() = 0;
+
+ virtual void addMenuItem(ContextMenuItem menuItem) = 0;
+ virtual bool isMenuItemEnabled(ContextMenuItem menuItem) = 0;
+
+ const WebEngineContextMenuData &m_contextData;
+
+private:
+ void appendCanvasItems();
+ void appendCopyItem();
+ void appendEditableItems();
+ void appendExitFullscreenItem();
+ void appendDeveloperItems();
+ void appendImageItems();
+ void appendLinkItems();
+ void appendMediaItems();
+ void appendPageItems();
+ void appendSpellingSuggestionItems();
+ void appendSeparatorItem();
+ bool canViewSource();
+};
+
+}
+
+#endif // RENDER_VIEW_CONTEXT_MENU_QT_H
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index d6de9dfe6..dfb2dddcc 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -95,6 +95,7 @@ public:
, isSpellCheckerEnabled(false)
, mediaType(0)
, mediaFlags(0)
+ , editFlags(0)
{
}
bool hasImageContent;
@@ -102,6 +103,7 @@ public:
bool isSpellCheckerEnabled;
uint mediaType;
uint mediaFlags;
+ uint editFlags;
QPoint pos;
QUrl linkUrl;
QUrl unfilteredLinkUrl;
@@ -155,6 +157,20 @@ public:
MediaCanRotate = 0x200,
};
+ // Must match blink::WebContextMenuData::EditFlags:
+ enum EditFlags {
+ CanDoNone = 0x0,
+ CanUndo = 0x1,
+ CanRedo = 0x2,
+ CanCut = 0x4,
+ CanCopy = 0x8,
+ CanPaste = 0x10,
+ CanDelete = 0x20,
+ CanSelectAll = 0x40,
+ CanTranslate = 0x80,
+ CanEditRichly = 0x100,
+ };
+
WebEngineContextMenuData():d(new WebEngineContextMenuSharedData) {
}
@@ -230,6 +246,14 @@ public:
return MediaFlags(d->mediaFlags);
}
+ void setEditFlags(EditFlags flags) {
+ d->editFlags = flags;
+ }
+
+ EditFlags editFlags() const {
+ return EditFlags(d->editFlags);
+ }
+
void setSuggestedFileName(const QString &filename) {
d->suggestedFileName = filename;
}
diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp
index 28f202e24..0ad3c1c38 100644
--- a/src/core/web_contents_view_qt.cpp
+++ b/src/core/web_contents_view_qt.cpp
@@ -158,6 +158,17 @@ ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaControls, blink::WebContextMen
ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanPrint, blink::WebContextMenuData::kMediaCanPrint)
ASSERT_ENUMS_MATCH(WebEngineContextMenuData::MediaCanRotate, blink::WebContextMenuData::kMediaCanRotate)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanDoNone, blink::WebContextMenuData::kCanDoNone)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanUndo, blink::WebContextMenuData::kCanUndo)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanRedo, blink::WebContextMenuData::kCanRedo)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanCut, blink::WebContextMenuData::kCanCut)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanCopy, blink::WebContextMenuData::kCanCopy)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanPaste, blink::WebContextMenuData::kCanPaste)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanDelete, blink::WebContextMenuData::kCanDelete)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanSelectAll, blink::WebContextMenuData::kCanSelectAll)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanTranslate, blink::WebContextMenuData::kCanTranslate)
+ASSERT_ENUMS_MATCH(WebEngineContextMenuData::CanEditRichly, blink::WebContextMenuData::kCanEditRichly)
+
static inline WebEngineContextMenuData fromParams(const content::ContextMenuParams &params)
{
WebEngineContextMenuData ret;
@@ -170,6 +181,7 @@ static inline WebEngineContextMenuData fromParams(const content::ContextMenuPara
ret.setMediaType((WebEngineContextMenuData::MediaType)params.media_type);
ret.setHasImageContent(params.has_image_contents);
ret.setMediaFlags((WebEngineContextMenuData::MediaFlags)params.media_flags);
+ ret.setEditFlags((WebEngineContextMenuData::EditFlags)params.edit_flags);
ret.setSuggestedFileName(toQt(params.suggested_filename.data()));
ret.setIsEditable(params.is_editable);
#if BUILDFLAG(ENABLE_SPELLCHECK)