summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-09-16 15:34:03 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2022-09-21 10:38:37 +0000
commitc265315931bc375235993f8513de21da24f6b5aa (patch)
tree24ec5243956d43c7f843337b97b879f22cacc74d
parent54f68e19ddb4282012df3cf0cc57a1243fd5fa52 (diff)
Make the clipboard paste from the outside work correctly
During the previous refactoring, two exceptions that triggered native copy/paste events were omitted. Fixes: QTBUG-106668 Change-Id: Ie61dd6a0c1d9d2fdd47bd94be055d0221feae25b Reviewed-by: Lorn Potter <lorn.potter@gmail.com> (cherry picked from commit 38049164c370dd424afe0c4574b458f7bd79083b) Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r--src/plugins/platforms/wasm/qwasmclipboard.cpp24
-rw-r--r--src/plugins/platforms/wasm/qwasmclipboard.h10
-rw-r--r--src/plugins/platforms/wasm/qwasmcompositor.cpp17
3 files changed, 34 insertions, 17 deletions
diff --git a/src/plugins/platforms/wasm/qwasmclipboard.cpp b/src/plugins/platforms/wasm/qwasmclipboard.cpp
index 9ea51af859..d49f7b3673 100644
--- a/src/plugins/platforms/wasm/qwasmclipboard.cpp
+++ b/src/plugins/platforms/wasm/qwasmclipboard.cpp
@@ -284,19 +284,21 @@ void QWasmClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode)
isPaste = false;
}
-bool QWasmClipboard::processKeyboard(const QWasmEventTranslator::TranslatedEvent &event,
- const QFlags<Qt::KeyboardModifier> &modifiers)
+QWasmClipboard::ProcessKeyboardResult
+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;
- }
+ if (event.type != QEvent::KeyPress || !modifiers.testFlag(Qt::ControlModifier))
+ return ProcessKeyboardResult::Ignored;
+
+ if (event.key != Qt::Key_C && event.key != Qt::Key_V && event.key != Qt::Key_X)
+ return ProcessKeyboardResult::Ignored;
+
isPaste = event.key == Qt::Key_V;
- return true;
+
+ return hasClipboardApi && !isPaste
+ ? ProcessKeyboardResult::NativeClipboardEventAndCopiedDataNeeded
+ : ProcessKeyboardResult::NativeClipboardEventNeeded;
}
bool QWasmClipboard::supportsMode(QClipboard::Mode mode) const
diff --git a/src/plugins/platforms/wasm/qwasmclipboard.h b/src/plugins/platforms/wasm/qwasmclipboard.h
index e2701e9bb1..6bf552e58e 100644
--- a/src/plugins/platforms/wasm/qwasmclipboard.h
+++ b/src/plugins/platforms/wasm/qwasmclipboard.h
@@ -19,6 +19,12 @@ QT_BEGIN_NAMESPACE
class QWasmClipboard : public QObject, public QPlatformClipboard
{
public:
+ enum class ProcessKeyboardResult {
+ Ignored,
+ NativeClipboardEventNeeded,
+ NativeClipboardEventAndCopiedDataNeeded,
+ };
+
QWasmClipboard();
virtual ~QWasmClipboard();
@@ -29,8 +35,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);
+ ProcessKeyboardResult 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 7dee14a97e..6f9ac02fc6 100644
--- a/src/plugins/platforms/wasm/qwasmcompositor.cpp
+++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp
@@ -1145,21 +1145,30 @@ void QWasmCompositor::WindowManipulation::onPointerUp(const PointerEvent& event)
bool QWasmCompositor::processKeyboard(int eventType, const EmscriptenKeyboardEvent *emKeyEvent)
{
+ constexpr bool ProceedToNativeEvent = false;
Q_ASSERT(eventType == EMSCRIPTEN_EVENT_KEYDOWN || eventType == EMSCRIPTEN_EVENT_KEYUP);
auto translatedEvent = m_eventTranslator->translateKeyEvent(eventType, emKeyEvent);
const QFlags<Qt::KeyboardModifier> modifiers = KeyboardModifier::getForEvent(*emKeyEvent);
- if (QWasmIntegration::get()->getWasmClipboard()->processKeyboard(translatedEvent, modifiers))
- return false;
+ const auto clipboardResult = QWasmIntegration::get()->getWasmClipboard()->processKeyboard(
+ translatedEvent, modifiers);
+
+ using ProcessKeyboardResult = QWasmClipboard::ProcessKeyboardResult;
+ if (clipboardResult == ProcessKeyboardResult::NativeClipboardEventNeeded)
+ return ProceedToNativeEvent;
if (translatedEvent.text.isEmpty())
translatedEvent.text = QString(emKeyEvent->key);
if (translatedEvent.text.size() > 1)
translatedEvent.text.clear();
- return QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(
- 0, translatedEvent.type, translatedEvent.key, modifiers, translatedEvent.text);
+ const auto result =
+ QWindowSystemInterface::handleKeyEvent<QWindowSystemInterface::SynchronousDelivery>(
+ 0, translatedEvent.type, translatedEvent.key, modifiers, translatedEvent.text);
+ return clipboardResult == ProcessKeyboardResult::NativeClipboardEventAndCopiedDataNeeded
+ ? ProceedToNativeEvent
+ : result;
}
bool QWasmCompositor::processWheel(int eventType, const EmscriptenWheelEvent *wheelEvent)