diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index 0a99b46af84..9963f39b6b4 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -29,6 +29,7 @@ const char *QWasmScreen::m_canvasResizeObserverCallbackContextPropertyName = QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas) : m_container(containerOrCanvas), + m_intermediateContainer(emscripten::val::undefined()), m_shadowContainer(emscripten::val::undefined()), m_compositor(new QWasmCompositor(this)), m_deadKeySupport(std::make_unique()) @@ -44,9 +45,20 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas) m_container["parentNode"].call("replaceChild", container, m_container); m_container = container; } + + // Create an intermediate container which we can remove during cleanup in ~QWasmScreen(). + // This is required due to the attachShadow() call below; there is no corresponding + // "detachShadow()" API to return the container to its previous state. + m_intermediateContainer = document.call("createElement", emscripten::val("div")); + m_intermediateContainer.set("id", std::string("qt-shadow-container")); + emscripten::val intermediateContainerStyle = m_intermediateContainer["style"]; + intermediateContainerStyle.set("width", std::string("100%")); + intermediateContainerStyle.set("height", std::string("100%")); + m_container.call("appendChild", m_intermediateContainer); + auto shadowOptions = emscripten::val::object(); shadowOptions.set("mode", "open"); - auto shadow = m_container.call("attachShadow", shadowOptions); + auto shadow = m_intermediateContainer.call("attachShadow", shadowOptions); m_shadowContainer = document.call("createElement", emscripten::val("div")); @@ -87,6 +99,8 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas) QWasmScreen::~QWasmScreen() { + m_intermediateContainer.call("remove"); + emscripten::val::module_property("specialHTMLTargets") .set(eventTargetId().toStdString(), emscripten::val::undefined()); diff --git a/src/plugins/platforms/wasm/qwasmscreen.h b/src/plugins/platforms/wasm/qwasmscreen.h index 47ce11495f2..e860b5d4655 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.h +++ b/src/plugins/platforms/wasm/qwasmscreen.h @@ -78,6 +78,7 @@ private: QWasmWindow *child) final; emscripten::val m_container; + emscripten::val m_intermediateContainer; emscripten::val m_shadowContainer; std::unique_ptr m_compositor; std::unique_ptr m_touchDevice;