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.

Pick-to: 6.4 6.4.0
Change-Id: I030a31aa0951c3813ce1d38da9a6526010b3bfc8
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Mikolaj Boc 2022-09-06 12:56:42 +02:00
parent 124522a0a5
commit adebdd0f9a
3 changed files with 21 additions and 7 deletions

View File

@ -183,6 +183,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;

View File

@ -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;

View File

@ -829,13 +829,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);