summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2023-09-12 17:59:09 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-11-11 10:45:38 +0000
commit45cab397e8fe8997db3557a98855b9690beb4c7c (patch)
tree0eecc116d7ad186b68e29ef0c6609142ed08695f
parent1d261f3a54f068d5c7aa9fe37e833927a8261e6a (diff)
wasm: Improve screen cleanup
Fix the use case where the application recreates the QApplication object while reusing the html container element. This would cause an error: Uncaught DOMException: Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree It looks like there is no way to remove a previously attached shadow root, which means we can't return the container element to its initial state if we attach to the user-provided container element. Fix this by introducing an intermediate element which we can remove() in the QWasmScreen destructor. Pick-to: 6.5 Change-Id: I929393a498b0440390a3e2c1774a3cac3a5a7e79 Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com> (cherry picked from commit 0e23865c9ed0cf6560df8c7c5fcea6e0eef1160e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/platforms/wasm/qwasmscreen.cpp16
-rw-r--r--src/plugins/platforms/wasm/qwasmscreen.h1
2 files changed, 16 insertions, 1 deletions
diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp
index e09e942c27..c035de4a33 100644
--- a/src/plugins/platforms/wasm/qwasmscreen.cpp
+++ b/src/plugins/platforms/wasm/qwasmscreen.cpp
@@ -28,6 +28,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<QWasmDeadKeySupport>())
@@ -43,9 +44,20 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas)
m_container["parentNode"].call<void>("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<emscripten::val>("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<void>("appendChild", m_intermediateContainer);
+
auto shadowOptions = emscripten::val::object();
shadowOptions.set("mode", "open");
- auto shadow = m_container.call<emscripten::val>("attachShadow", shadowOptions);
+ auto shadow = m_intermediateContainer.call<emscripten::val>("attachShadow", shadowOptions);
m_shadowContainer = document.call<emscripten::val>("createElement", emscripten::val("div"));
@@ -86,6 +98,8 @@ QWasmScreen::QWasmScreen(const emscripten::val &containerOrCanvas)
QWasmScreen::~QWasmScreen()
{
+ m_intermediateContainer.call<void>("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 633cf853f7..e0195549f9 100644
--- a/src/plugins/platforms/wasm/qwasmscreen.h
+++ b/src/plugins/platforms/wasm/qwasmscreen.h
@@ -66,6 +66,7 @@ public slots:
private:
emscripten::val m_container;
+ emscripten::val m_intermediateContainer;
emscripten::val m_shadowContainer;
std::unique_ptr<QWasmCompositor> m_compositor;
std::unique_ptr<QPointingDevice> m_touchDevice;