From 7c33f4be022d87c5a83d728cceb5673cd55ed346 Mon Sep 17 00:00:00 2001 From: Mikolaj Boc Date: Wed, 1 Feb 2023 13:19:33 +0100 Subject: Support window masks on WASM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWasmWindow is now implementing the setMask method, which translates the received QRegion to a css clip path Fixes: QTBUG-73260 Change-Id: Ie934c1e6ab650426bfc32154bf9e49a4a2aeb45b Reviewed-by: Aleksandr Reviakin Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmwindow.cpp | 24 ++++++++++++++++++++++-- src/plugins/platforms/wasm/qwasmwindow.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index be0dd74797..1dc43b61bb 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -20,9 +20,9 @@ #include "qwasmaccessibility.h" #include -#include +#include -#include +#include #include @@ -544,6 +544,26 @@ bool QWasmWindow::windowEvent(QEvent *event) } } +void QWasmWindow::setMask(const QRegion ®ion) +{ + if (region.isEmpty()) { + m_qtWindow["style"].set("clipPath", emscripten::val("")); + return; + } + + std::ostringstream cssClipPath; + cssClipPath << "path('"; + for (const auto &rect : region) { + const auto cssRect = rect.adjusted(0, 0, 1, 1); + cssClipPath << "M " << cssRect.left() << " " << cssRect.top() << " "; + cssClipPath << "L " << cssRect.right() << " " << cssRect.top() << " "; + cssClipPath << "L " << cssRect.right() << " " << cssRect.bottom() << " "; + cssClipPath << "L " << cssRect.left() << " " << cssRect.bottom() << " z "; + } + cssClipPath << "')"; + m_qtWindow["style"].set("clipPath", emscripten::val(cssClipPath.str())); +} + std::string QWasmWindow::canvasSelector() const { return "!qtwindow" + std::to_string(m_winId); diff --git a/src/plugins/platforms/wasm/qwasmwindow.h b/src/plugins/platforms/wasm/qwasmwindow.h index d90e828283..7f4047b758 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.h +++ b/src/plugins/platforms/wasm/qwasmwindow.h @@ -75,6 +75,7 @@ public: bool setKeyboardGrabEnabled(bool) override { return false; } bool setMouseGrabEnabled(bool grab) final; bool windowEvent(QEvent *event) final; + void setMask(const QRegion ®ion) final; QWasmScreen *platformScreen() const; void setBackingStore(QWasmBackingStore *store) { m_backingStore = store; } -- cgit v1.2.3