18#include <QtGui/private/qgenericunixeventdispatcher_p.h>
20#include <qpa/qplatformwindow.h>
21#include <QtGui/qscreen.h>
22#include <qpa/qwindowsysteminterface.h>
23#include <QtCore/qcoreapplication.h>
24#include <qpa/qplatforminputcontextfactory_p.h>
26#include <emscripten/bind.h>
27#include <emscripten/val.h>
31#include <private/qsimpledrag_p.h>
89 , m_accessibility(new QWasmAccessibility)
97 touchPoints = emscripten::val::global(
"navigator")[
"maxTouchPoints"].as<
int>();
103 emscripten::val filtered = emscripten::val::array();
104 emscripten::val qtContainerElements = val::module_property(
"qtContainerElements");
105 if (qtContainerElements.isArray()) {
106 for (
int i = 0;
i < qtContainerElements[
"length"].as<
int>(); ++
i) {
107 emscripten::val element = qtContainerElements[
i].as<emscripten::val>();
108 if (element.isNull() || element.isUndefined())
109 qWarning() <<
"Skipping null or undefined element in qtContainerElements";
111 filtered.call<
void>(
"push", element);
115 qWarning() <<
"The qtContainerElements module property was not set or is invalid. "
116 "Proceeding with no screens.";
121 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
nullptr, EM_TRUE,
122 [](
int,
const EmscriptenUiEvent *,
void *) ->
int {
128 integration->resizeAllScreens();
133 emscripten::val visualViewport = emscripten::val::global(
"window")[
"visualViewport"];
134 if (!visualViewport.isUndefined()) {
135 visualViewport.call<
void>(
"addEventListener",
val(
"resize"),
136 val::module_property(
"qtResizeAllScreens"));
138 m_drag = std::make_unique<QSimpleDrag>();
144 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
nullptr, EM_TRUE,
nullptr);
145 emscripten::val visualViewport = emscripten::val::global(
"window")[
"visualViewport"];
146 if (!visualViewport.isUndefined()) {
147 visualViewport.call<
void>(
"removeEventListener",
val(
"resize"),
148 val::module_property(
"qtResizeAllScreens"));
152 delete m_desktopServices;
153 if (m_platformInputContext)
154 delete m_platformInputContext;
155#if QT_CONFIG(accessibility)
156 delete m_accessibility;
159 for (
const auto &elementAndScreen : m_screens)
160 elementAndScreen.wasmScreen->deleteScreen();
164 s_instance =
nullptr;
223 return m_inputContext.
data();
233 if (m_fontDb ==
nullptr)
272 if (
name ==
"webassembly"_L1)
279 if (m_desktopServices ==
nullptr)
281 return m_desktopServices;
289#ifndef QT_NO_ACCESSIBILITY
292 return m_accessibility;
298 const auto *primaryScreenBefore = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
302 std::transform(m_screens.
begin(), m_screens.
end(), std::back_inserter(screensToDelete),
303 [](
const ScreenMapping &
mapping) { return mapping.wasmScreen; });
305 for (
int i = 0;
i < elementArray[
"length"].as<
int>(); ++
i) {
306 const auto element = elementArray[
i];
307 const auto it = std::find_if(
309 [&element](
const ScreenMapping &
screen) { return screen.emscriptenVal == element; });
311 if (
it != m_screens.
end()) {
313 screensToDelete.
erase(std::remove_if(screensToDelete.
begin(), screensToDelete.
end(),
315 return removedScreen == screen;
317 screensToDelete.
end());
325 std::for_each(screensToDelete.
begin(), screensToDelete.
end(),
326 [](
QWasmScreen *removed) { removed->deleteScreen(); });
328 m_screens = newScreens;
329 auto *primaryScreenAfter = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
330 if (primaryScreenAfter && primaryScreenAfter != primaryScreenBefore)
337 == std::find_if(m_screens.
begin(), m_screens.
end(),
338 [&element](
const ScreenMapping &
screen) {
339 return screen.emscriptenVal == element;
350 const auto *primaryScreenBefore = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
353 std::find_if(m_screens.
begin(), m_screens.
end(),
354 [&element](
const ScreenMapping &
screen) { return screen.emscriptenVal == element; });
355 if (
it == m_screens.
end()) {
356 qWarning() <<
"Attempt to remove a nonexistent screen.";
363 m_screens.
erase(std::remove_if(m_screens.
begin(), m_screens.
end(),
364 [removedScreen](
const ScreenMapping &
mapping) {
365 return removedScreen == mapping.wasmScreen;
368 auto *primaryScreenAfter = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
369 if (primaryScreenAfter && primaryScreenAfter != primaryScreenBefore)
375 auto it = std::find_if(m_screens.
begin(), m_screens.
end(),
376 [&] (
const ScreenMapping &candidate) { return candidate.emscriptenVal.equals(element); });
377 if (
it == m_screens.
end()) {
378 qWarning() <<
"Attempting to resize non-existing screen for element"
379 << QString::fromJsString(element[
"id"]);
382 it->wasmScreen->updateQScreenAndCanvasRenderSize();
387 emscripten::val dpi = emscripten::val::module_property(
"qtFontDpi");
388 if (dpi.isUndefined())
391 for (
const auto &elementAndScreen : m_screens)
397 for (
const auto &elementAndScreen : m_screens)
398 elementAndScreen.wasmScreen->updateQScreenAndCanvasRenderSize();
403 return emscripten_performance_now();
406#if QT_CONFIG(draganddrop)
bool remove(const Key &key)
Removes the item that has the key from the hash.
T value(const Key &key) const noexcept
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
bool isEmpty() const noexcept
iterator erase(const_iterator begin, const_iterator end)
void push_back(parameter_type t)
static QString requested()
static QPlatformInputContext * create()
The QPlatformInputContext class abstracts the input method dependent data and composing state.
The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isNull() const
Returns true if this string is null; otherwise returns false.
QPlatformInputContext * inputContext() const override
Returns the platforms input context.
void setContainerElements(emscripten::val elementArray)
static QWasmIntegration * get()
Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const override
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
Factory function for QOffscreenSurface.
void addContainerElement(emscripten::val elementArray)
void initialize() override
Performs initialization steps that depend on having an event dispatcher available.
void removeContainerElement(emscripten::val elementArray)
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
QStringList themeNames() const override
QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const override
Factory function for QPlatformOpenGLContext.
void removeBackingStore(QWindow *window)
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
static quint64 getTimestamp()
QPlatformServices * services() const override
QPlatformClipboard * clipboard() const override
Accessor for the platform integration's clipboard.
QPlatformTheme * createPlatformTheme(const QString &name) const override
void resizeScreen(const emscripten::val &canvas)
QVariant styleHint(QPlatformIntegration::StyleHint hint) const override
bool hasCapability(QPlatformIntegration::Capability cap) const override
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
QPlatformAccessibility * accessibility() const override
static QWasmScreen * get(QPlatformScreen *screen)
QWasmCompositor * compositor()
static void handlePrimaryScreenChanged(QPlatformScreen *newPrimary)
Should be called whenever the primary screen changes.
static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary=false)
Should be called by the implementation whenever a new screen is added.
static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
void Q_GUI_EXPORT qt_set_sequence_auto_mnemonic(bool b)
static QOpenGLCompositor * compositor
GLenum GLenum GLenum GLenum mapping
#define Q_ASSERT_X(cond, x, msg)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_CONFIG(feature)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
unsigned long long quint64
EMSCRIPTEN_BINDINGS(qtQWasmIntegraton)
static void addContainerElement(emscripten::val element)
static void removeContainerElement(emscripten::val element)
QT_BEGIN_NAMESPACE void qt_set_sequence_auto_mnemonic(bool)
static void resizeAllScreens(emscripten::val event)
static void resizeContainerElement(emscripten::val element)
static void setContainerElements(emscripten::val elementArray)
static void qtUpdateDpi()
if(qFloatDistance(a, b)<(1<< 7))
[0]