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: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
eb8aab9b60
commit
bc01540a6d
@ -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
|
||||
|
@ -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;
|
||||
|
@ -1146,21 +1146,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user