-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add live region semantics flag #5512
Changes from all commits
eb006ca
5329a88
87b2b01
f53d5e3
e3a3c58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess | |
private static final int ROOT_NODE_ID = 0; | ||
|
||
private Map<Integer, SemanticsObject> mObjects; | ||
private Map<Integer, String> mLiveRegions; | ||
private final FlutterView mOwner; | ||
private boolean mAccessibilityEnabled = false; | ||
private SemanticsObject mA11yFocusedObject; | ||
|
@@ -91,7 +92,8 @@ enum Flag { | |
IS_OBSCURED(1 << 10), | ||
SCOPES_ROUTE(1 << 11), | ||
NAMES_ROUTE(1 << 12), | ||
IS_HIDDEN(1 << 13); | ||
IS_HIDDEN(1 << 13), | ||
IS_LIVE_REGION(1 << 14); | ||
|
||
Flag(int value) { | ||
this.value = value; | ||
|
@@ -104,6 +106,7 @@ enum Flag { | |
assert owner != null; | ||
mOwner = owner; | ||
mObjects = new HashMap<Integer, SemanticsObject>(); | ||
mLiveRegions = new HashMap<Integer, String>(); | ||
previousRoutes = new ArrayList<>(); | ||
mFlutterAccessibilityChannel = new BasicMessageChannel<>(owner, "flutter/accessibility", | ||
StandardMessageCodec.INSTANCE); | ||
|
@@ -238,7 +241,20 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) { | |
result.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); | ||
} | ||
} | ||
|
||
if (object.hasFlag(Flag.IS_LIVE_REGION)) { | ||
result.setLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); | ||
String priorLabelHint = mLiveRegions.get(object.id); | ||
String labelHint = object.getLabelHint(); | ||
// It is very important that this is added to mLiveRegions before sending the accessibility event | ||
// below. | ||
mLiveRegions.put(object.id, labelHint); | ||
if (priorLabelHint == null || !priorLabelHint.equals(labelHint)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little surprised to see this get send here and not in updateSemantics with the other events. This means, we only send the event if Android actually happens to ask us for the semantics of a particular node, which might not be guaranteed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this is odd. In my experiments I found that (at least on a pixel) no notifications are produced if this event is sent before the framework calls this method. during seems to be no problem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did some more investigation and found that there was another error that was masking this. Fixed and moved to a better location |
||
sendAccessibilityEvent(object.id, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); | ||
} | ||
} else if (object.hadFlag(Flag.IS_LIVE_REGION)) { | ||
mLiveRegions.remove(object.id); | ||
} | ||
|
||
boolean hasCheckedState = object.hasFlag(Flag.HAS_CHECKED_STATE); | ||
result.setCheckable(hasCheckedState); | ||
if (hasCheckedState) { | ||
|
@@ -499,7 +515,7 @@ void updateSemantics(ByteBuffer buffer, String[] strings) { | |
rootObject.updateRecursively(identity, visitedObjects, false); | ||
rootObject.collectRoutes(newRoutes); | ||
} | ||
|
||
// Dispatch a TYPE_WINDOW_STATE_CHANGED event if the most recent route id changed from the | ||
// previously cached route id. | ||
SemanticsObject lastAdded = null; | ||
|
@@ -705,6 +721,7 @@ private void createWindowChangeEvent(SemanticsObject route) { | |
private void willRemoveSemanticsObject(SemanticsObject object) { | ||
assert mObjects.containsKey(object.id); | ||
assert mObjects.get(object.id) == object; | ||
mLiveRegions.remove(object.id); | ||
object.parent = null; | ||
if (mA11yFocusedObject == object) { | ||
sendAccessibilityEvent(mA11yFocusedObject.id, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); | ||
|
@@ -1061,6 +1078,20 @@ private float max(float a, float b, float c, float d) { | |
return Math.max(a, Math.max(b, Math.max(c, d))); | ||
} | ||
|
||
private String getLabelHint() { | ||
StringBuilder sb = new StringBuilder(); | ||
if (label != null) { | ||
sb.append(label); | ||
} | ||
if (sb.length() > 0) { | ||
sb.append(", "); | ||
} | ||
if (hint != null) { | ||
sb.append(hint); | ||
} | ||
return sb.length() > 0 ? sb.toString() : null; | ||
} | ||
|
||
private String getValueLabelHint() { | ||
StringBuilder sb = new StringBuilder(); | ||
String[] array = { value, label, hint }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds misleading to me. Any semantics node may update its semantics label without being a liveRegion, no? liveRegion just tells a11y systems that a it may be relevant to inform the user about a changed label, no?