19#include <qpa/qplatformwindow.h>
20#include <QtGui/qscreen.h>
21#include <qpa/qwindowsysteminterface.h>
22#include <QtCore/qcoreapplication.h>
23#include <qpa/qplatforminputcontextfactory_p.h>
24#include <qpa/qwindowsysteminterface_p.h>
26#include <emscripten/bind.h>
27#include <emscripten/val.h>
31#include <private/qsimpledrag_p.h>
95 , m_accessibility(new QWasmAccessibility)
103 touchPoints = emscripten::val::global(
"navigator")[
"maxTouchPoints"].as<
int>();
110 emscripten::val filtered = emscripten::val::array();
111 emscripten::val qtContainerElements = val::module_property(
"qtContainerElements");
112 if (qtContainerElements.isArray()) {
113 for (
int i = 0;
i < qtContainerElements[
"length"].as<
int>(); ++
i) {
114 emscripten::val element = qtContainerElements[
i].as<emscripten::val>();
115 if (element.isNull() || element.isUndefined())
116 qWarning() <<
"Skipping null or undefined element in qtContainerElements";
118 filtered.call<
void>(
"push", element);
122 qWarning() <<
"The qtContainerElements module property was not set or is invalid. "
123 "Proceeding with no screens.";
128 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
nullptr, EM_TRUE,
129 [](
int,
const EmscriptenUiEvent *,
void *) ->
int {
135 integration->resizeAllScreens();
140 emscripten::val visualViewport = emscripten::val::global(
"window")[
"visualViewport"];
141 if (!visualViewport.isUndefined()) {
142 visualViewport.call<
void>(
"addEventListener",
val(
"resize"),
143 val::module_property(
"qtResizeAllScreens"));
145 m_drag = std::make_unique<QWasmDrag>();
151 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
nullptr, EM_TRUE,
nullptr);
152 emscripten::val visualViewport = emscripten::val::global(
"window")[
"visualViewport"];
153 if (!visualViewport.isUndefined()) {
154 visualViewport.call<
void>(
"removeEventListener",
val(
"resize"),
155 val::module_property(
"qtResizeAllScreens"));
159 delete m_desktopServices;
160 if (m_platformInputContext)
161 delete m_platformInputContext;
162#if QT_CONFIG(accessibility)
163 delete m_accessibility;
166 for (
const auto &elementAndScreen : m_screens)
167 elementAndScreen.wasmScreen->deleteScreen();
171 s_instance =
nullptr;
213 for (
const auto &elementAndScreen : m_screens) {
214 elementAndScreen.wasmScreen->compositor()->requestUpdate();
232 if (!icStrs.isEmpty())
240 return m_inputContext.
data();
250 if (m_fontDb ==
nullptr)
289 if (
name ==
"webassembly"_L1)
296 if (m_desktopServices ==
nullptr)
298 return m_desktopServices;
306#ifndef QT_NO_ACCESSIBILITY
309 return m_accessibility;
315 const auto *primaryScreenBefore = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
316 QList<ScreenMapping> newScreens;
318 QList<QWasmScreen *> screensToDelete;
319 std::transform(m_screens.
begin(), m_screens.
end(), std::back_inserter(screensToDelete),
320 [](
const ScreenMapping &
mapping) { return mapping.wasmScreen; });
322 for (
int i = 0;
i < elementArray[
"length"].as<
int>(); ++
i) {
323 const auto element = elementArray[
i];
324 const auto it = std::find_if(
326 [&element](
const ScreenMapping &
screen) { return screen.emscriptenVal == element; });
328 if (
it != m_screens.
end()) {
330 screensToDelete.
erase(std::remove_if(screensToDelete.begin(), screensToDelete.end(),
332 return removedScreen == screen;
334 screensToDelete.end());
339 newScreens.push_back({element,
screen});
342 std::for_each(screensToDelete.begin(), screensToDelete.end(),
343 [](
QWasmScreen *removed) { removed->deleteScreen(); });
345 m_screens = newScreens;
346 auto *primaryScreenAfter = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
347 if (primaryScreenAfter && primaryScreenAfter != primaryScreenBefore)
354 == std::find_if(m_screens.
begin(), m_screens.
end(),
355 [&element](
const ScreenMapping &
screen) {
356 return screen.emscriptenVal == element;
367 const auto *primaryScreenBefore = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
370 std::find_if(m_screens.
begin(), m_screens.
end(),
371 [&element](
const ScreenMapping &
screen) { return screen.emscriptenVal == element; });
372 if (
it == m_screens.
end()) {
373 qWarning() <<
"Attempt to remove a nonexistent screen.";
378 removedScreen->deleteScreen();
380 m_screens.
erase(std::remove_if(m_screens.
begin(), m_screens.
end(),
381 [removedScreen](
const ScreenMapping &
mapping) {
382 return removedScreen == mapping.wasmScreen;
385 auto *primaryScreenAfter = m_screens.
isEmpty() ?
nullptr : m_screens[0].wasmScreen;
386 if (primaryScreenAfter && primaryScreenAfter != primaryScreenBefore)
392 auto it = std::find_if(m_screens.
begin(), m_screens.
end(),
393 [&] (
const ScreenMapping &candidate) { return candidate.emscriptenVal.equals(element); });
394 if (
it == m_screens.
end()) {
395 qWarning() <<
"Attempting to resize non-existing screen for element"
396 << QString::fromEcmaString(element[
"id"]);
399 it->wasmScreen->updateQScreenAndCanvasRenderSize();
404 emscripten::val dpi = emscripten::val::module_property(
"qtFontDpi");
405 if (dpi.isUndefined())
408 for (
const auto &elementAndScreen : m_screens)
414 for (
const auto &elementAndScreen : m_screens)
415 elementAndScreen.wasmScreen->updateQScreenAndCanvasRenderSize();
425 return emscripten_performance_now();
428#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 QPlatformInputContext * create()
static QStringList requested()
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.
iterator erase(const_iterator i)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static bool releaseRequestUpdateHold()
void populateLocalFontFamilies(emscripten::val families)
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
void releaseRequesetUpdateHold()
void loadLocalFontFamilies(emscripten::val families)
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)
static void setPlatformSynthesizesMouse(bool v)
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.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
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)
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 loadLocalFontFamilies(emscripten::val event)
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]