Commit 528fea0c authored by Mark Schillaci's avatar Mark Schillaci Committed by Commit Bot

Addressing text selection mode on Android and AccessibilityEvent discrepancies

This CL addresses various coupled bugs in both text selection and non-
default granularity navigation for input fields/contenteditables on
Android. It fixes various issues with improper announcements,
announcements at the wrong time, and text selection not functioning in
general. It also addresses AccessibilityEvent discrepancies under-the-
hood in cases where we appeared to have the correct functionality to
the user, but only by happenstance as we were passing bad data to
TalkBack.

This CL addresses:
Bug 1041649 - Text selection on Android broken/not functioning
Bug 1017466 - Contenteditable word granularity navigation not reading
correctly
Bug 1041587 - Beginning/End of field announcements being read at
wrong index

Bug: 1041649,1017466,1041587
Change-Id: I30a8888e99e90356398d14319fbdf225839f5dac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1998829
Commit-Queue: Mark Schillaci <mschillaci@google.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734171}
parent b66375b9
......@@ -85,8 +85,7 @@ class AndroidGranularityMovementBrowserTest : public ContentBrowserTest {
int previous_end_index = -1;
while (manager->NextAtGranularity(granularity, end_index, android_node,
&start_index, &end_index)) {
int len =
(granularity == GRANULARITY_CHARACTER) ? 1 : end_index - start_index;
int len = end_index - start_index;
base::string16 selection = text.substr(start_index, len);
if (base::EndsWith(selection, base::ASCIIToUTF16("\n"),
base::CompareCase::INSENSITIVE_ASCII))
......@@ -111,8 +110,7 @@ class AndroidGranularityMovementBrowserTest : public ContentBrowserTest {
start_index = end_index;
while (manager->PreviousAtGranularity(
granularity, start_index, android_node, &start_index, &end_index)) {
int len =
(granularity == GRANULARITY_CHARACTER) ? 1 : end_index - start_index;
int len = end_index - start_index;
base::string16 selection = text.substr(start_index, len);
if (base::EndsWith(selection, base::ASCIIToUTF16("\n"),
base::CompareCase::INSENSITIVE_ASCII))
......
......@@ -287,8 +287,9 @@ bool BrowserAccessibilityManagerAndroid::NextAtGranularity(
base::i18n::UTF16CharIterator iter(text.data(), text.size());
while (!iter.end() && iter.array_pos() <= cursor_index)
iter.Advance();
*start_index = iter.array_pos();
*end_index = iter.array_pos();
iter.Rewind();
*start_index = iter.array_pos();
break;
}
case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD:
......@@ -335,7 +336,7 @@ bool BrowserAccessibilityManagerAndroid::PreviousAtGranularity(
iter.Advance();
}
*start_index = previous_index;
*end_index = previous_index;
*end_index = iter.array_pos();
break;
}
case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD:
......
......@@ -1066,9 +1066,9 @@ jboolean WebContentsAccessibilityAndroid::NextAtGranularity(
if (root_manager_->NextAtGranularity(granularity, cursor_index, node,
&start_index, &end_index)) {
base::string16 text = node->GetInnerText();
Java_WebContentsAccessibilityImpl_finishGranularityMove(
Java_WebContentsAccessibilityImpl_finishGranularityMoveNext(
env, obj, base::android::ConvertUTF16ToJavaString(env, text),
extend_selection, start_index, end_index, true);
extend_selection, start_index, end_index);
return true;
}
return false;
......@@ -1132,10 +1132,10 @@ jboolean WebContentsAccessibilityAndroid::PreviousAtGranularity(
int end_index = -1;
if (root_manager_->PreviousAtGranularity(granularity, cursor_index, node,
&start_index, &end_index)) {
Java_WebContentsAccessibilityImpl_finishGranularityMove(
Java_WebContentsAccessibilityImpl_finishGranularityMovePrevious(
env, obj,
base::android::ConvertUTF16ToJavaString(env, node->GetInnerText()),
extend_selection, start_index, end_index, false);
extend_selection, start_index, end_index);
return true;
}
return false;
......
......@@ -137,8 +137,8 @@ class CONTENT_EXPORT WebContentsAccessibilityAndroid
// of our own selection in BrowserAccessibilityManager.java for static
// text, but if this is an editable text node, updates the selected text
// in Blink, too, and either way calls
// Java_BrowserAccessibilityManager_finishGranularityMove with the
// result.
// Java_BrowserAccessibilityManager_finishGranularityMove[NEXT/PREVIOUS]
// with the result.
jboolean NextAtGranularity(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
jint granularity,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment