Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Send AccessibilityEvent.TYPE_VIEW_FOCUSED when input focus is set. #12746

Merged
merged 2 commits into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
@Nullable
private SemanticsNode inputFocusedSemanticsNode;

// Keeps track of the last semantics node that had the input focus.
//
// This is used to determine if the input focus has changed since the last time the
// {@code inputFocusSemanticsNode} has been set, so that we can send a {@code TYPE_VIEW_FOCUSED}
// event when it changes.
@Nullable
private SemanticsNode lastInputFocusedSemanticsNode;

// The widget within Flutter that currently sits beneath a cursor, e.g,
// beneath a stylus or mouse cursor.
@Nullable
Expand Down Expand Up @@ -1377,6 +1385,20 @@ void updateSemantics(@NonNull ByteBuffer buffer, @NonNull String[] strings) {
event.getText().add(object.label);
sendAccessibilityEvent(event);
}

// If the object is the input-focused node, then tell the reader about it, but only if
// it has changed since the last update.
if (inputFocusedSemanticsNode != null && inputFocusedSemanticsNode.id == object.id &&
(lastInputFocusedSemanticsNode == null || lastInputFocusedSemanticsNode.id != inputFocusedSemanticsNode.id)) {
lastInputFocusedSemanticsNode = inputFocusedSemanticsNode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the indentation here is strange making it hard to see where the condition ends and where the body of the if starts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

sendAccessibilityEvent(obtainAccessibilityEvent(object.id, AccessibilityEvent.TYPE_VIEW_FOCUSED));
} else if (inputFocusedSemanticsNode == null) {
// There's no TYPE_VIEW_CLEAR_FOCUSED event, so if the current input focus becomes
// null, then we just set the last one to null too, so that it sends the event again
// when something regains focus.
lastInputFocusedSemanticsNode = null;
}

if (inputFocusedSemanticsNode != null && inputFocusedSemanticsNode.id == object.id
&& object.hadFlag(Flag.IS_TEXT_FIELD) && object.hasFlag(Flag.IS_TEXT_FIELD)
// If we have a TextField that has InputFocus, we should avoid announcing it if something
Expand Down