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 { ...@@ -85,8 +85,7 @@ class AndroidGranularityMovementBrowserTest : public ContentBrowserTest {
int previous_end_index = -1; int previous_end_index = -1;
while (manager->NextAtGranularity(granularity, end_index, android_node, while (manager->NextAtGranularity(granularity, end_index, android_node,
&start_index, &end_index)) { &start_index, &end_index)) {
int len = int len = end_index - start_index;
(granularity == GRANULARITY_CHARACTER) ? 1 : end_index - start_index;
base::string16 selection = text.substr(start_index, len); base::string16 selection = text.substr(start_index, len);
if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), if (base::EndsWith(selection, base::ASCIIToUTF16("\n"),
base::CompareCase::INSENSITIVE_ASCII)) base::CompareCase::INSENSITIVE_ASCII))
...@@ -111,8 +110,7 @@ class AndroidGranularityMovementBrowserTest : public ContentBrowserTest { ...@@ -111,8 +110,7 @@ class AndroidGranularityMovementBrowserTest : public ContentBrowserTest {
start_index = end_index; start_index = end_index;
while (manager->PreviousAtGranularity( while (manager->PreviousAtGranularity(
granularity, start_index, android_node, &start_index, &end_index)) { granularity, start_index, android_node, &start_index, &end_index)) {
int len = int len = end_index - start_index;
(granularity == GRANULARITY_CHARACTER) ? 1 : end_index - start_index;
base::string16 selection = text.substr(start_index, len); base::string16 selection = text.substr(start_index, len);
if (base::EndsWith(selection, base::ASCIIToUTF16("\n"), if (base::EndsWith(selection, base::ASCIIToUTF16("\n"),
base::CompareCase::INSENSITIVE_ASCII)) base::CompareCase::INSENSITIVE_ASCII))
......
...@@ -287,8 +287,9 @@ bool BrowserAccessibilityManagerAndroid::NextAtGranularity( ...@@ -287,8 +287,9 @@ bool BrowserAccessibilityManagerAndroid::NextAtGranularity(
base::i18n::UTF16CharIterator iter(text.data(), text.size()); base::i18n::UTF16CharIterator iter(text.data(), text.size());
while (!iter.end() && iter.array_pos() <= cursor_index) while (!iter.end() && iter.array_pos() <= cursor_index)
iter.Advance(); iter.Advance();
*start_index = iter.array_pos();
*end_index = iter.array_pos(); *end_index = iter.array_pos();
iter.Rewind();
*start_index = iter.array_pos();
break; break;
} }
case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD: case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD:
...@@ -335,7 +336,7 @@ bool BrowserAccessibilityManagerAndroid::PreviousAtGranularity( ...@@ -335,7 +336,7 @@ bool BrowserAccessibilityManagerAndroid::PreviousAtGranularity(
iter.Advance(); iter.Advance();
} }
*start_index = previous_index; *start_index = previous_index;
*end_index = previous_index; *end_index = iter.array_pos();
break; break;
} }
case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD: case ANDROID_ACCESSIBILITY_NODE_INFO_MOVEMENT_GRANULARITY_WORD:
......
...@@ -1066,9 +1066,9 @@ jboolean WebContentsAccessibilityAndroid::NextAtGranularity( ...@@ -1066,9 +1066,9 @@ jboolean WebContentsAccessibilityAndroid::NextAtGranularity(
if (root_manager_->NextAtGranularity(granularity, cursor_index, node, if (root_manager_->NextAtGranularity(granularity, cursor_index, node,
&start_index, &end_index)) { &start_index, &end_index)) {
base::string16 text = node->GetInnerText(); base::string16 text = node->GetInnerText();
Java_WebContentsAccessibilityImpl_finishGranularityMove( Java_WebContentsAccessibilityImpl_finishGranularityMoveNext(
env, obj, base::android::ConvertUTF16ToJavaString(env, text), env, obj, base::android::ConvertUTF16ToJavaString(env, text),
extend_selection, start_index, end_index, true); extend_selection, start_index, end_index);
return true; return true;
} }
return false; return false;
...@@ -1132,10 +1132,10 @@ jboolean WebContentsAccessibilityAndroid::PreviousAtGranularity( ...@@ -1132,10 +1132,10 @@ jboolean WebContentsAccessibilityAndroid::PreviousAtGranularity(
int end_index = -1; int end_index = -1;
if (root_manager_->PreviousAtGranularity(granularity, cursor_index, node, if (root_manager_->PreviousAtGranularity(granularity, cursor_index, node,
&start_index, &end_index)) { &start_index, &end_index)) {
Java_WebContentsAccessibilityImpl_finishGranularityMove( Java_WebContentsAccessibilityImpl_finishGranularityMovePrevious(
env, obj, env, obj,
base::android::ConvertUTF16ToJavaString(env, node->GetInnerText()), base::android::ConvertUTF16ToJavaString(env, node->GetInnerText()),
extend_selection, start_index, end_index, false); extend_selection, start_index, end_index);
return true; return true;
} }
return false; return false;
......
...@@ -137,8 +137,8 @@ class CONTENT_EXPORT WebContentsAccessibilityAndroid ...@@ -137,8 +137,8 @@ class CONTENT_EXPORT WebContentsAccessibilityAndroid
// of our own selection in BrowserAccessibilityManager.java for static // of our own selection in BrowserAccessibilityManager.java for static
// text, but if this is an editable text node, updates the selected text // text, but if this is an editable text node, updates the selected text
// in Blink, too, and either way calls // in Blink, too, and either way calls
// Java_BrowserAccessibilityManager_finishGranularityMove with the // Java_BrowserAccessibilityManager_finishGranularityMove[NEXT/PREVIOUS]
// result. // with the result.
jboolean NextAtGranularity(JNIEnv* env, jboolean NextAtGranularity(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
jint granularity, 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