diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-09-16 15:34:03 +0200 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-09-18 21:44:35 +0200 |
commit | 38049164c370dd424afe0c4574b458f7bd79083b (patch) | |
tree | 3ee33506ad9ace404f57d58842efbdec9db5c0fe /src/plugins | |
parent | 9536a0ad48a54fef504689cc7a1e65ab865c5ff4 (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
Pick-to: 6.4.0 6.4
Change-Id: Ie61dd6a0c1d9d2fdd47bd94be055d0221feae25b
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/wasm/qwasmclipboard.cpp | 24 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmclipboard.h | 10 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmcompositor.cpp | 17 |
3 files changed, 34 insertions, 17 deletions
diff --git a/src/plugins/platforms/wasm/qwasmclipboard.cpp b/src/plugins/platforms/wasm/qwasmclipboard.cpp index d290fe245b..4f4538eec6 100644 --- a/src/plugins/platforms/wasm/qwasmclipboard.cpp +++ b/src/plugins/platforms/wasm/qwasmclipboard.cpp @@ -183,19 +183,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 24dad06127..70f9982898 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 ccf7bd9356..a892f7077b 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.cpp +++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp @@ -823,21 +823,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) |