summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp')
-rw-r--r--src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp93
1 files changed, 58 insertions, 35 deletions
diff --git a/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp b/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp
index 8650f7a0c9..00fa8fb236 100644
--- a/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp
+++ b/src/plugins/platforms/wasm/qwasmwindownonclientarea.cpp
@@ -129,9 +129,6 @@ Resizer::ResizerElement::ResizerElement(ResizerElement &&other) = default;
bool Resizer::ResizerElement::onPointerDown(const PointerEvent &event)
{
- if (event.pointerType != PointerType::Mouse)
- return false;
-
m_element.call<void>("setPointerCapture", event.pointerId);
m_capturedPointerId = event.pointerId;
@@ -181,6 +178,24 @@ 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"));
+ auto containerGeometry =
+ QRectF::fromDOMRect(m_window->parentNode()->containerElement().call<emscripten::val>(
+ "getBoundingClientRect"));
+
+ const int maxGrowTop = frameRect.top() - containerGeometry.top();
+
+ return ResizeConstraints{minShrink, maxGrow, maxGrowTop};
+}
+
void Resizer::onInteraction()
{
m_window->onNonClientAreaInteraction();
@@ -193,33 +208,25 @@ void Resizer::startResize(Qt::Edges resizeEdges, const PointerEvent &event)
m_currentResizeData.reset(new ResizeData{
.edges = resizeEdges,
.originInScreenCoords = dom::mapPoint(
- event.target, m_window->platformScreen()->element(), event.localPoint),
+ 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)
{
const auto pointInScreen =
- dom::mapPoint(event.target, m_window->platformScreen()->element(), event.localPoint);
- const auto amount = pointInScreen - m_currentResizeData->originInScreenCoords;
+ dom::mapPoint(event.target(), m_window->platformScreen()->element(), event.localPoint);
+ const auto amount = (pointInScreen - m_currentResizeData->originInScreenCoords).toPoint();
const QPoint cappedGrowVector(
std::min(m_currentResizeData->maxGrow.x(),
std::max(m_currentResizeData->minShrink.x(),
@@ -371,14 +378,11 @@ QRectF TitleBar::geometry() const
bool TitleBar::onPointerDown(const PointerEvent &event)
{
- if (event.pointerType != PointerType::Mouse)
- return false;
-
m_element.call<void>("setPointerCapture", event.pointerId);
m_capturedPointerId = event.pointerId;
- const QPoint targetPointClippedToScreen = clipPointWithScreen(event.localPoint);
- m_lastMovePoint = targetPointClippedToScreen;
+ m_moveStartWindowPosition = m_window->window()->position();
+ m_moveStartPoint = clipPointWithScreen(event.localPoint);
m_window->onNonClientEvent(event);
return true;
}
@@ -388,11 +392,9 @@ bool TitleBar::onPointerMove(const PointerEvent &event)
if (m_capturedPointerId != event.pointerId)
return false;
- const QPoint targetPointClippedToScreen = clipPointWithScreen(event.localPoint);
- const QPoint delta = targetPointClippedToScreen - m_lastMovePoint;
- m_lastMovePoint = targetPointClippedToScreen;
+ const QPoint delta = (clipPointWithScreen(event.localPoint) - m_moveStartPoint).toPoint();
- m_window->window()->setPosition(m_window->window()->position() + delta);
+ m_window->window()->setPosition(m_moveStartWindowPosition + delta);
m_window->onNonClientEvent(event);
return true;
}
@@ -414,17 +416,25 @@ bool TitleBar::onDoubleClick()
return true;
}
-QPoint TitleBar::clipPointWithScreen(const QPoint &pointInTitleBarCoords) const
+QPointF TitleBar::clipPointWithScreen(const QPointF &pointInTitleBarCoords) const
{
- auto *screen = m_window->platformScreen();
- return screen->clipPoint(screen->mapFromLocal(
- dom::mapPoint(m_element, screen->element(), pointInTitleBarCoords)));
+ auto containerRect =
+ QRectF::fromDOMRect(m_window->parentNode()->containerElement().call<emscripten::val>(
+ "getBoundingClientRect"));
+ const auto p = dom::mapPoint(m_element, m_window->parentNode()->containerElement(),
+ pointInTitleBarCoords);
+
+ auto result = QPointF(qBound(0., qreal(p.x()), containerRect.width()),
+ qBound(0., qreal(p.y()), containerRect.height()));
+ return m_window->parent() ? result : m_window->platformScreen()->mapFromLocal(result).toPoint();
}
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;
@@ -434,4 +444,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