From e0bd650cb7f8c8fd3014541b4c49104906e0e139 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 20 Jun 2016 17:14:35 +0200 Subject: Override short-cuts to common editor commands To ensure Chromium is given a chance to handle editor commands, we must override these short-cuts. On OS X we must also perform the action afterwards as these are not handled internally by the Blink Editor. The patch solves copy/paste in flash plugins and copy/paste on OS X when no application short-cuts have been defined. The handling of short-cut override events is based on how it was handled in Qt WebKit Task-number: QTBUG-54221 Change-Id: I748671c7bfa5662aae16c6a4b9bbe5e2bce1b907 Reviewed-by: Alexandru Croitor --- src/webenginewidgets/api/qwebenginepage.cpp | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/webenginewidgets/api/qwebenginepage.cpp') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 0279c9343..45177d8d8 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -77,6 +77,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QtWebEngineCore; @@ -96,6 +98,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))) @@ -226,6 +249,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); } -- cgit v1.2.3