diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2019-03-16 23:58:36 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2019-04-01 07:18:05 +0000 |
commit | 69beb5f5a04bbb5b7fd64e69d1a655c0f5d956cb (patch) | |
tree | 25ea750e70d38da66c72e98676138abb0bf474b0 /src/plugins/platforms/wasm | |
parent | 73db765aaf9fad622f050e55e1d240329da0a07c (diff) |
wasm: add resizeCanvasElement() API to qtloader.js
HTMl does not have per-element resize events, which
means Qt has not way of knowing that a canvas has been
resized and that the canvas buffer size should be updated.
Depending on the use case, the hosting JavaScript code
that caused the canvas resize could also inform Qt
that the canvas has been resized. Add API to do this,
which calls the existing canvas/screen resize implementation.
Other solutions taken/not taken:
- browser window resize events: these are available,
and we install an event handler in qwasmeventtranslator.cpp.
- DOM mutation events: would detect changes to the
the size attributes themselves, but not if the size
indirectly changed, e.g. “width: 100%” depends on the
parent width. Not implemented.
Change-Id: Ib324bb30f523e9fceea68000b95bf857a1d36b6c
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm')
-rw-r--r-- | src/plugins/platforms/wasm/qtloader.js | 8 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmintegration.cpp | 12 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmintegration.h | 1 |
3 files changed, 21 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index 9bacce5944..3cbb1c8aa8 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -122,6 +122,8 @@ // Add canvas at run-time. Adds a corresponding QScreen, // removeCanvasElement // Remove canvas at run-time. Removes the corresponding QScreen. +// resizeCanvasElement +// Signals to the application that a canvas has been resized. var Module = {} @@ -233,6 +235,7 @@ function QtLoader(config) publicAPI.loadEmscriptenModule = loadEmscriptenModule; publicAPI.addCanvasElement = addCanvasElement; publicAPI.removeCanvasElement = removeCanvasElement; + publicAPI.resizeCanvasElement = resizeCanvasElement; restartCount = 0; @@ -548,6 +551,11 @@ function QtLoader(config) console.log("Error: removeCanvasElement can only be called in the Running state"); } + function resizeCanvasElement(element) { + if (publicAPI.status == "Running") + Module.qtResizeCanvasElement(element); + } + setStatus("Created"); return publicAPI; diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 44b4546dc6..55bb167fcc 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -73,11 +73,18 @@ static void removeCanvasElement(emscripten::val canvas) QWasmIntegration::get()->removeScreen(canvasId); } +static void resizeCanvasElement(emscripten::val canvas) +{ + QString canvasId = QString::fromStdString(canvas["id"].as<std::string>()); + QWasmIntegration::get()->resizeScreen(canvasId); +} + EMSCRIPTEN_BINDINGS(qtQWasmIntegraton) { function("qtBrowserBeforeUnload", &browserBeforeUnload); function("qtAddCanvasElement", &addCanvasElement); function("qtRemoveCanvasElement", &removeCanvasElement); + function("qtResizeCanvasElement", &resizeCanvasElement); } QWasmIntegration *QWasmIntegration::s_instance; @@ -212,4 +219,9 @@ void QWasmIntegration::removeScreen(const QString &canvasId) QWindowSystemInterface::handleScreenRemoved(m_screens.take(canvasId)); } +void QWasmIntegration::resizeScreen(const QString &canvasId) +{ + m_screens.value(canvasId)->updateQScreenAndCanvasRenderSize(); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasmintegration.h b/src/plugins/platforms/wasm/qwasmintegration.h index 01ce6ec007..2239bdc118 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.h +++ b/src/plugins/platforms/wasm/qwasmintegration.h @@ -77,6 +77,7 @@ public: void addScreen(const QString &canvasId); void removeScreen(const QString &canvasId); + void resizeScreen(const QString &canvasId); private: mutable QWasmFontDatabase *m_fontDb; |