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 <lorn.potter@gmail.com>
Morten Johan Sørvig 2019-04-26 15:33:49 +02:00 committed by Jani Heikkinen
parent bac2b0ef36
commit 22c3c55de4
4 changed files with 23 additions and 20 deletions

View File

@ -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 <typename Event>
@ -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<QWasmEventTranslator *>(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

View File

@ -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);

View File

@ -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

View File

@ -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;