未验证 提交 e4cabae5 编写于 作者: M Michael Goderbauer 提交者: GitHub

Add a11y support for selected text (#4584)

上级 d7158609
......@@ -293,6 +293,9 @@ 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
/// currently selected text within `value`.
///
/// The `rect` is the region occupied by this node in its own coordinate
/// system.
///
......@@ -302,6 +305,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
Rect rect,
String label,
String hint,
......@@ -318,6 +323,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
id,
flags,
actions,
textSelectionStart,
textSelectionEnd,
rect.left,
rect.top,
rect.right,
......@@ -336,6 +343,8 @@ class SemanticsUpdateBuilder extends NativeFieldWrapperClass2 {
int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
double left,
double top,
double right,
......
......@@ -55,6 +55,8 @@ struct SemanticsNode {
int32_t id = 0;
int32_t flags = 0;
int32_t actions = 0;
int32_t textSelectionStart = -1;
int32_t textSelectionEnd = -1;
std::string label;
std::string hint;
std::string value;
......
......@@ -37,6 +37,8 @@ SemanticsUpdateBuilder::~SemanticsUpdateBuilder() = default;
void SemanticsUpdateBuilder::updateNode(int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
double left,
double top,
double right,
......@@ -53,6 +55,8 @@ void SemanticsUpdateBuilder::updateNode(int id,
node.id = id;
node.flags = flags;
node.actions = actions;
node.textSelectionStart = textSelectionStart;
node.textSelectionEnd = textSelectionEnd;
node.rect = SkRect::MakeLTRB(left, top, right, bottom);
node.label = label;
node.hint = hint;
......
......@@ -28,6 +28,8 @@ class SemanticsUpdateBuilder
void updateNode(int id,
int flags,
int actions,
int textSelectionStart,
int textSelectionEnd,
double left,
double top,
double right,
......
......@@ -123,8 +123,12 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
if (object.hasFlag(Flag.IS_TEXT_FIELD)) {
result.setClassName("android.widget.EditText");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
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);
}
}
// Cursor movements
int granularities = 0;
......@@ -599,6 +603,8 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
int flags;
int actions;
int textSelectionStart;
int textSelectionEnd;
String label;
String value;
String increasedValue;
......@@ -658,6 +664,8 @@ class AccessibilityBridge extends AccessibilityNodeProvider implements BasicMess
flags = buffer.getInt();
actions = buffer.getInt();
textSelectionStart = buffer.getInt();
textSelectionEnd = buffer.getInt();
int stringIndex = buffer.getInt();
label = stringIndex == -1 ? null : strings[stringIndex];
......
......@@ -461,7 +461,7 @@ bool PlatformViewAndroid::ResourceContextMakeCurrent() {
void PlatformViewAndroid::UpdateSemantics(
std::vector<blink::SemanticsNode> update) {
constexpr size_t kBytesPerNode = 30 * sizeof(int32_t);
constexpr size_t kBytesPerNode = 32 * sizeof(int32_t);
constexpr size_t kBytesPerChild = sizeof(int32_t);
JNIEnv* env = fml::jni::AttachCurrentThread();
......@@ -488,6 +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;
if (node.label.empty()) {
buffer_int32[position++] = -1;
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册