From 960af0d64de576321db91ccbe426891465b24540 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 30 Jan 2019 18:17:39 +1000 Subject: wasm: remove EM_ASM calls in wasm platform plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8453836b6730d18eaaa4ffe1fb9cb3933079ebee Reviewed-by: Edward Welbourne Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmintegration.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 1be909f0a0..7a44c47893 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -55,7 +55,7 @@ using namespace emscripten; QT_BEGIN_NAMESPACE -void browserBeforeUnload() +void browserBeforeUnload(emscripten::val) { QWasmIntegration::QWasmBrowserExit(); } @@ -83,11 +83,8 @@ QWasmIntegration::QWasmIntegration() m_eventTranslator = new QWasmEventTranslator; - EM_ASM(// exit app if browser closes - window.onbeforeunload = function () { - Module.browserBeforeUnload(); - }; - ); + emscripten::val::global("window").set("onbeforeunload", val::module_property("browserBeforeUnload")); + } QWasmIntegration::~QWasmIntegration() @@ -187,11 +184,9 @@ int QWasmIntegration::uiEvent_cb(int eventType, const EmscriptenUiEvent *e, void static void set_canvas_size(double width, double height) { - EM_ASM_({ - var canvas = Module.canvas; - canvas.width = $0; - canvas.height = $1; - }, width, height); + emscripten::val canvas = emscripten::val::global("canvas"); + canvas.set("width", width); + canvas.set("height", height); } void QWasmIntegration::updateQScreenAndCanvasRenderSize() -- cgit v1.2.3 From 2c6c724949374b17bd3da2938fe8747b480d575a Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Thu, 22 Feb 2018 04:35:25 +1000 Subject: wasm: add clipboard support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This feature uses the js Clipboard API and is supported only in Chrome, as Firefox only supports reading the clipboard in browser extensions. It also requires https or localhost access, otherwise access to the clipboard is blocked by chrome. Chrome users will be able to copy/paste text to and from the system clipbaord. Other browsers will be able to use the clipboard from within the same application. Currently only supports text and html. Task-number: QTBUG-64638 Change-Id: Ie6de9d10812b776519bd6115593b433fe77059fe Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmintegration.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 7a44c47893..6f96ec69da 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -33,6 +33,7 @@ #include "qwasmcompositor.h" #include "qwasmopenglcontext.h" #include "qwasmtheme.h" +#include "qwasmclipboard.h" #include "qwasmwindow.h" #ifndef QT_NO_OPENGL @@ -65,17 +66,16 @@ EMSCRIPTEN_BINDINGS(my_module) function("browserBeforeUnload", &browserBeforeUnload); } -static QWasmIntegration *globalHtml5Integration; -QWasmIntegration *QWasmIntegration::get() { return globalHtml5Integration; } +QWasmIntegration *QWasmIntegration::s_instance; QWasmIntegration::QWasmIntegration() : m_fontDb(nullptr), m_compositor(new QWasmCompositor), m_screen(new QWasmScreen(m_compositor)), - m_eventDispatcher(nullptr) + m_eventDispatcher(nullptr), + m_clipboard(new QWasmClipboard) { - - globalHtml5Integration = this; + s_instance = this; updateQScreenAndCanvasRenderSize(); screenAdded(m_screen); @@ -93,6 +93,7 @@ QWasmIntegration::~QWasmIntegration() destroyScreen(m_screen); delete m_fontDb; delete m_eventTranslator; + s_instance = nullptr; } void QWasmIntegration::QWasmBrowserExit() @@ -211,4 +212,11 @@ void QWasmIntegration::updateQScreenAndCanvasRenderSize() QWasmIntegration::get()->m_compositor->redrawWindowContent(); } +QPlatformClipboard* QWasmIntegration::clipboard() const +{ + if (!m_clipboard) + m_clipboard = new QWasmClipboard; + return m_clipboard; +} + QT_END_NAMESPACE -- cgit v1.2.3 From 452c644c5c51d78d72dde703c81fc7789e5b84f1 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Thu, 31 Jan 2019 14:06:39 +1000 Subject: wasm: make wasm platform target a specific canvas instead of default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows for multi canvas use Task-number: QTBUG-64079 Change-Id: I69c998aa4c2869bb5b7f14ba65bb63284365ad70 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmintegration.cpp | 55 ++++--------------------- 1 file changed, 9 insertions(+), 46 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 6f96ec69da..f45048ffa4 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -75,11 +75,18 @@ QWasmIntegration::QWasmIntegration() m_eventDispatcher(nullptr), m_clipboard(new QWasmClipboard) { + + globalHtml5Integration = this; s_instance = this; - updateQScreenAndCanvasRenderSize(); + emscripten::val defaultCanvasId = emscripten::val::global("canvas"); + canvasIds.append(QString::fromStdString(defaultCanvasId["id"].as())); + m_screen->setCanvas(canvasIds.at(0)); + + globalHtml5Integration = this; + + screen()->updateQScreenAndCanvasRenderSize(m_screen->m_canvasId); screenAdded(m_screen); - emscripten_set_resize_callback(0, (void *)this, 1, uiEvent_cb); m_eventTranslator = new QWasmEventTranslator; @@ -168,50 +175,6 @@ QPlatformTheme *QWasmIntegration::createPlatformTheme(const QString &name) const return QPlatformIntegration::createPlatformTheme(name); } -int QWasmIntegration::uiEvent_cb(int eventType, const EmscriptenUiEvent *e, void *userData) -{ - Q_UNUSED(e) - Q_UNUSED(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). - updateQScreenAndCanvasRenderSize(); - } - - return 0; -} - -static void set_canvas_size(double width, double height) -{ - emscripten::val canvas = emscripten::val::global("canvas"); - canvas.set("width", width); - canvas.set("height", height); -} - -void QWasmIntegration::updateQScreenAndCanvasRenderSize() -{ - // The HTML canvas has two sizes: the CSS size and the canvas render size. - // The CSS size is determined according to standard CSS rules, while the - // render size is set using the "width" and "height" attributes. The render - // size must be set manually and is not auto-updated on CSS size change. - // Setting the render size to a value larger than the CSS size enables high-dpi - // rendering. - - double css_width; - double css_height; - emscripten_get_element_css_size(0, &css_width, &css_height); - QSizeF cssSize(css_width, css_height); - - QWasmScreen *screen = QWasmIntegration::get()->m_screen; - QSizeF canvasSize = cssSize * screen->devicePixelRatio(); - - set_canvas_size(canvasSize.width(), canvasSize.height()); - screen->setGeometry(QRect(QPoint(0, 0), cssSize.toSize())); - QWasmIntegration::get()->m_compositor->redrawWindowContent(); -} - QPlatformClipboard* QWasmIntegration::clipboard() const { if (!m_clipboard) -- cgit v1.2.3 From caa74f16d41ebe65e1edbea219f799cf246d6067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 15 Feb 2019 22:04:09 +0100 Subject: wasm: support rendering to multiple canvases Qt (via the the qtloader.js API) now supports rendering to multiple canvases. The application sees each canvas as a QScreen. Make qtloader.js support multiple canvases: var qtloader = QtLoader({ canvasElements : [array-of-canvas], showCanvas: function() { // make canvas(es) visible }, }); The canvases were previously created/returned by showCanvas(), however this function is called after the Qt app has been started and adding screens that that point is too late. (This worked before since there was only one screen, and no need to connect each screen instance to specific canvas.) Remove QWasmScreen, QWasmCompositor, and QWasmEventTranslator singletons from QWasmIntegration. These are are now crated per-screen and are owned by the QWasmScreen. Task-number: QTBUG-64079 Change-Id: I24689929fd5bfb7ff0ba076f66937728fa4bc4e4 Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmintegration.cpp | 56 +++++++++++++++---------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index f45048ffa4..1964cefdad 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -70,36 +70,35 @@ QWasmIntegration *QWasmIntegration::s_instance; QWasmIntegration::QWasmIntegration() : m_fontDb(nullptr), - m_compositor(new QWasmCompositor), - m_screen(new QWasmScreen(m_compositor)), m_eventDispatcher(nullptr), m_clipboard(new QWasmClipboard) { - - globalHtml5Integration = this; s_instance = this; - emscripten::val defaultCanvasId = emscripten::val::global("canvas"); - canvasIds.append(QString::fromStdString(defaultCanvasId["id"].as())); - m_screen->setCanvas(canvasIds.at(0)); - - globalHtml5Integration = this; - - screen()->updateQScreenAndCanvasRenderSize(m_screen->m_canvasId); - screenAdded(m_screen); - - m_eventTranslator = new QWasmEventTranslator; + // We expect that qtloader.js has populated Module.qtCanvasElements with one or more canvases. + // Also check Module.canvas, which may be set if the emscripen or a custom loader is used. + emscripten::val qtCanvaseElements = val::module_property("qtCanvasElements"); + emscripten::val canvas = val::module_property("canvas"); + + if (!qtCanvaseElements.isUndefined()) { + int screenCount = qtCanvaseElements["length"].as(); + for (int i = 0; i < screenCount; ++i) { + emscripten::val canvas = qtCanvaseElements[i].as(); + QString canvasId = QString::fromStdString(canvas["id"].as()); + addScreen(canvasId); + } + } else if (!canvas.isUndefined()){ + QString canvasId = QString::fromStdString(canvas["id"].as()); + addScreen(canvasId); + } emscripten::val::global("window").set("onbeforeunload", val::module_property("browserBeforeUnload")); - } QWasmIntegration::~QWasmIntegration() { - delete m_compositor; - destroyScreen(m_screen); delete m_fontDb; - delete m_eventTranslator; + qDeleteAll(m_screens); s_instance = nullptr; } @@ -124,13 +123,15 @@ bool QWasmIntegration::hasCapability(QPlatformIntegration::Capability cap) const QPlatformWindow *QWasmIntegration::createPlatformWindow(QWindow *window) const { - return new QWasmWindow(window, m_compositor, m_backingStores.value(window)); + QWasmCompositor *compositor = QWasmScreen::get(window->screen())->compositor(); + return new QWasmWindow(window, compositor, m_backingStores.value(window)); } QPlatformBackingStore *QWasmIntegration::createPlatformBackingStore(QWindow *window) const { #ifndef QT_NO_OPENGL - QWasmBackingStore *backingStore = new QWasmBackingStore(m_compositor, window); + QWasmCompositor *compositor = QWasmScreen::get(window->screen())->compositor(); + QWasmBackingStore *backingStore = new QWasmBackingStore(compositor, window); m_backingStores.insert(window, backingStore); return backingStore; #else @@ -177,9 +178,20 @@ QPlatformTheme *QWasmIntegration::createPlatformTheme(const QString &name) const QPlatformClipboard* QWasmIntegration::clipboard() const { - if (!m_clipboard) - m_clipboard = new QWasmClipboard; return m_clipboard; } +QVector QWasmIntegration::screens() +{ + return m_screens; +} + +void QWasmIntegration::addScreen(const QString &canvasId) +{ + QWasmScreen *screen = new QWasmScreen(canvasId); + m_clipboard->installEventHandlers(canvasId); + m_screens.append(screen); + screenAdded(screen); +} + QT_END_NAMESPACE -- cgit v1.2.3 From 01e1df90a7debd333314720fdd5cf6cd9964d796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 14 Mar 2019 00:36:34 +0100 Subject: Move screen maintenance functions from QPlatformIntegration to QWSI QWindowSystemInterface is the de facto API for any plumbing going from the platform plugin to QtGui. Having the functions as protected members of QPlatformIntegration was idiosyncratic, and resulted in awkward workarounds to be able to call the functions from outside of the QPlatformIntegration subclass. The functions in QPlatformIntegration have been left in, but deprecated so that platform plugins outside of qtbase have a chance to move over to the new QWSI API before they are removed. Change-Id: I327fec460db6b0faaf0ae2a151c20aa30dbe7182 Reviewed-by: Gatis Paeglis --- src/plugins/platforms/wasm/qwasmintegration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 1be909f0a0..3829043d07 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -78,7 +78,7 @@ QWasmIntegration::QWasmIntegration() globalHtml5Integration = this; updateQScreenAndCanvasRenderSize(); - screenAdded(m_screen); + QWindowSystemInterface::handleScreenAdded(m_screen); emscripten_set_resize_callback(0, (void *)this, 1, uiEvent_cb); m_eventTranslator = new QWasmEventTranslator; @@ -93,7 +93,7 @@ QWasmIntegration::QWasmIntegration() QWasmIntegration::~QWasmIntegration() { delete m_compositor; - destroyScreen(m_screen); + QWindowSystemInterface::handleScreenRemoved(m_screen); delete m_fontDb; delete m_eventTranslator; } -- cgit v1.2.3 From 98b3321e6fcade5fa8c3d3f33de327a93d13b78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 22 Mar 2019 09:51:11 +0100 Subject: wasm: disable threaded rendering Enabling makes QtQuick to attempt to access window.devicePixelRatio [via QWasmWindow::devicePixelRatio()] from a web worker. Change-Id: I957df29060c7eb8c47d02bc67c8c5c2219b570f4 Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmintegration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 499a82adbd..486f4cb2b3 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -116,7 +116,7 @@ bool QWasmIntegration::hasCapability(QPlatformIntegration::Capability cap) const switch (cap) { case ThreadedPixmaps: return true; case OpenGL: return true; - case ThreadedOpenGL: return true; + case ThreadedOpenGL: return false; case RasterGLSurface: return false; // to enable this you need to fix qopenglwidget and quickwidget for wasm case MultipleWindows: return true; case WindowManagement: return true; -- cgit v1.2.3 From f4ac50a8389597827fd7fb952617b78aa4b113c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 15 Mar 2019 15:04:59 +0100 Subject: =?UTF-8?q?wasm:=20Use=20common=20=E2=80=9Cqt=E2=80=9D=20prefix=20?= =?UTF-8?q?for=20exported=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent namespace collisions and make sure Qt functions are grouped together. Change-Id: I217188ee93e4300e273d10a79d6014179fc5a1ef Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmintegration.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 486f4cb2b3..3b4800a787 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -56,14 +56,14 @@ using namespace emscripten; QT_BEGIN_NAMESPACE -void browserBeforeUnload(emscripten::val) +static void browserBeforeUnload(emscripten::val) { QWasmIntegration::QWasmBrowserExit(); } -EMSCRIPTEN_BINDINGS(my_module) +EMSCRIPTEN_BINDINGS(qtQWasmIntegraton) { - function("browserBeforeUnload", &browserBeforeUnload); + function("qtBrowserBeforeUnload", &browserBeforeUnload); } QWasmIntegration *QWasmIntegration::s_instance; @@ -92,7 +92,7 @@ QWasmIntegration::QWasmIntegration() addScreen(canvasId); } - emscripten::val::global("window").set("onbeforeunload", val::module_property("browserBeforeUnload")); + emscripten::val::global("window").set("onbeforeunload", val::module_property("qtBrowserBeforeUnload")); } QWasmIntegration::~QWasmIntegration() -- cgit v1.2.3 From 73db765aaf9fad622f050e55e1d240329da0a07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 15 Mar 2019 19:42:17 +0100 Subject: wasm: support adding and removing canvases at runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add qtloader API: addCanvasElement() removeCanvasElement() These functions call the corresponding add/remove screen functions on QWasmIntegration. Task-number: QTBUG-64079 Change-Id: I537c11f3b5fb9240cca9b6313dd45f803d865ac6 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmintegration.cpp | 31 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 3b4800a787..44b4546dc6 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -61,9 +61,23 @@ static void browserBeforeUnload(emscripten::val) QWasmIntegration::QWasmBrowserExit(); } +static void addCanvasElement(emscripten::val canvas) +{ + QString canvasId = QString::fromStdString(canvas["id"].as()); + QWasmIntegration::get()->addScreen(canvasId); +} + +static void removeCanvasElement(emscripten::val canvas) +{ + QString canvasId = QString::fromStdString(canvas["id"].as()); + QWasmIntegration::get()->removeScreen(canvasId); +} + EMSCRIPTEN_BINDINGS(qtQWasmIntegraton) { function("qtBrowserBeforeUnload", &browserBeforeUnload); + function("qtAddCanvasElement", &addCanvasElement); + function("qtRemoveCanvasElement", &removeCanvasElement); } QWasmIntegration *QWasmIntegration::s_instance; @@ -99,8 +113,9 @@ QWasmIntegration::~QWasmIntegration() { delete m_fontDb; - while (!m_screens.isEmpty()) - QWindowSystemInterface::handleScreenRemoved(m_screens.takeLast()); + for (auto it = m_screens.constBegin(); it != m_screens.constEnd(); ++it) + QWindowSystemInterface::handleScreenRemoved(*it); + m_screens.clear(); s_instance = nullptr; } @@ -184,17 +199,17 @@ QPlatformClipboard* QWasmIntegration::clipboard() const return m_clipboard; } -QVector QWasmIntegration::screens() -{ - return m_screens; -} - void QWasmIntegration::addScreen(const QString &canvasId) { QWasmScreen *screen = new QWasmScreen(canvasId); m_clipboard->installEventHandlers(canvasId); - m_screens.append(screen); + m_screens.insert(canvasId, screen); QWindowSystemInterface::handleScreenAdded(screen); } +void QWasmIntegration::removeScreen(const QString &canvasId) +{ + QWindowSystemInterface::handleScreenRemoved(m_screens.take(canvasId)); +} + QT_END_NAMESPACE -- cgit v1.2.3 From 69beb5f5a04bbb5b7fd64e69d1a655c0f5d956cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Sat, 16 Mar 2019 23:58:36 +0100 Subject: wasm: add resizeCanvasElement() API to qtloader.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/plugins/platforms/wasm/qwasmintegration.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') 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()); + 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 -- cgit v1.2.3 From 81ed119da1215c9dda5ff202cc1339eadb62bda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 25 Mar 2019 14:54:58 +0100 Subject: wasm: make windows fullscreen by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (fullscreen as in use the entire canvas area, without showing window decorations) This is a better default for Qt on the web where window decorations are not common. We also avoid the “window close” trap, where there is no way to re-open a closed main window. Change-Id: Ie0fbf6ada3f49244bee765ea882acb473809e715 Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmintegration.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 55bb167fcc..374b2e7e32 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -186,9 +186,21 @@ QAbstractEventDispatcher *QWasmIntegration::createEventDispatcher() const QVariant QWasmIntegration::styleHint(QPlatformIntegration::StyleHint hint) const { + if (hint == ShowIsFullScreen) + return true; + return QPlatformIntegration::styleHint(hint); } +Qt::WindowState QWasmIntegration::defaultWindowState(Qt::WindowFlags flags) const +{ + // Don't maximize dialogs + if (flags & Qt::Dialog & ~Qt::Window) + return Qt::WindowNoState; + + return QPlatformIntegration::defaultWindowState(flags); +} + QStringList QWasmIntegration::themeNames() const { return QStringList() << QLatin1String("webassembly"); -- cgit v1.2.3 From f99fe9cee9d35e1fabbf45364631f4a7f049ebe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 1 Apr 2019 18:41:23 +0200 Subject: wasm: implement QDesktopServices::openUrl() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call window.open(url, ”_blank”) for a new tab. Change-Id: I227904f905262c7aedd086203ed816b53f66359c Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmintegration.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/wasm/qwasmintegration.cpp') diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 374b2e7e32..e601d553f2 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -34,6 +34,7 @@ #include "qwasmopenglcontext.h" #include "qwasmtheme.h" #include "qwasmclipboard.h" +#include "qwasmservices.h" #include "qwasmwindow.h" #ifndef QT_NO_OPENGL @@ -91,7 +92,7 @@ QWasmIntegration *QWasmIntegration::s_instance; QWasmIntegration::QWasmIntegration() : m_fontDb(nullptr), - m_eventDispatcher(nullptr), + m_desktopServices(nullptr), m_clipboard(new QWasmClipboard) { s_instance = this; @@ -119,6 +120,7 @@ QWasmIntegration::QWasmIntegration() QWasmIntegration::~QWasmIntegration() { delete m_fontDb; + delete m_desktopServices; for (auto it = m_screens.constBegin(); it != m_screens.constEnd(); ++it) QWindowSystemInterface::handleScreenRemoved(*it); @@ -213,6 +215,13 @@ QPlatformTheme *QWasmIntegration::createPlatformTheme(const QString &name) const return QPlatformIntegration::createPlatformTheme(name); } +QPlatformServices *QWasmIntegration::services() const +{ + if (m_desktopServices == nullptr) + m_desktopServices = new QWasmServices(); + return m_desktopServices; +} + QPlatformClipboard* QWasmIntegration::clipboard() const { return m_clipboard; -- cgit v1.2.3