From e48c19449e3856661f4fe2ccd30d94ba9d61301f Mon Sep 17 00:00:00 2001 From: Even Oscar Andersen Date: Fri, 23 May 2025 12:37:25 +0200 Subject: wasm: Fix stacking order problem for transient parent windows Windows with a transient parent does not reflect the relationship in the stacking order. Essentially AboveTransientParent is missing as a configuration choice. What makes this slightly convoluted is that the window stack does not depend on the window (for testability). We solve this problem by making the stack and treenode templates, and provide test class as arguments when testing. QWasmWindow and QWasmScreen are not templated as before. There is also a new order type StayAboveTransientParent. Which means that we can no longer use order type to get to the group location (Since StayAboveTransientParent can map to either of the three types). The window stack tests have been updated to handle the StayAboveTransientParent type. Finally, we do not do anything with a normal parent child relationship as this should already work correctly. Fixes: QTBUG-131699 Change-Id: Ie08e18f9e0a2339175c4a09da0a831f031df71e1 Reviewed-by: Lorn Potter --- .../wasm/qwasmwindowstack/tst_qwasmwindowstack.cpp | 318 ++++++++++++++++++++- 1 file changed, 315 insertions(+), 3 deletions(-) (limited to 'tests/auto/wasm/qwasmwindowstack/tst_qwasmwindowstack.cpp') diff --git a/tests/auto/wasm/qwasmwindowstack/tst_qwasmwindowstack.cpp b/tests/auto/wasm/qwasmwindowstack/tst_qwasmwindowstack.cpp index fe169b52dca..3df72ba6379 100644 --- a/tests/auto/wasm/qwasmwindowstack/tst_qwasmwindowstack.cpp +++ b/tests/auto/wasm/qwasmwindowstack/tst_qwasmwindowstack.cpp @@ -2,15 +2,75 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "../../../../src/plugins/platforms/wasm/qwasmwindowstack.h" + #include #include #include -class QWasmWindow +class TestWindow { +public: + TestWindow *transientParent() const { return m_transientParent; } + Qt::WindowFlags windowFlags() const { return m_windowFlags; } + bool isModal() const { return m_isModal; } + +public: + TestWindow *m_transientParent = nullptr; + Qt::WindowFlags m_windowFlags = {}; + bool m_isModal = false; }; +#define QWasmWindowStack QWasmWindowStack +#define QWasmWindow TestWindow + namespace { + +QDebug operator<<(QDebug d, const QWasmWindowStack::PositionPreference &pref) +{ + switch (pref) { + case QWasmWindowStack::PositionPreference::StayOnBottom: + d << "StayOnBottom"; + break; + case QWasmWindowStack::PositionPreference::Regular: + d << "Regular"; + break; + case QWasmWindowStack::PositionPreference::StayOnTop: + d << "StayOnTop"; + break; + case QWasmWindowStack::PositionPreference::StayAboveTransientParent: + d << "StayAboveParent"; + break; + } /* end-switch */ + return d; +} + +class LogWindows +{ +public: + LogWindows(QWasmWindow *window, const QWasmWindowStack &stack) + : m_window(window), m_stack(&stack) + { + } + +public: + friend QDebug operator<<(QDebug d, const LogWindows &cl) + { + LogWindows &l = const_cast(cl); + d << "\n"; + for (auto it = l.m_stack->rend(); it != l.m_stack->rbegin();) { + --it; + d << " Window " << (*it) - l.m_window + << l.m_stack->getWindowPositionPreference(it, false) + << l.m_stack->getWindowPositionPreference(it, true) << "\n"; + } + return d; + } + +private: + QWasmWindow *m_window; + const QWasmWindowStack *m_stack; +}; + std::vector getWindowsFrontToBack(const QWasmWindowStack *stack) { return std::vector(stack->begin(), stack->end()); @@ -42,6 +102,11 @@ private slots: void removingWithAlwaysOnTop(); void positionPreferenceChanges(); void clearing(); + void stayAboveParentOnBottom1(); + void stayAboveParentOnBottom2(); + void stayAboveParentOnBottom3(); + void stayAboveParentRegular(); + void stayAboveParentOnTop(); private: void onTopWindowChanged() @@ -97,7 +162,6 @@ void tst_QWasmWindowStack::insertion() void tst_QWasmWindowStack::raising() { QWasmWindowStack stack(m_mockCallback); - stack.pushWindow(&m_root, QWasmWindowStack::PositionPreference::StayOnBottom); stack.pushWindow(&m_window1, QWasmWindowStack::PositionPreference::Regular); stack.pushWindow(&m_window2, QWasmWindowStack::PositionPreference::Regular); @@ -106,7 +170,6 @@ void tst_QWasmWindowStack::raising() stack.pushWindow(&m_window5, QWasmWindowStack::PositionPreference::Regular); clearCallbackCounter(); - QCOMPARE(&m_window5, stack.topWindow()); m_onTopLevelChangedAction = [this, &stack]() { QVERIFY(stack.topWindow() == &m_window1); }; @@ -710,5 +773,254 @@ void tst_QWasmWindowStack::clearing() QCOMPARE(0u, stack.size()); } +void tst_QWasmWindowStack::stayAboveParentOnBottom1() +{ + QWasmWindow windows[5]; + windows[4].m_transientParent = &windows[0]; + windows[4].m_windowFlags = Qt::Tool; + + QWasmWindowStack stack(m_mockCallback); + + stack.pushWindow(windows + 0, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 1, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 2, QWasmWindowStack::PositionPreference::Regular); + stack.pushWindow(windows + 3, QWasmWindowStack::PositionPreference::StayOnTop); + stack.pushWindow(windows + 4, QWasmWindowStack::PositionPreference::StayAboveTransientParent); + + { + const std::vector expectedWindowOrder = { + windows + 3, + windows + 2, + windows + 1, + windows + 4, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } + { + // Check that window is moved to correct group: + // it was: StayAboveParent, in group StayOnBottom + // it is: StayOnTop + stack.windowPositionPreferenceChanged( + windows + 4, + QWasmWindowStack::PositionPreference::StayOnTop); + + const std::vector expectedWindowOrder = { + windows + 4, + windows + 3, + windows + 2, + windows + 1, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } +} + +void tst_QWasmWindowStack::stayAboveParentOnBottom2() +{ + QWasmWindow windows[5]; + windows[4].m_transientParent = &windows[0]; + windows[4].m_windowFlags = Qt::Tool; + + QWasmWindowStack stack(m_mockCallback); + + stack.pushWindow(windows + 0, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 1, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 2, QWasmWindowStack::PositionPreference::Regular); + stack.pushWindow(windows + 3, QWasmWindowStack::PositionPreference::StayOnTop); + stack.pushWindow(windows + 4, QWasmWindowStack::PositionPreference::StayAboveTransientParent); + + { + const std::vector expectedWindowOrder = { + windows + 3, + windows + 2, + windows + 1, + windows + 4, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } + { + // Check that order does not change: + // it was: StayAboveParent, in group StayOnBottom + // it is: StayOnBottom + stack.windowPositionPreferenceChanged( + windows + 4, + QWasmWindowStack::PositionPreference::StayOnBottom); + + const std::vector expectedWindowOrder = { + windows + 3, + windows + 2, + windows + 1, + windows + 4, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } +} + +void tst_QWasmWindowStack::stayAboveParentOnBottom3() +{ + QWasmWindow windows[5]; + windows[4].m_transientParent = &windows[0]; + windows[4].m_windowFlags = Qt::Tool; + + QWasmWindowStack stack(m_mockCallback); + + stack.pushWindow(windows + 0, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 1, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 2, QWasmWindowStack::PositionPreference::Regular); + stack.pushWindow(windows + 3, QWasmWindowStack::PositionPreference::StayOnTop); + stack.pushWindow(windows + 4, QWasmWindowStack::PositionPreference::StayAboveTransientParent); + + { + const std::vector expectedWindowOrder = { + windows + 3, + windows + 2, + windows + 1, + windows + 4, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } + { + // Check that windows is moved to correct group + // it was: StayAboveParent, in group StayOnBottom + // it is: Regular + stack.windowPositionPreferenceChanged( + windows + 4, + QWasmWindowStack::PositionPreference::Regular); + + const std::vector expectedWindowOrder = { + windows + 3, + windows + 4, + windows + 2, + windows + 1, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } +} + +void tst_QWasmWindowStack::stayAboveParentRegular() +{ + QWasmWindow windows[5]; + windows[4].m_transientParent = &windows[1]; + windows[4].m_windowFlags = Qt::Tool; + + QWasmWindowStack stack(m_mockCallback); + + stack.pushWindow(windows + 0, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 1, QWasmWindowStack::PositionPreference::Regular); + stack.pushWindow(windows + 2, QWasmWindowStack::PositionPreference::Regular); + stack.pushWindow(windows + 3, QWasmWindowStack::PositionPreference::StayOnTop); + stack.pushWindow(windows + 4, QWasmWindowStack::PositionPreference::StayAboveTransientParent); + + { + const std::vector expectedWindowOrder = { + windows + 3, + windows + 2, + windows + 4, + windows + 1, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } + { + stack.windowPositionPreferenceChanged( + windows + 4, + QWasmWindowStack::PositionPreference::StayOnTop); + + const std::vector expectedWindowOrder = { + windows + 4, + windows + 3, + windows + 2, + windows + 1, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } +} + +void tst_QWasmWindowStack::stayAboveParentOnTop() +{ + QWasmWindow windows[5]; + windows[3].m_transientParent = &windows[2]; + windows[3].m_windowFlags = Qt::Tool; + + QWasmWindowStack stack(m_mockCallback); + + stack.pushWindow(windows + 0, QWasmWindowStack::PositionPreference::StayOnBottom); + stack.pushWindow(windows + 1, QWasmWindowStack::PositionPreference::Regular); + stack.pushWindow(windows + 2, QWasmWindowStack::PositionPreference::StayOnTop); + stack.pushWindow(windows + 3, QWasmWindowStack::PositionPreference::StayAboveTransientParent); + stack.pushWindow(windows + 4, QWasmWindowStack::PositionPreference::StayOnTop); + + { + const std::vector expectedWindowOrder = { + windows + 4, + windows + 3, + windows + 2, + windows + 1, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } + { + stack.windowPositionPreferenceChanged( + windows + 3, + QWasmWindowStack::PositionPreference::StayOnTop); + + const std::vector expectedWindowOrder = { + windows + 4, + windows + 3, + windows + 2, + windows + 1, + windows + 0 + }; + + qDebug() << LogWindows(windows + 0, stack); + + QVERIFY(std::equal(expectedWindowOrder.begin(), expectedWindowOrder.end(), + getWindowsFrontToBack(&stack).begin())); + } +} + + QTEST_MAIN(tst_QWasmWindowStack) #include "tst_qwasmwindowstack.moc" -- cgit v1.2.3