Skip to content

Commit

Permalink
a11y: Announce changes to cursor position on Android (flutter#4587)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Jan 25, 2018
1 parent 93296fb commit 4c82c56
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
14 changes: 7 additions & 7 deletions lib/ui/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
/// string describes what result an action performed on this node has. The
/// reading direction of all these strings is given by `textDirection`.
///
/// The fields 'textSelectionStart' and 'textSelectionEnd' describe the
/// The fields 'textSelectionBase' and 'textSelectionExtent' describe the
/// currently selected text within `value`.
///
/// The `rect` is the region occupied by this node in its own coordinate
Expand All @@ -305,8 +305,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
int textSelectionBase,
int textSelectionExtent,
Rect rect,
String label,
String hint,
Expand All @@ -323,8 +323,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
id,
flags,
actions,
textSelectionStart,
textSelectionEnd,
textSelectionBase,
textSelectionExtent,
rect.left,
rect.top,
rect.right,
Expand All @@ -343,8 +343,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
int textSelectionBase,
int textSelectionExtent,
double left,
double top,
double right,
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/semantics/semantics_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ struct SemanticsNode {
int32_t id = 0;
int32_t flags = 0;
int32_t actions = 0;
int32_t textSelectionStart = -1;
int32_t textSelectionEnd = -1;
int32_t textSelectionBase = -1;
int32_t textSelectionExtent = -1;
std::string label;
std::string hint;
std::string value;
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/semantics/semantics_update_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ SemanticsUpdateBuilder::~SemanticsUpdateBuilder() = default;
void SemanticsUpdateBuilder::updateNode(int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
int textSelectionBase,
int textSelectionExtent,
double left,
double top,
double right,
Expand All @@ -55,8 +55,8 @@ void SemanticsUpdateBuilder::updateNode(int id,
node.id = id;
node.flags = flags;
node.actions = actions;
node.textSelectionStart = textSelectionStart;
node.textSelectionEnd = textSelectionEnd;
node.textSelectionBase = textSelectionBase;
node.textSelectionExtent = textSelectionExtent;
node.rect = SkRect::MakeLTRB(left, top, right, bottom);
node.label = label;
node.hint = hint;
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/semantics/semantics_update_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class SemanticsUpdateBuilder
void updateNode(int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
int textSelectionBase,
int textSelectionExtent,
double left,
double top,
double right,
Expand Down
29 changes: 22 additions & 7 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
result.setClassName("android.widget.EditText");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
result.setEditable(true);
if (object.textSelectionStart != -1 && object.textSelectionEnd != -1) {
result.setTextSelection(object.textSelectionStart, object.textSelectionEnd);
if (object.textSelectionBase != -1 && object.textSelectionExtent != -1) {
result.setTextSelection(object.textSelectionBase, object.textSelectionExtent);
}
}

Expand Down Expand Up @@ -460,6 +460,17 @@ void updateSemantics(ByteBuffer buffer, String[] strings) {
if (event != null) {
sendAccessibilityEvent(event);
}

if (object.previousTextSelectionBase != object.textSelectionBase
|| object.previousTextSelectionExtent != object.textSelectionExtent) {
AccessibilityEvent selectionEvent = obtainAccessibilityEvent(
object.id, AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED);
selectionEvent.getText().add(newValue);
selectionEvent.setFromIndex(object.textSelectionBase);
selectionEvent.setToIndex(object.previousTextSelectionExtent);
selectionEvent.setItemCount(newValue.length());
sendAccessibilityEvent(selectionEvent);
}
}
}
}
Expand Down Expand Up @@ -603,8 +614,8 @@ private class SemanticsObject {

int flags;
int actions;
int textSelectionStart;
int textSelectionEnd;
int textSelectionBase;
int textSelectionExtent;
String label;
String value;
String increasedValue;
Expand All @@ -614,6 +625,8 @@ private class SemanticsObject {

boolean hadPreviousConfig = false;
int previousFlags;
int previousTextSelectionBase;
int previousTextSelectionExtent;
String previousValue;

private float left;
Expand Down Expand Up @@ -658,14 +671,16 @@ void log(String indent) {
}

void updateWith(ByteBuffer buffer, String[] strings) {
hadPreviousConfig = true;
previousValue = value;
previousFlags = flags;
hadPreviousConfig = true;
previousTextSelectionBase = textSelectionBase;
previousTextSelectionExtent = textSelectionExtent;

flags = buffer.getInt();
actions = buffer.getInt();
textSelectionStart = buffer.getInt();
textSelectionEnd = buffer.getInt();
textSelectionBase = buffer.getInt();
textSelectionExtent = buffer.getInt();

int stringIndex = buffer.getInt();
label = stringIndex == -1 ? null : strings[stringIndex];
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ void PlatformViewAndroid::UpdateSemantics(
buffer_int32[position++] = node.id;
buffer_int32[position++] = node.flags;
buffer_int32[position++] = node.actions;
buffer_int32[position++] = node.textSelectionStart;
buffer_int32[position++] = node.textSelectionEnd;
buffer_int32[position++] = node.textSelectionBase;
buffer_int32[position++] = node.textSelectionExtent;
if (node.label.empty()) {
buffer_int32[position++] = -1;
} else {
Expand Down

0 comments on commit 4c82c56

Please sign in to comment.