summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmintegration.cpp
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@gmail.com>2022-01-17 07:25:26 +1000
committerLorn Potter <lorn.potter@gmail.com>2022-03-03 12:30:59 +1000
commit66a76a5def46d0e4a330f7130ad440c639b87cf7 (patch)
tree88a05b0a11fce75c7a672e16957c7d9f4f3bff0c /src/plugins/platforms/wasm/qwasmintegration.cpp
parent6f5c78fe3d445f1c6c8738f9cedb9dbd847645fa (diff)
wasm: enable mobile native keyboarding
This works on iOS and Android, and Windows with touchscreen. On Android, we need to listen to the input event of a hidden text element and synthesize Qt keyboard events from that in order to get input events into Qt. On Windows, we need to be more creative about bringing the native virtual keyboard up. Because the entire canvas is contenteditable, we need to specify the inputmode is set to 'none', otherwise the v keyboard pops up when user clicks anywhere on the canvas. Therefore we set a hidden element as contenteditable, which pops up keyboard when Qt needs it for editable widgets. On Android, this is the same element that is used to proxy the keyboard input. [ChangeLog][wasm] Add support for native mobile keyboard Done-with: Morten Johan Sørvig <morten.sorvig@qt.io> Fixes: QTBUG-83064 Fixes: QTBUG-88803 Change-Id: I769fe344fc10c17971bd1c0a603501040fe82653 Reviewed-by: David Skoland <david.skoland@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp')
-rw-r--r--src/plugins/platforms/wasm/qwasmintegration.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp
index 031128563e..01fb9f1cd0 100644
--- a/src/plugins/platforms/wasm/qwasmintegration.cpp
+++ b/src/plugins/platforms/wasm/qwasmintegration.cpp
@@ -106,6 +106,22 @@ QWasmIntegration::QWasmIntegration()
{
s_instance = this;
+ touchPoints = emscripten::val::global("navigator")["maxTouchPoints"].as<int>();
+ // The Platform Detect: expand coverage as needed
+ platform = GenericPlatform;
+ emscripten::val rawPlatform = emscripten::val::global("navigator")["platform"];
+
+ if (rawPlatform.call<bool>("includes", emscripten::val("Mac")))
+ platform = MacOSPlatform;
+ if (rawPlatform.call<bool>("includes", emscripten::val("Win32")))
+ platform = WindowsPlatform;
+ if (rawPlatform.call<bool>("includes", emscripten::val("Linux"))) {
+ platform = LinuxPlatform;
+ emscripten::val uAgent = emscripten::val::global("navigator")["userAgent"];
+ if (uAgent.call<bool>("includes", emscripten::val("Android")))
+ platform = AndroidPlatform;
+ }
+
// We expect that qtloader.js has populated Module.qtCanvasElements with one or more canvases.
emscripten::val qtCanvaseElements = val::module_property("qtCanvasElements");
emscripten::val canvas = val::module_property("canvas"); // TODO: remove for Qt 6.0
@@ -156,6 +172,8 @@ QWasmIntegration::~QWasmIntegration()
delete m_fontDb;
delete m_desktopServices;
+ if (m_platformInputContext)
+ delete m_platformInputContext;
for (const auto &canvasAndScreen : m_screens)
QWindowSystemInterface::handleScreenRemoved(canvasAndScreen.second);
@@ -210,9 +228,14 @@ QPlatformOpenGLContext *QWasmIntegration::createPlatformOpenGLContext(QOpenGLCon
void QWasmIntegration::initialize()
{
+ if (touchPoints < 1) // only touchscreen need inputcontexts
+ return;
+
QString icStr = QPlatformInputContextFactory::requested();
if (!icStr.isNull())
m_inputContext.reset(QPlatformInputContextFactory::create(icStr));
+ else
+ m_inputContext.reset(new QWasmInputContext());
}
QPlatformInputContext *QWasmIntegration::inputContext() const