diff --git a/src/plugins/platforms/wasm/qwasmcssstyle.cpp b/src/plugins/platforms/wasm/qwasmcssstyle.cpp index 79b1964d22..409aad88c7 100644 --- a/src/plugins/platforms/wasm/qwasmcssstyle.cpp +++ b/src/plugins/platforms/wasm/qwasmcssstyle.cpp @@ -53,7 +53,9 @@ const char *Style = R"css( display: none; } -.qt-window.has-frame:not(.maximized) .resize-outline { +.qt-window.no-resize > .resize-outline { display: none; } + +.qt-window.has-frame:not(.maximized):not(.no-resize) .resize-outline { display: block; } diff --git a/src/plugins/platforms/wasm/qwasmwindow.cpp b/src/plugins/platforms/wasm/qwasmwindow.cpp index 9ee3c37f85..d728ec64a8 100644 --- a/src/plugins/platforms/wasm/qwasmwindow.cpp +++ b/src/plugins/platforms/wasm/qwasmwindow.cpp @@ -351,6 +351,7 @@ void QWasmWindow::propagateSizeHints() rect.setSize(windowMinimumSize()); setGeometry(rect); } + m_nonClientArea->propagateSizeHints(); } void QWasmWindow::invalidate() diff --git a/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp b/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp index 68f1442510..bc597069e7 100644 --- a/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp +++ b/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp @@ -178,6 +178,22 @@ Resizer::Resizer(QWasmWindow *window, emscripten::val parentElement) Resizer::~Resizer() = default; +ResizeConstraints Resizer::getResizeConstraints() { + const auto *window = m_window->window(); + const auto minShrink = QPoint(window->minimumWidth() - window->geometry().width(), + window->minimumHeight() - window->geometry().height()); + const auto maxGrow = QPoint(window->maximumWidth() - window->geometry().width(), + window->maximumHeight() - window->geometry().height()); + + const auto frameRect = + QRectF::fromDOMRect(m_windowElement.call("getBoundingClientRect")); + const auto screenRect = QRectF::fromDOMRect( + m_window->platformScreen()->element().call("getBoundingClientRect")); + const int maxGrowTop = frameRect.top() - screenRect.top(); + + return ResizeConstraints{minShrink, maxGrow, maxGrowTop}; +} + void Resizer::onInteraction() { m_window->onNonClientAreaInteraction(); @@ -193,23 +209,14 @@ void Resizer::startResize(Qt::Edges resizeEdges, const PointerEvent &event) event.target, m_window->platformScreen()->element(), event.localPoint), }); - const auto *window = m_window->window(); - m_currentResizeData->minShrink = QPoint(window->minimumWidth() - window->geometry().width(), - window->minimumHeight() - window->geometry().height()); - - const auto frameRect = - QRectF::fromDOMRect(m_windowElement.call("getBoundingClientRect")); - const auto screenRect = QRectF::fromDOMRect( - m_window->platformScreen()->element().call("getBoundingClientRect")); - - const int maxGrowTop = frameRect.top() - screenRect.top(); - + const auto resizeConstraints = getResizeConstraints(); + m_currentResizeData->minShrink = resizeConstraints.minShrink; m_currentResizeData->maxGrow = - QPoint(window->maximumWidth() - window->geometry().width(), - std::min(resizeEdges & Qt::Edge::TopEdge ? maxGrowTop : INT_MAX, - window->maximumHeight() - window->geometry().height())); + QPoint(resizeConstraints.maxGrow.x(), + std::min(resizeEdges & Qt::Edge::TopEdge ? resizeConstraints.maxGrowTop : INT_MAX, + resizeConstraints.maxGrow.y())); - m_currentResizeData->initialBounds = window->geometry(); + m_currentResizeData->initialBounds = m_window->window()->geometry(); } void Resizer::continueResize(const PointerEvent &event) @@ -414,9 +421,11 @@ QPointF TitleBar::clipPointWithScreen(const QPointF &pointInTitleBarCoords) cons } NonClientArea::NonClientArea(QWasmWindow *window, emscripten::val qtWindowElement) + : m_qtWindowElement(qtWindowElement), + m_resizer(std::make_unique(window, m_qtWindowElement)), + m_titleBar(std::make_unique(window, m_qtWindowElement)) { - m_titleBar = std::make_unique(window, qtWindowElement); - m_resizer = std::make_unique(window, qtWindowElement); + updateResizability(); } NonClientArea::~NonClientArea() = default; @@ -426,4 +435,17 @@ void NonClientArea::onClientAreaWidthChange(int width) m_titleBar->setWidth(width); } +void NonClientArea::propagateSizeHints() +{ + updateResizability(); +} + +void NonClientArea::updateResizability() +{ + const auto resizeConstraints = m_resizer->getResizeConstraints(); + const bool nonResizable = resizeConstraints.minShrink.isNull() + && resizeConstraints.maxGrow.isNull() && resizeConstraints.maxGrowTop == 0; + dom::syncCSSClassWith(m_qtWindowElement, "no-resize", nonResizable); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasmwindownonclientarea.h b/src/plugins/platforms/wasm/qwasmwindownonclientarea.h index 29168b9957..78c77585a0 100644 --- a/src/plugins/platforms/wasm/qwasmwindownonclientarea.h +++ b/src/plugins/platforms/wasm/qwasmwindownonclientarea.h @@ -34,9 +34,13 @@ public: ~NonClientArea(); void onClientAreaWidthChange(int width); + void propagateSizeHints(); TitleBar *titleBar() const { return m_titleBar.get(); } private: + void updateResizability(); + + emscripten::val m_qtWindowElement; std::unique_ptr m_resizer; std::unique_ptr m_titleBar; }; @@ -87,6 +91,12 @@ private: Callbacks m_callbacks; }; +struct ResizeConstraints { + QPoint minShrink; + QPoint maxGrow; + int maxGrowTop; +}; + class Resizer { public: @@ -147,6 +157,8 @@ public: Resizer(QWasmWindow *window, emscripten::val parentElement); ~Resizer(); + ResizeConstraints getResizeConstraints(); + private: void onInteraction(); void startResize(Qt::Edges resizeEdges, const PointerEvent &event);