diff options
author | Jens Trillmann <jens.trillmann@governikus.de> | 2022-05-24 08:57:45 +0200 |
---|---|---|
committer | Jens Trillmann <jens.trillmann@governikus.de> | 2022-08-29 12:31:23 +0200 |
commit | 56c4d183ec30c7f40ece09de1c483829eedc299b (patch) | |
tree | 9610347f22d15c18c9e124012944b74598b3bf24 /src/plugins/platforms/android | |
parent | 3c709198838866d5122c69a30cacdc806605d0cf (diff) |
Android A11Y: Fix TalkBack scrolling behavior
* Add CollectionInfo to scrollable nodes.
Every scrollable node will get a CollectionInfo attached to signal
the number of (possibly invisible) children.
This is necessary as TalkBack on Android doesn't scroll to items not
visible on screen if the number of further child nodes is not
communicated to TalkBack.
* Return success of scroll to TalkBack.
TalkBack needs the result of the scroll to decide if it should leave
the current element or stay after a scroll was successful.
Success of a scroll action is measured as the successful movement
of the children of the scrolled element. This is a workaround for
the Qt Accessibility API not returning the success of failure of a
performed action.
Task-number: QTBUG-103499
Pick-to: 6.4 6.3 6.2 5.15
Change-Id: Ie2c51d0b77fb5030973a0f93c42e0db3082be45e
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r-- | src/plugins/platforms/android/androidjniaccessibility.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/androidjniaccessibility.cpp b/src/plugins/platforms/android/androidjniaccessibility.cpp index 7bdbd96a4a..3067cb178a 100644 --- a/src/plugins/platforms/android/androidjniaccessibility.cpp +++ b/src/plugins/platforms/android/androidjniaccessibility.cpp @@ -193,7 +193,7 @@ namespace QtAndroidAccessibility return result; } - static QRect screenRect_helper(int objectId) + static QRect screenRect_helper(int objectId, bool clip = true) { QRect rect; QAccessibleInterface *iface = interfaceFromId(objectId); @@ -201,7 +201,7 @@ namespace QtAndroidAccessibility rect = QHighDpi::toNativePixels(iface->rect(), iface->window()); } // If the widget is not fully in-bound in its parent then we have to clip the rectangle to draw - if (iface && iface->parent() && iface->parent()->isValid()) { + if (clip && iface && iface->parent() && iface->parent()->isValid()) { const auto parentRect = QHighDpi::toNativePixels(iface->parent()->rect(), iface->parent()->window()); rect = rect.intersected(parentRect); } @@ -303,23 +303,43 @@ namespace QtAndroidAccessibility static jboolean scrollForward(JNIEnv */*env*/, jobject /*thiz*/, jint objectId) { bool result = false; + + const auto& ids = childIdListForAccessibleObject_helper(objectId); + if (ids.isEmpty()) + return false; + + const int firstChildId = ids.first(); + const QRect oldPosition = screenRect_helper(firstChildId, false); + if (m_accessibilityContext) { runInObjectContext(m_accessibilityContext, [objectId]() { return scroll_helper(objectId, QAccessibleActionInterface::increaseAction()); }, &result); } - return result; + + // Don't check for position change if the call was not successful + return result && oldPosition != screenRect_helper(firstChildId, false); } static jboolean scrollBackward(JNIEnv */*env*/, jobject /*thiz*/, jint objectId) { bool result = false; + + const auto& ids = childIdListForAccessibleObject_helper(objectId); + if (ids.isEmpty()) + return false; + + const int firstChildId = ids.first(); + const QRect oldPosition = screenRect_helper(firstChildId, false); + if (m_accessibilityContext) { runInObjectContext(m_accessibilityContext, [objectId]() { return scroll_helper(objectId, QAccessibleActionInterface::decreaseAction()); }, &result); } - return result; + + // Don't check for position change if the call was not successful + return result && oldPosition != screenRect_helper(firstChildId, false); } |