Android: explicitly remove accessibility focus when element is hidden

Before this patch when an element that had an Accessibility focus was
hidden (for example, a button because of Accessibility.onPressAction),
the focus was still remaining on that hidden element. So the next
doubletaps on the screen caused the Accessibility.onPressAction() of the
hidden element to be executed again and again.

To fix this, we have to explicitly send a FOCUS_CLEARED event to the
Android OS, when the object is hidden.
Another needed fix is to set the m_focusedVirtualViewId in
notifyObjectFocus() properly.

Fixes: QTBUG-93393
Pick-to: 6.3 6.2 5.15
Change-Id: I6ff8a19868b96842719924037545c4ecc91e0dad
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Ivan Solovev 2022-01-19 11:43:21 +01:00
parent c1a93b20ff
commit f6ddb3e921

View File

@ -198,6 +198,16 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
public void notifyObjectHide(int viewId)
{
// If the object had accessibility focus, we need to clear it.
// Note: This code is mostly copied from
// AccessibilityNodeProvider::performAction, but we remove the
// focus only if the focused view id matches the one that was hidden.
if (m_focusedVirtualViewId == viewId) {
m_focusedVirtualViewId = INVALID_ID;
m_view.invalidate();
sendEventForVirtualViewId(viewId,
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
}
invalidateVirtualViewId(viewId);
}
@ -205,6 +215,7 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
{
if (m_view == null)
return;
m_focusedVirtualViewId = viewId;
m_view.invalidate();
sendEventForVirtualViewId(viewId,
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);