Makes empty scrollable not focusable in Talkback (flutter/engine#28229)
This commit is contained in:
@@ -85,6 +85,25 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
|
||||
private static final float SCROLL_EXTENT_FOR_INFINITY = 100000.0f;
|
||||
private static final float SCROLL_POSITION_CAP_FOR_INFINITY = 70000.0f;
|
||||
private static final int ROOT_NODE_ID = 0;
|
||||
private static final int SCROLLABLE_ACTIONS =
|
||||
Action.SCROLL_RIGHT.value
|
||||
| Action.SCROLL_LEFT.value
|
||||
| Action.SCROLL_UP.value
|
||||
| Action.SCROLL_DOWN.value;
|
||||
// Flags that make a node accessibilty focusable.
|
||||
private static final int FOCUSABLE_FLAGS =
|
||||
Flag.HAS_CHECKED_STATE.value
|
||||
| Flag.IS_CHECKED.value
|
||||
| Flag.IS_SELECTED.value
|
||||
| Flag.IS_TEXT_FIELD.value
|
||||
| Flag.IS_FOCUSED.value
|
||||
| Flag.HAS_ENABLED_STATE.value
|
||||
| Flag.IS_ENABLED.value
|
||||
| Flag.IS_IN_MUTUALLY_EXCLUSIVE_GROUP.value
|
||||
| Flag.HAS_TOGGLED_STATE.value
|
||||
| Flag.IS_TOGGLED.value
|
||||
| Flag.IS_FOCUSABLE.value
|
||||
| Flag.IS_SLIDER.value;
|
||||
|
||||
// The minimal ID for an engine generated AccessibilityNodeInfo.
|
||||
//
|
||||
@@ -2578,13 +2597,8 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
|
||||
// If not explicitly set as focusable, then use our legacy
|
||||
// algorithm. Once all focusable widgets have a Focus widget, then
|
||||
// this won't be needed.
|
||||
int scrollableActions =
|
||||
Action.SCROLL_RIGHT.value
|
||||
| Action.SCROLL_LEFT.value
|
||||
| Action.SCROLL_UP.value
|
||||
| Action.SCROLL_DOWN.value;
|
||||
return (actions & ~scrollableActions) != 0
|
||||
|| flags != 0
|
||||
return (actions & ~SCROLLABLE_ACTIONS) != 0
|
||||
|| (flags & FOCUSABLE_FLAGS) != 0
|
||||
|| (label != null && !label.isEmpty())
|
||||
|| (value != null && !value.isEmpty())
|
||||
|| (hint != null && !hint.isEmpty());
|
||||
|
||||
@@ -40,6 +40,7 @@ import android.view.accessibility.AccessibilityManager;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import io.flutter.embedding.engine.systemchannels.AccessibilityChannel;
|
||||
import io.flutter.plugin.platform.PlatformViewsAccessibilityDelegate;
|
||||
import io.flutter.view.AccessibilityBridge.Flag;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@@ -885,6 +886,52 @@ public class AccessibilityBridgeTest {
|
||||
assertFalse(nodeInfo.isAccessibilityFocused());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itSetsFocusabilityBasedOnFlagsCorrectly() {
|
||||
AccessibilityChannel mockChannel = mock(AccessibilityChannel.class);
|
||||
AccessibilityViewEmbedder mockViewEmbedder = mock(AccessibilityViewEmbedder.class);
|
||||
AccessibilityManager mockManager = mock(AccessibilityManager.class);
|
||||
View mockRootView = mock(View.class);
|
||||
Context context = mock(Context.class);
|
||||
when(mockRootView.getContext()).thenReturn(context);
|
||||
when(context.getPackageName()).thenReturn("test");
|
||||
AccessibilityBridge accessibilityBridge =
|
||||
setUpBridge(
|
||||
/*rootAccessibilityView=*/ mockRootView,
|
||||
/*accessibilityChannel=*/ mockChannel,
|
||||
/*accessibilityManager=*/ mockManager,
|
||||
/*contentResolver=*/ null,
|
||||
/*accessibilityViewEmbedder=*/ mockViewEmbedder,
|
||||
/*platformViewsAccessibilityDelegate=*/ null);
|
||||
|
||||
ViewParent mockParent = mock(ViewParent.class);
|
||||
when(mockRootView.getParent()).thenReturn(mockParent);
|
||||
when(mockManager.isEnabled()).thenReturn(true);
|
||||
|
||||
TestSemanticsNode root = new TestSemanticsNode();
|
||||
root.id = 0;
|
||||
root.addFlag(Flag.HAS_IMPLICIT_SCROLLING);
|
||||
TestSemanticsNode node1 = new TestSemanticsNode();
|
||||
node1.id = 1;
|
||||
node1.addFlag(Flag.IS_READ_ONLY);
|
||||
root.children.add(node1);
|
||||
TestSemanticsNode node2 = new TestSemanticsNode();
|
||||
node2.id = 2;
|
||||
node2.addFlag(Flag.HAS_CHECKED_STATE);
|
||||
root.children.add(node2);
|
||||
TestSemanticsUpdate testSemanticsUpdate = root.toUpdate();
|
||||
testSemanticsUpdate.sendUpdateToBridge(accessibilityBridge);
|
||||
|
||||
// Only node 2 is focusable because it has a flag that is not in
|
||||
// AccessibilityBridge.TRIVIAL_FLAGS.
|
||||
AccessibilityNodeInfo rootInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
|
||||
assertFalse(rootInfo.isFocusable());
|
||||
AccessibilityNodeInfo node1Info = accessibilityBridge.createAccessibilityNodeInfo(1);
|
||||
assertFalse(node1Info.isFocusable());
|
||||
AccessibilityNodeInfo node2Info = accessibilityBridge.createAccessibilityNodeInfo(2);
|
||||
assertTrue(node2Info.isFocusable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itSetsFocusedNodeBeforeSendingEvent() {
|
||||
AccessibilityChannel mockChannel = mock(AccessibilityChannel.class);
|
||||
|
||||
Reference in New Issue
Block a user