diff options
| author | Mikolaj Boc <mikolaj.boc@qt.io> | 2022-12-06 08:42:34 +0100 |
|---|---|---|
| committer | Mikołaj Boc <Mikolaj.Boc@qt.io> | 2022-12-07 13:03:03 +0000 |
| commit | 4d07f843072b367f45cb636d49415ceb92ca1dd9 (patch) | |
| tree | e4403fd6e3fed787f13667e068c86835aa1b2f8c /src/plugins/platforms/wasm/qwasmcompositor.cpp | |
| parent | 6d780fa0aba2d53379c51c8c7439def8fad781aa (diff) | |
Fix the coordinate problems in wasm windows
The QWasmScreen's top left coordinate does not precisely translate
to correct page coordinates, especially when fixed position is used
and page margins are set. Also, this is wrong in complicated setups
with e.g. multiple nested elements.
Therefore, to get the correct coordinates in pointer event handlers,
we have to assume the local coordinates of the screen, and translate
those to the (possibly incorrect) coordinates that QWasmScreen thinks
it has in page.
It is another problem to fix the wrong coordinates QWasmScreen thinks
it has in the page.
This has been checked with complicated setups with screens in scroll
containers, screens with fixed position, screens with relative position,
with and without body margins etc.
Change-Id: I749f2507fec7ae278b6f9d7d13ae288e65472dba
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmcompositor.cpp')
| -rw-r--r-- | src/plugins/platforms/wasm/qwasmcompositor.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp index b84e05e1c95..0f082543ff4 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.cpp +++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp @@ -369,10 +369,12 @@ bool QWasmCompositor::processPointer(const PointerEvent& event) if (event.pointerType != PointerType::Mouse) return false; - QWindow *const targetWindow = ([this, &event]() -> QWindow * { + const auto pointInScreen = screen()->mapFromLocal(event.localPoint); + + QWindow *const targetWindow = ([this, pointInScreen]() -> QWindow * { auto *targetWindow = m_mouseCaptureWindow != nullptr ? m_mouseCaptureWindow.get() : m_windowManipulation.operation() == WindowManipulation::Operation::None - ? screen()->compositor()->windowAt(event.point, 5) + ? screen()->compositor()->windowAt(pointInScreen, 5) : nullptr; return targetWindow ? targetWindow : m_lastMouseTargetWindow.get(); @@ -381,13 +383,13 @@ bool QWasmCompositor::processPointer(const PointerEvent& event) return false; m_lastMouseTargetWindow = targetWindow; - const QPoint pointInTargetWindowCoords = targetWindow->mapFromGlobal(event.point); - const bool pointerIsWithinTargetWindowBounds = targetWindow->geometry().contains(event.point); + const QPoint pointInTargetWindowCoords = targetWindow->mapFromGlobal(pointInScreen); + const bool pointerIsWithinTargetWindowBounds = targetWindow->geometry().contains(pointInScreen); if (m_mouseInScreen && m_windowUnderMouse != targetWindow && pointerIsWithinTargetWindowBounds) { // delayed mouse enter - enterWindow(targetWindow, pointInTargetWindowCoords, event.point); + enterWindow(targetWindow, pointInTargetWindowCoords, pointInScreen); m_windowUnderMouse = targetWindow; } @@ -439,11 +441,13 @@ bool QWasmCompositor::deliverEventToTarget(const PointerEvent &event, QWindow *e { Q_ASSERT(!m_mouseCaptureWindow || m_mouseCaptureWindow.get() == eventTarget); + const auto pointInScreen = screen()->mapFromLocal(event.localPoint); + const QPoint targetPointClippedToScreen( std::max(screen()->geometry().left(), - std::min(screen()->geometry().right(), event.point.x())), + std::min(screen()->geometry().right(), pointInScreen.x())), std::max(screen()->geometry().top(), - std::min(screen()->geometry().bottom(), event.point.y()))); + std::min(screen()->geometry().bottom(), pointInScreen.y()))); bool deliveringToPreviouslyClickedWindow = false; @@ -509,12 +513,13 @@ void QWasmCompositor::WindowManipulation::onPointerDown( if (isTargetWindowBlocked) return; - if (!asWasmWindow(windowAtPoint)->isPointOnTitle(event.point)) + if (!asWasmWindow(windowAtPoint)->isPointOnTitle(event.pointInViewport)) return; m_state.reset(new OperationState{ .pointerId = event.pointerId, .window = windowAtPoint, - .lastPointInScreenCoords = event.point }); + .lastPointInScreenCoords = + m_screen->mapFromLocal(event.localPoint) }); } void QWasmCompositor::WindowManipulation::onPointerMove( @@ -525,7 +530,8 @@ void QWasmCompositor::WindowManipulation::onPointerMove( switch (operation()) { case Operation::Move: { - const QPoint targetPointClippedToScreen = m_screen->clipPoint(event.point); + const QPoint targetPointClippedToScreen = + m_screen->clipPoint(m_screen->mapFromLocal(event.localPoint)); const QPoint difference = targetPointClippedToScreen - m_state->lastPointInScreenCoords; m_state->lastPointInScreenCoords = targetPointClippedToScreen; |
