summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-06-27 16:52:21 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-06-27 16:52:35 +0200
commitec5a99b0515779ff5ec3df6bd657127b4e037823 (patch)
treec5dc52e8892b6740123469276dcb303a81d9fd56 /src/webenginewidgets
parent56bea56b2d8fabc4b09d41531177a22d9297ce2c (diff)
parent722732d1f089630ad517aef8f94325a51186b274 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp36
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h2
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp7
3 files changed, 45 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index bb0db402b..db1915b9f 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -83,6 +83,8 @@
#include <QStyle>
#include <QUrl>
+#include <private/qguiapplication_p.h>
+
QT_BEGIN_NAMESPACE
using namespace QtWebEngineCore;
@@ -103,6 +105,27 @@ static QWebEnginePage::WebWindowType toWindowType(WebContentsAdapterClient::Wind
}
}
+QWebEnginePage::WebAction editorActionForKeyEvent(QKeyEvent* event)
+{
+ static struct {
+ QKeySequence::StandardKey standardKey;
+ QWebEnginePage::WebAction action;
+ } editorActions[] = {
+ { QKeySequence::Cut, QWebEnginePage::Cut },
+ { QKeySequence::Copy, QWebEnginePage::Copy },
+ { QKeySequence::Paste, QWebEnginePage::Paste },
+ { QKeySequence::Undo, QWebEnginePage::Undo },
+ { QKeySequence::Redo, QWebEnginePage::Redo },
+ { QKeySequence::SelectAll, QWebEnginePage::SelectAll },
+ { QKeySequence::UnknownKey, QWebEnginePage::NoWebAction }
+ };
+ for (int i = 0; editorActions[i].standardKey != QKeySequence::UnknownKey; ++i)
+ if (event == editorActions[i].standardKey)
+ return editorActions[i].action;
+
+ return QWebEnginePage::NoWebAction;
+}
+
QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile)
: adapter(new WebContentsAdapter)
, history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this)))
@@ -244,6 +267,19 @@ void QWebEnginePagePrivate::focusContainer()
void QWebEnginePagePrivate::unhandledKeyEvent(QKeyEvent *event)
{
+#ifdef Q_OS_OSX
+ Q_Q(QWebEnginePage);
+ if (event->type() == QEvent::KeyPress) {
+ QWebEnginePage::WebAction action = editorActionForKeyEvent(event);
+ if (action != QWebEnginePage::NoWebAction) {
+ // Try triggering a registered short-cut
+ if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcut(event))
+ return;
+ q->triggerAction(action);
+ return;
+ }
+ }
+#endif
if (view && view->parentWidget())
QGuiApplication::sendEvent(view->parentWidget(), event);
}
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index c0b1b9a4e..fb0b85268 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -71,6 +71,8 @@ class QWebEngineProfile;
class QWebEngineSettings;
class QWebEngineView;
+QWebEnginePage::WebAction editorActionForKeyEvent(QKeyEvent* event);
+
class QWebEnginePagePrivate : public QtWebEngineCore::WebContentsAdapterClient
{
public:
diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
index 99621b602..f0385a252 100644
--- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
+++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
@@ -326,6 +326,13 @@ bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event)
}
}
+ if (event->type() == QEvent::ShortcutOverride) {
+ if (editorActionForKeyEvent(static_cast<QKeyEvent*>(event)) != QWebEnginePage::NoWebAction) {
+ event->accept();
+ return true;
+ }
+ }
+
if (event->type() == QEvent::MouseButtonDblClick) {
// QWidget keeps the Qt4 behavior where the DblClick event would replace the Press event.
// QtQuick is different by sending both the Press and DblClick events for the second press