diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-09-06 12:56:42 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-09-10 16:50:52 +0000 |
commit | ffa3c3579acaf3291b0cfa7e5670313d576d5d49 (patch) | |
tree | 77536af94af15f632b9f91c0e1229d1f05760550 | |
parent | 9fe9c41f8377d4194108c69b3fc684532c630e9c (diff) |
Propagate the copy event correctly to Qt widgets on WASM
The event should be propagated when the native clipboard is available.
A recent regression caused it to be suppressed, which resulted in lack
of copy/paste capabilities.
Change-Id: I030a31aa0951c3813ce1d38da9a6526010b3bfc8
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
(cherry picked from commit adebdd0f9af0ffe47250b4a273407b84a6c61879)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/platforms/wasm/qwasmclipboard.cpp | 15 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmclipboard.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmcompositor.cpp | 9 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/plugins/platforms/wasm/qwasmclipboard.cpp b/src/plugins/platforms/wasm/qwasmclipboard.cpp index 88043ba092..9ea51af859 100644 --- a/src/plugins/platforms/wasm/qwasmclipboard.cpp +++ b/src/plugins/platforms/wasm/qwasmclipboard.cpp @@ -284,6 +284,21 @@ void QWasmClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode) isPaste = false; } +bool QWasmClipboard::processKeyboard(const QWasmEventTranslator::TranslatedEvent &event, + const QFlags<Qt::KeyboardModifier> &modifiers) +{ + // Clipboard path: cut/copy/paste are handled by clipboard event or direct clipboard + // access. + if (hasClipboardApi) + return false; + if (event.type != QEvent::KeyPress || !modifiers.testFlag(Qt::ControlModifier) + || (event.key != Qt::Key_C && event.key != Qt::Key_V && event.key != Qt::Key_X)) { + return false; + } + isPaste = event.key == Qt::Key_V; + return true; +} + bool QWasmClipboard::supportsMode(QClipboard::Mode mode) const { return mode == QClipboard::Clipboard; diff --git a/src/plugins/platforms/wasm/qwasmclipboard.h b/src/plugins/platforms/wasm/qwasmclipboard.h index ef11fd2e49..e2701e9bb1 100644 --- a/src/plugins/platforms/wasm/qwasmclipboard.h +++ b/src/plugins/platforms/wasm/qwasmclipboard.h @@ -12,6 +12,8 @@ #include <emscripten/bind.h> #include <emscripten/val.h> +#include "qwasmeventtranslator.h" + QT_BEGIN_NAMESPACE class QWasmClipboard : public QObject, public QPlatformClipboard @@ -27,6 +29,8 @@ public: bool ownsMode(QClipboard::Mode mode) const override; static void qWasmClipboardPaste(QMimeData *mData); + bool processKeyboard(const QWasmEventTranslator::TranslatedEvent &event, + const QFlags<Qt::KeyboardModifier> &modifiers); void initClipboardPermissions(); void installEventHandlers(const emscripten::val &canvas); bool hasClipboardApi; diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp index b167390850..7dee14a97e 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.cpp +++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp @@ -1151,13 +1151,8 @@ bool QWasmCompositor::processKeyboard(int eventType, const EmscriptenKeyboardEve const QFlags<Qt::KeyboardModifier> modifiers = KeyboardModifier::getForEvent(*emKeyEvent); - // Clipboard path: cut/copy/paste are handled by clipboard event or direct clipboard access. - if (translatedEvent.type == QEvent::KeyPress && modifiers.testFlag(Qt::ControlModifier) - && (translatedEvent.key == Qt::Key_X || translatedEvent.key == Qt::Key_V - || translatedEvent.key == Qt::Key_C)) { - QWasmIntegration::get()->getWasmClipboard()->isPaste = translatedEvent.key == Qt::Key_V; - return false; // continue on to event - } + if (QWasmIntegration::get()->getWasmClipboard()->processKeyboard(translatedEvent, modifiers)) + return false; if (translatedEvent.text.isEmpty()) translatedEvent.text = QString(emKeyEvent->key); |