diff --git a/engine/src/flutter/lib/ui/semantics.dart b/engine/src/flutter/lib/ui/semantics.dart index 926f464bb5..b51ad19e4f 100644 --- a/engine/src/flutter/lib/ui/semantics.dart +++ b/engine/src/flutter/lib/ui/semantics.dart @@ -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 @@ -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, @@ -323,8 +323,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 { id, flags, actions, - textSelectionStart, - textSelectionEnd, + textSelectionBase, + textSelectionExtent, rect.left, rect.top, rect.right, @@ -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, diff --git a/engine/src/flutter/lib/ui/semantics/semantics_node.h b/engine/src/flutter/lib/ui/semantics/semantics_node.h index 61a97c9367..c1cc027bb7 100644 --- a/engine/src/flutter/lib/ui/semantics/semantics_node.h +++ b/engine/src/flutter/lib/ui/semantics/semantics_node.h @@ -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; diff --git a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc index 7896747792..46d722552c 100644 --- a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc +++ b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.cc @@ -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, @@ -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; diff --git a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h index 160816823d..7c85b35abc 100644 --- a/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h +++ b/engine/src/flutter/lib/ui/semantics/semantics_update_builder.h @@ -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, diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 4ae2dfbe49..972e72ad9e 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -125,8 +125,8 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess 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); } } @@ -460,6 +460,17 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess 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); + } } } } @@ -603,8 +614,8 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess int flags; int actions; - int textSelectionStart; - int textSelectionEnd; + int textSelectionBase; + int textSelectionExtent; String label; String value; String increasedValue; @@ -614,6 +625,8 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess boolean hadPreviousConfig = false; int previousFlags; + int previousTextSelectionBase; + int previousTextSelectionExtent; String previousValue; private float left; @@ -658,14 +671,16 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess } 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]; diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.cc b/engine/src/flutter/shell/platform/android/platform_view_android.cc index be6cc26b1f..fd58baed5a 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android.cc @@ -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 {