summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Wierciński <[email protected]>2023-05-03 17:07:06 +0200
committerPiotr Wierciński <[email protected]>2023-05-05 12:27:36 +0200
commitfb2fccc534d8dc0bf4e5a1b71cd5572fd6da325f (patch)
tree1e426711d04a53e1be6568ad98b7ca7ed1d3725e
parenta1f7fb73c273ea858a9eb81bdb48874bfcdf9858 (diff)
wasm: Add DOM accessors functions through NativeInterface
Expose document and clientArea emscripten objects through NativeInterface. This is required by WebView implementation for wasm platform. Task-number: QTBUG-75183 Change-Id: I6f2f084a9dbceb80d2186c7395c008f268a91e39 Reviewed-by: Tor Arne Vestbø <[email protected]> Reviewed-by: Mikołaj Boc <[email protected]>
-rw-r--r--src/gui/CMakeLists.txt5
-rw-r--r--src/gui/kernel/qplatformwindow_p.h9
-rw-r--r--src/gui/kernel/qwindow.cpp4
-rw-r--r--src/gui/platform/wasm/qwasmnativeinterface.cpp17
-rw-r--r--src/plugins/platforms/wasm/qwasmwindow.h7
5 files changed, 41 insertions, 1 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 714a7ee058c..8f41efa47dc 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -371,6 +371,11 @@ qt_internal_extend_target(Gui CONDITION MACOS
${FWAppKit}
)
+qt_internal_extend_target(Gui CONDITION WASM
+ SOURCES
+ platform/wasm/qwasmnativeinterface.cpp
+)
+
qt_internal_extend_target(Gui CONDITION APPLE
SOURCES
image/qimage_darwin.mm
diff --git a/src/gui/kernel/qplatformwindow_p.h b/src/gui/kernel/qplatformwindow_p.h
index 65b8b4a2c53..a1c7b75468e 100644
--- a/src/gui/kernel/qplatformwindow_p.h
+++ b/src/gui/kernel/qplatformwindow_p.h
@@ -41,6 +41,15 @@ public:
namespace QNativeInterface::Private {
+#if defined(Q_OS_WASM) || defined(Q_QDOC)
+struct Q_GUI_EXPORT QWasmWindow
+{
+ QT_DECLARE_NATIVE_INTERFACE(QWasmWindow, 1, QWindow)
+ virtual emscripten::val document() const = 0;
+ virtual emscripten::val clientArea() const = 0;
+};
+#endif
+
#if defined(Q_OS_MACOS) || defined(Q_QDOC)
struct Q_GUI_EXPORT QCocoaWindow
{
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index e83ed33a369..b59c32ac343 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -3065,6 +3065,10 @@ void *QWindow::resolveInterface(const char *name, int revision) const
QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
#endif
+#if defined(Q_OS_WASM)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
+#endif
+
return nullptr;
}
diff --git a/src/gui/platform/wasm/qwasmnativeinterface.cpp b/src/gui/platform/wasm/qwasmnativeinterface.cpp
new file mode 100644
index 00000000000..7313629a8d4
--- /dev/null
+++ b/src/gui/platform/wasm/qwasmnativeinterface.cpp
@@ -0,0 +1,17 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+
+
+#include <QtGui/private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
+#include <qpa/qplatformwindow_p.h>
+
+
+QT_BEGIN_NAMESPACE
+
+using namespace QNativeInterface::Private;
+
+QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QWasmWindow);
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/wasm/qwasmwindow.h b/src/plugins/platforms/wasm/qwasmwindow.h
index 661a5160e89..f191c909542 100644
--- a/src/plugins/platforms/wasm/qwasmwindow.h
+++ b/src/plugins/platforms/wasm/qwasmwindow.h
@@ -6,6 +6,7 @@
#include "qwasmintegration.h"
#include <qpa/qplatformwindow.h>
+#include <qpa/qplatformwindow_p.h>
#include <emscripten/html5.h>
#include "qwasmbackingstore.h"
#include "qwasmscreen.h"
@@ -37,7 +38,7 @@ struct PointerEvent;
class QWasmDeadKeySupport;
struct WheelEvent;
-class QWasmWindow final : public QPlatformWindow
+class QWasmWindow final : public QPlatformWindow, public QNativeInterface::Private::QWasmWindow
{
public:
QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, QWasmCompositor *compositor,
@@ -91,6 +92,10 @@ public:
emscripten::val a11yContainer() const { return m_a11yContainer; }
emscripten::val inputHandlerElement() const { return m_windowContents; }
+ // QNativeInterface::Private::QWasmWindow
+ emscripten::val document() const override { return m_document; }
+ emscripten::val clientArea() const override { return m_qtWindow; }
+
private:
friend class QWasmScreen;
static constexpr auto minSizeForRegularWindows = 100;