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ø <tor.arne.vestbo@qt.io>
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
This commit is contained in:
Piotr Wierciński 2023-05-03 17:07:06 +02:00
parent a1f7fb73c2
commit fb2fccc534
5 changed files with 41 additions and 1 deletions

View File

@ -371,6 +371,11 @@ qt_internal_extend_target(Gui CONDITION MACOS
${FWAppKit} ${FWAppKit}
) )
qt_internal_extend_target(Gui CONDITION WASM
SOURCES
platform/wasm/qwasmnativeinterface.cpp
)
qt_internal_extend_target(Gui CONDITION APPLE qt_internal_extend_target(Gui CONDITION APPLE
SOURCES SOURCES
image/qimage_darwin.mm image/qimage_darwin.mm

View File

@ -41,6 +41,15 @@ public:
namespace QNativeInterface::Private { 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) #if defined(Q_OS_MACOS) || defined(Q_QDOC)
struct Q_GUI_EXPORT QCocoaWindow struct Q_GUI_EXPORT QCocoaWindow
{ {

View File

@ -3065,6 +3065,10 @@ void *QWindow::resolveInterface(const char *name, int revision) const
QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow); QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
#endif #endif
#if defined(Q_OS_WASM)
QT_NATIVE_INTERFACE_RETURN_IF(QWasmWindow, platformWindow);
#endif
return nullptr; return nullptr;
} }

View File

@ -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

View File

@ -6,6 +6,7 @@
#include "qwasmintegration.h" #include "qwasmintegration.h"
#include <qpa/qplatformwindow.h> #include <qpa/qplatformwindow.h>
#include <qpa/qplatformwindow_p.h>
#include <emscripten/html5.h> #include <emscripten/html5.h>
#include "qwasmbackingstore.h" #include "qwasmbackingstore.h"
#include "qwasmscreen.h" #include "qwasmscreen.h"
@ -37,7 +38,7 @@ struct PointerEvent;
class QWasmDeadKeySupport; class QWasmDeadKeySupport;
struct WheelEvent; struct WheelEvent;
class QWasmWindow final : public QPlatformWindow class QWasmWindow final : public QPlatformWindow, public QNativeInterface::Private::QWasmWindow
{ {
public: public:
QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, QWasmCompositor *compositor, QWasmWindow(QWindow *w, QWasmDeadKeySupport *deadKeySupport, QWasmCompositor *compositor,
@ -91,6 +92,10 @@ public:
emscripten::val a11yContainer() const { return m_a11yContainer; } emscripten::val a11yContainer() const { return m_a11yContainer; }
emscripten::val inputHandlerElement() const { return m_windowContents; } 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: private:
friend class QWasmScreen; friend class QWasmScreen;
static constexpr auto minSizeForRegularWindows = 100; static constexpr auto minSizeForRegularWindows = 100;