From 254a56252874b63430701351dcd8c9bef8507353 Mon Sep 17 00:00:00 2001 From: Wang Chuan Date: Wed, 26 Feb 2020 21:14:50 +0800 Subject: QQuickItem: prevent endless loop in focus tab chain Since the commit a18ab2a3822e0d, we promote the [startItem] in focus tab chain when it is invisible to prevent endless loop. However the problem still happen if the [startItem] is equal to [firstFromItem] Fixes it by compare the [current] item with the original start item Fixes: QTBUG-81510 Change-Id: Iae0207f39e2b8c4fc6ed0cf36f0a855668accfba Reviewed-by: Mitch Curtis Reviewed-by: Liang Qi Reviewed-by: Shawn Rutledge --- src/quick/items/qquickitem.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/quick/items/qquickitem.cpp') diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 3785abc450..11c1f12e75 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -2568,6 +2568,7 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo bool skip = false; QQuickItem *startItem = item; + QQuickItem *originalStartItem = startItem; // Protect from endless loop: // If we start on an invisible item we will not find it again. // If there is no other item which can become the focus item, we have a forever loop, @@ -2643,7 +2644,12 @@ QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item, boo } } from = last; - if (current == startItem && from == firstFromItem) { + // if [from] item is equal to [firstFromItem], means we have traversed one path and + // jump back to parent of the chain, and then we have to check whether we have + // traversed all of the chain (by compare the [current] item with [startItem]) + // Since the [startItem] might be promoted to its parent if it is invisible, + // we still have to check [current] item with original start item + if ((current == startItem || current == originalStartItem) && from == firstFromItem) { // wrapped around, avoid endless loops if (item == contentItem) { qCDebug(DBG_FOCUS) << "QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem"; -- cgit v1.2.3