From 22c3c55de44b9b900b5e4d7040a9c3f906d0bfa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 26 Apr 2019 15:33:49 +0200 Subject: wasm: install one browser window resize handler Install one browser window resize handler instead of per-canvas resize handlers, which avoids having to uninstall on QScreen destruction. Task-number: QTBUG-75463 Change-Id: I8345262a906ed735f8e9e146f1e963f515cf0d25 Reviewed-by: Lorn Potter --- .../platforms/wasm/qwasmeventtranslator.cpp | 18 ------------------ src/plugins/platforms/wasm/qwasmeventtranslator.h | 2 -- src/plugins/platforms/wasm/qwasmintegration.cpp | 22 ++++++++++++++++++++++ src/plugins/platforms/wasm/qwasmintegration.h | 1 + 4 files changed, 23 insertions(+), 20 deletions(-) (limited to 'src/plugins/platforms/wasm') diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index 7126c00354..f586c5378e 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -375,9 +375,6 @@ void QWasmEventTranslator::initEventHandlers() emscripten_set_touchend_callback(canvasId, (void *)this, 1, &touchCallback); emscripten_set_touchmove_callback(canvasId, (void *)this, 1, &touchCallback); emscripten_set_touchcancel_callback(canvasId, (void *)this, 1, &touchCallback); - - emscripten_set_resize_callback(nullptr, (void *)this, 1, uiEvent_cb); // Note: handles browser window resize - } template @@ -909,19 +906,4 @@ bool QWasmEventTranslator::processKeyboard(int eventType, const EmscriptenKeyboa return accepted; } -int QWasmEventTranslator::uiEvent_cb(int eventType, const EmscriptenUiEvent *e, void *userData) -{ - Q_UNUSED(e) - QWasmEventTranslator *eventTranslator = static_cast(userData); - - if (eventType == EMSCRIPTEN_EVENT_RESIZE) { - // This resize event is called when the HTML window is resized. Depending - // on the page layout the the canvas might also have been resized, so we - // update the Qt screen size (and canvas render size). - eventTranslator->screen()->updateQScreenAndCanvasRenderSize(); - } - - return 0; -} - QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.h b/src/plugins/platforms/wasm/qwasmeventtranslator.h index d6043072ba..1655b7226a 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.h +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.h @@ -57,8 +57,6 @@ public: static int touchCallback(int eventType, const EmscriptenTouchEvent *ev, void *userData); - static int uiEvent_cb(int eventType, const EmscriptenUiEvent *e, void *userData); - void processEvents(); void initEventHandlers(); int handleTouch(int eventType, const EmscriptenTouchEvent *touchEvent); diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index e601d553f2..703b0fde0b 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -115,6 +115,21 @@ QWasmIntegration::QWasmIntegration() } emscripten::val::global("window").set("onbeforeunload", val::module_property("qtBrowserBeforeUnload")); + + // install browser window resize handler + auto onWindowResize = [](int eventType, const EmscriptenUiEvent *e, void *userData) -> int { + Q_UNUSED(eventType); + Q_UNUSED(e); + Q_UNUSED(userData); + + // This resize event is called when the HTML window is resized. Depending + // on the page layout the the canvas(es) might also have been resized, so we + // update the Qt screen sizes (and canvas render sizes). + if (QWasmIntegration *integration = QWasmIntegration::get()) + integration->resizeAllScreens(); + return 0; + }; + emscripten_set_resize_callback(nullptr, nullptr, 1, onWindowResize); } QWasmIntegration::~QWasmIntegration() @@ -245,4 +260,11 @@ void QWasmIntegration::resizeScreen(const QString &canvasId) m_screens.value(canvasId)->updateQScreenAndCanvasRenderSize(); } +void QWasmIntegration::resizeAllScreens() +{ + qDebug() << "resizeAllScreens"; + for (QWasmScreen *screen : m_screens) + screen->updateQScreenAndCanvasRenderSize(); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasmintegration.h b/src/plugins/platforms/wasm/qwasmintegration.h index 11d8d0f7f5..d5011db067 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.h +++ b/src/plugins/platforms/wasm/qwasmintegration.h @@ -81,6 +81,7 @@ public: void addScreen(const QString &canvasId); void removeScreen(const QString &canvasId); void resizeScreen(const QString &canvasId); + void resizeAllScreens(); private: mutable QWasmFontDatabase *m_fontDb; -- cgit v1.2.3