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>
This commit is contained in:
Piotr Wierciński 2023-03-06 10:51:56 +01:00
parent 79cc3ae201
commit 4d09152344
4 changed files with 55 additions and 18 deletions

View File

@ -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;
}

View File

@ -351,6 +351,7 @@ void QWasmWindow::propagateSizeHints()
rect.setSize(windowMinimumSize());
setGeometry(rect);
}
m_nonClientArea->propagateSizeHints();
}
void QWasmWindow::invalidate()

View File

@ -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

View File

@ -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);