summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorPiotr Wierciński <piotr.wiercinski@qt.io>2023-03-06 10:51:56 +0100
committerPiotr Wierciński <piotr.wiercinski@qt.io>2023-03-07 12:50:41 +0100
commit4d091523443285f9d3ee51c063aac40d79be39d1 (patch)
tree9e22bfe925bb8208da8a20a72eb0df6972448d06 /src/plugins/platforms
parent79cc3ae201483f42b8b333b29a7924ec1d4e2acd (diff)
Wasm: Hide resizing divs when the window is not resizable
Hide divs that are responsible for resizing the window and changing the appearance of the cursor on this window if this window is not resizable. Fixes: QTBUG-111618 Change-Id: I1948eaedf02fdd2a5289ae314521b3fd74ad7811 Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/wasm/qwasmcssstyle.cpp4
-rw-r--r--src/plugins/platforms/wasm/qwasmwindow.cpp1
-rw-r--r--src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp56
-rw-r--r--src/plugins/platforms/wasm/qwasmwindownonclientarea.h12
4 files changed, 55 insertions, 18 deletions
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<emscripten::val>("getBoundingClientRect"));
+ const auto screenRect = QRectF::fromDOMRect(
+ m_window->platformScreen()->element().call<emscripten::val>("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<emscripten::val>("getBoundingClientRect"));
- const auto screenRect = QRectF::fromDOMRect(
- m_window->platformScreen()->element().call<emscripten::val>("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<Resizer>(window, m_qtWindowElement)),
+ m_titleBar(std::make_unique<TitleBar>(window, m_qtWindowElement))
{
- m_titleBar = std::make_unique<TitleBar>(window, qtWindowElement);
- m_resizer = std::make_unique<Resizer>(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<Resizer> m_resizer;
std::unique_ptr<TitleBar> 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);