diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-06-20 17:14:35 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-06-22 13:53:40 +0000 |
commit | e0bd650cb7f8c8fd3014541b4c49104906e0e139 (patch) | |
tree | 76b7ed34eb9dd5e1b60698c0851b64414f182c4b /src/webengine | |
parent | 7494836e3a1e61a000fa0f73f91665fa291ec287 (diff) |
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 <alexandru.croitor@theqtcompany.com>
Diffstat (limited to 'src/webengine')
4 files changed, 48 insertions, 0 deletions
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 357f95bc4..6b3614fc5 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -86,6 +86,27 @@ QT_BEGIN_NAMESPACE using namespace QtWebEngineCore; +QQuickWebEngineView::WebAction editorActionForKeyEvent(QKeyEvent* event) +{ + static struct { + QKeySequence::StandardKey standardKey; + QQuickWebEngineView::WebAction action; + } editorActions[] = { + { QKeySequence::Cut, QQuickWebEngineView::Cut }, + { QKeySequence::Copy, QQuickWebEngineView::Copy }, + { QKeySequence::Paste, QQuickWebEngineView::Paste }, + { QKeySequence::Undo, QQuickWebEngineView::Undo }, + { QKeySequence::Redo, QQuickWebEngineView::Redo }, + { QKeySequence::SelectAll, QQuickWebEngineView::SelectAll }, + { QKeySequence::UnknownKey, QQuickWebEngineView::NoWebAction } + }; + for (int i = 0; editorActions[i].standardKey != QKeySequence::UnknownKey; ++i) + if (event == editorActions[i].standardKey) + return editorActions[i].action; + + return QQuickWebEngineView::NoWebAction; +} + #ifndef QT_NO_ACCESSIBILITY static QAccessibleInterface *webAccessibleFactory(const QString &, QObject *object) { @@ -489,6 +510,18 @@ void QQuickWebEngineViewPrivate::focusContainer() void QQuickWebEngineViewPrivate::unhandledKeyEvent(QKeyEvent *event) { Q_Q(QQuickWebEngineView); +#ifdef Q_OS_OSX + if (event->type() == QEvent::KeyPress) { + QQuickWebEngineView::WebAction action = editorActionForKeyEvent(event); + if (action != QQuickWebEngineView::NoWebAction) { + // Try triggering a registered short-cut + if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcut(event)) + return; + q->triggerWebAction(action); + return; + } + } +#endif if (q->parentItem()) q->window()->sendEvent(q->parentItem(), event); } diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 2a6c2c879..aab86bc3a 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -68,6 +68,8 @@ class QQmlComponent; class QQmlContext; class QQuickWebEngineSettings; +QQuickWebEngineView::WebAction editorActionForKeyEvent(QKeyEvent* event); + #ifdef ENABLE_QML_TESTSUPPORT_API class QQuickWebEngineTestSupport; #endif diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp index cd8fc54b9..b10ca8bdb 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -207,6 +207,18 @@ void RenderWidgetHostViewQtDelegateQuick::inputMethodStateChanged(bool editorVis } +bool RenderWidgetHostViewQtDelegateQuick::event(QEvent *event) +{ + if (event->type() == QEvent::ShortcutOverride) { + if (editorActionForKeyEvent(static_cast<QKeyEvent*>(event)) != QQuickWebEngineView::NoWebAction) { + event->accept(); + return true; + } + } + + return QQuickItem::event(event); +} + void RenderWidgetHostViewQtDelegateQuick::focusInEvent(QFocusEvent *event) { m_client->forwardEvent(event); diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.h b/src/webengine/render_widget_host_view_qt_delegate_quick.h index 7c44da9b9..dc0e481db 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.h +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.h @@ -74,6 +74,7 @@ public: virtual void setClearColor(const QColor &) Q_DECL_OVERRIDE { } protected: + virtual bool event(QEvent *event) Q_DECL_OVERRIDE; virtual void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE; virtual void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE; virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; |