summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2025-04-10 13:39:38 +0300
committerJuha Vuolle <juha.vuolle@qt.io>2025-04-22 14:28:32 +0300
commit0bf2fafd38ee94eb31db514beaaa9ea4cb0adba6 (patch)
tree6db20d6c0a2805a4b4d9243491cc7ed11903543b
parent4748d4303b7b49a9187a353df5d8e7a7fe9ec2dd (diff)
Allow configuring WASM without clipboard
Pick-to: 6.9 6.8 Fixes: QTBUG-135875 Change-Id: Ibf0a51ff0e1268f32d32511dff64003c28137795 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r--src/plugins/platforms/wasm/CMakeLists.txt6
-rw-r--r--src/plugins/platforms/wasm/qwasminputcontext.cpp8
-rw-r--r--src/plugins/platforms/wasm/qwasmintegration.cpp6
-rw-r--r--src/plugins/platforms/wasm/qwasmintegration.h2
-rw-r--r--src/plugins/platforms/wasm/qwasmwindow.cpp14
5 files changed, 34 insertions, 2 deletions
diff --git a/src/plugins/platforms/wasm/CMakeLists.txt b/src/plugins/platforms/wasm/CMakeLists.txt
index 4a669a84e31..7b2d79ce587 100644
--- a/src/plugins/platforms/wasm/CMakeLists.txt
+++ b/src/plugins/platforms/wasm/CMakeLists.txt
@@ -13,7 +13,6 @@ qt_internal_add_plugin(QWasmIntegrationPlugin
main.cpp
qwasmaccessibility.cpp qwasmaccessibility.h
qwasmbase64iconstore.cpp qwasmbase64iconstore.h
- qwasmclipboard.cpp qwasmclipboard.h
qwasmcompositor.cpp qwasmcompositor.h
qwasmcssstyle.cpp qwasmcssstyle.h
qwasmcursor.cpp qwasmcursor.h
@@ -63,6 +62,11 @@ qt_internal_add_resource(QWasmIntegrationPlugin "wasmfonts"
${wasmfonts_resource_files}
)
+qt_internal_extend_target(QWasmIntegrationPlugin CONDITION QT_FEATURE_clipboard
+ SOURCES
+ qwasmclipboard.cpp qwasmclipboard.h
+)
+
qt_internal_extend_target(QWasmIntegrationPlugin CONDITION QT_FEATURE_opengl
SOURCES
qwasmbackingstore.cpp qwasmbackingstore.h
diff --git a/src/plugins/platforms/wasm/qwasminputcontext.cpp b/src/plugins/platforms/wasm/qwasminputcontext.cpp
index 56cb7c032d8..b09cef50839 100644
--- a/src/plugins/platforms/wasm/qwasminputcontext.cpp
+++ b/src/plugins/platforms/wasm/qwasminputcontext.cpp
@@ -10,7 +10,9 @@
#include <qwindow.h>
#include <qpa/qplatforminputcontext.h>
#include <qpa/qwindowsysteminterface.h>
+#if QT_CONFIG(clipboard)
#include <QClipboard>
+#endif
#include <QtGui/qtextobject.h>
QT_BEGIN_NAMESPACE
@@ -90,6 +92,7 @@ void QWasmInputContext::inputCallback(emscripten::val event)
} else if (!inputTypeString.compare("insertText")) {
wasmInput->insertText(inputStr);
event.call<void>("stopImmediatePropagation");
+#if QT_CONFIG(clipboard)
} else if (!inputTypeString.compare("insertFromPaste")) {
wasmInput->insertText(QGuiApplication::clipboard()->text());
event.call<void>("stopImmediatePropagation");
@@ -97,6 +100,7 @@ void QWasmInputContext::inputCallback(emscripten::val event)
// But now, keyCallback in QWasmWindow
// will take them as exceptions.
//} else if (!inputTypeString.compare("deleteByCut")) {
+#endif
} else {
qCWarning(qLcQpaWasmInputContext) << Q_FUNC_INFO << "inputType \"" << inputType.as<std::string>() << "\" is not supported in Qt yet";
}
@@ -189,6 +193,7 @@ void QWasmInputContext::compositionUpdateCallback(emscripten::val event)
wasmInput->setPreeditString(compositionStr, 0);
}
+#if QT_CONFIG(clipboard)
static void copyCallback(emscripten::val event)
{
qCDebug(qLcQpaWasmInputContext) << Q_FUNC_INFO;
@@ -230,6 +235,7 @@ static void pasteCallback(emscripten::val event)
// propagate to input event (insertFromPaste)
}
+#endif // QT_CONFIG(clipboard)
QWasmInputContext::QWasmInputContext()
{
@@ -258,10 +264,12 @@ QWasmInputContext::QWasmInputContext()
m_compositionStartCallback = QWasmEventHandler(m_inputElement, "compositionstart", QWasmInputContext::compositionStartCallback);
m_compositionUpdateCallback = QWasmEventHandler(m_inputElement, "compositionupdate", QWasmInputContext::compositionUpdateCallback);
+#if QT_CONFIG(clipboard)
// Clipboard for InputContext
m_clipboardCut = QWasmEventHandler(m_inputElement, "cut", cutCallback);
m_clipboardCopy = QWasmEventHandler(m_inputElement, "copy", copyCallback);
m_clipboardPaste = QWasmEventHandler(m_inputElement, "paste", pasteCallback);
+#endif
}
QWasmInputContext::~QWasmInputContext()
diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp
index e3cdf11fa27..08092f2cccc 100644
--- a/src/plugins/platforms/wasm/qwasmintegration.cpp
+++ b/src/plugins/platforms/wasm/qwasmintegration.cpp
@@ -6,7 +6,9 @@
#include "qwasmcompositor.h"
#include "qwasmopenglcontext.h"
#include "qwasmtheme.h"
+#if QT_CONFIG(clipboard)
#include "qwasmclipboard.h"
+#endif
#include "qwasmaccessibility.h"
#include "qwasmservices.h"
#include "qwasmoffscreensurface.h"
@@ -92,7 +94,9 @@ QWasmIntegration::QWasmIntegration()
: m_suspendResume(std::make_shared<QWasmSuspendResumeControl>()) // create early in order to register event handlers at startup
, m_fontDb(nullptr)
, m_desktopServices(nullptr)
+#if QT_CONFIG(clipboard)
, m_clipboard(new QWasmClipboard)
+#endif
#if QT_CONFIG(accessibility)
, m_accessibility(new QWasmAccessibility)
#endif
@@ -309,10 +313,12 @@ QPlatformServices *QWasmIntegration::services() const
return m_desktopServices;
}
+#if QT_CONFIG(clipboard)
QPlatformClipboard* QWasmIntegration::clipboard() const
{
return m_clipboard;
}
+#endif
#ifndef QT_NO_ACCESSIBILITY
QPlatformAccessibility *QWasmIntegration::accessibility() const
diff --git a/src/plugins/platforms/wasm/qwasmintegration.h b/src/plugins/platforms/wasm/qwasmintegration.h
index 045f00de4dc..e02b51d7e98 100644
--- a/src/plugins/platforms/wasm/qwasmintegration.h
+++ b/src/plugins/platforms/wasm/qwasmintegration.h
@@ -59,7 +59,9 @@ public:
QStringList themeNames() const override;
QPlatformTheme *createPlatformTheme(const QString &name) const override;
QPlatformServices *services() const override;
+#if QT_CONFIG(clipboard)
QPlatformClipboard *clipboard() const override;
+#endif
#ifndef QT_NO_ACCESSIBILITY
QPlatformAccessibility *accessibility() const override;
#endif
diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp
index 98e9d9f9bfe..d0cc773cfed 100644
--- a/src/plugins/platforms/wasm/qwasmwindow.cpp
+++ b/src/plugins/platforms/wasm/qwasmwindow.cpp
@@ -12,7 +12,9 @@
#include "qwasmbase64iconstore.h"
#include "qwasmdom.h"
+#if QT_CONFIG(clipboard)
#include "qwasmclipboard.h"
+#endif
#include "qwasmintegration.h"
#include "qwasmkeytranslator.h"
#include "qwasmwindow.h"
@@ -21,7 +23,6 @@
#include "qwasmevent.h"
#include "qwasmeventdispatcher.h"
#include "qwasmaccessibility.h"
-#include "qwasmclipboard.h"
#include "qwasmdrag.h"
#include <iostream>
@@ -86,12 +87,14 @@ QWasmWindow::QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport,
m_canvas["classList"].call<void>("add", emscripten::val("qt-window-canvas"));
+#if QT_CONFIG(clipboard)
// Set contentEditable so that the window gets clipboard events,
// then hide the resulting focus frame.
m_window.set("contentEditable", std::string("true"));
m_window["style"].set("outline", std::string("none"));
QWasmClipboard::installEventHandlers(m_window);
+#endif
// Set inputMode to none to stop the mobile keyboard from opening
// when the user clicks on the window.
@@ -574,19 +577,26 @@ bool QWasmWindow::processKey(const KeyEvent &event)
constexpr bool ProceedToNativeEvent = false;
Q_ASSERT(event.type == EventType::KeyDown || event.type == EventType::KeyUp);
+#if QT_CONFIG(clipboard)
const auto clipboardResult =
QWasmIntegration::get()->getWasmClipboard()->processKeyboard(event);
using ProcessKeyboardResult = QWasmClipboard::ProcessKeyboardResult;
if (clipboardResult == ProcessKeyboardResult::NativeClipboardEventNeeded)
return ProceedToNativeEvent;
+#endif
const auto result = QWindowSystemInterface::handleKeyEvent(
0, event.type == EventType::KeyDown ? QEvent::KeyPress : QEvent::KeyRelease, event.key,
event.modifiers, event.text, event.autoRepeat);
+
+#if QT_CONFIG(clipboard)
return clipboardResult == ProcessKeyboardResult::NativeClipboardEventAndCopiedDataNeeded
? ProceedToNativeEvent
: result;
+#else
+ return result;
+#endif
}
void QWasmWindow::handleKeyForInputContextEvent(EventType eventType, const emscripten::val &event)
@@ -651,9 +661,11 @@ bool QWasmWindow::processKeyForInputContext(const KeyEvent &event)
0, event.type == EventType::KeyDown ? QEvent::KeyPress : QEvent::KeyRelease, event.key,
event.modifiers, event.text);
+#if QT_CONFIG(clipboard)
// Copy/Cut callback required to copy qtClipboard to system clipboard
if (keySeq == QKeySequence::Copy || keySeq == QKeySequence::Cut)
return false;
+#endif
return result;
}