Merge "Fixes for a11y selection" into tm-dev

This commit is contained in:
Sally Yuen
2022-03-22 20:15:13 +00:00
committed by Android (Google) Code Review
2 changed files with 39 additions and 10 deletions

View File

@@ -14649,6 +14649,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
int selectionStart; int selectionStart;
int selectionEnd; int selectionEnd;
if (extendSelection && isAccessibilitySelectionExtendable()) { if (extendSelection && isAccessibilitySelectionExtendable()) {
prepareForExtendedAccessibilitySelection();
selectionStart = getAccessibilitySelectionStart(); selectionStart = getAccessibilitySelectionStart();
if (selectionStart == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { if (selectionStart == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) {
selectionStart = forward ? segmentStart : segmentEnd; selectionStart = forward ? segmentStart : segmentEnd;
@@ -14687,6 +14688,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
return false; return false;
} }
/**
* Prepare for extended selection.
* @hide
*/
public void prepareForExtendedAccessibilitySelection() {
return;
}
/** /**
* @hide * @hide
*/ */

View File

@@ -12363,9 +12363,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
// A view should not be exposed as clickable/long-clickable to a service because of a // A view should not be exposed as clickable/long-clickable to a service because of a
// LinkMovementMethod. // LinkMovementMethod or because it has selectable and non-editable text.
if ((info.isClickable() || info.isLongClickable()) if ((info.isClickable() || info.isLongClickable())
&& mMovement instanceof LinkMovementMethod) { && (mMovement instanceof LinkMovementMethod
|| (isTextSelectable() && !isTextEditable()))) {
if (!hasOnClickListeners()) { if (!hasOnClickListeners()) {
info.setClickable(false); info.setClickable(false);
info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK); info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK);
@@ -12597,11 +12598,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return true; return true;
} }
if (start >= 0 && start <= end && end <= text.length()) { if (start >= 0 && start <= end && end <= text.length()) {
requestFocusOnNonEditableSelectableText();
Selection.setSelection((Spannable) text, start, end); Selection.setSelection((Spannable) text, start, end);
// Make sure selection mode is engaged. hideAccessibilitySelectionControllers();
if (mEditor != null) {
mEditor.startSelectionActionModeAsync(false);
}
return true; return true;
} }
} }
@@ -12695,6 +12694,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return handled; return handled;
} }
private void requestFocusOnNonEditableSelectableText() {
if (!isTextEditable() && isTextSelectable()) {
if (!isEnabled()) {
return;
}
if (isFocusable() && !isFocused()) {
requestFocus();
}
}
}
private boolean hasSpannableText() { private boolean hasSpannableText() {
return mText != null && mText instanceof Spannable; return mText != null && mText instanceof Spannable;
} }
@@ -12723,9 +12734,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
/** /**
* Returns the text that should be exposed to accessibility services. * Returns the text that should be exposed to accessibility services.
* <p> * <p>
* This approximates what is displayed visually. If the user has specified * This approximates what is displayed visually.
* that accessibility services should speak passwords, this method will
* bypass any password transformation method and return unobscured text.
* *
* @return the text that should be exposed to accessibility services, may * @return the text that should be exposed to accessibility services, may
* be {@code null} if no text is set * be {@code null} if no text is set
@@ -13703,6 +13712,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return true; return true;
} }
/**
* @hide
*/
public void prepareForExtendedAccessibilitySelection() {
requestFocusOnNonEditableSelectableText();
}
/** /**
* @hide * @hide
*/ */
@@ -13727,8 +13743,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
Selection.removeSelection((Spannable) text); Selection.removeSelection((Spannable) text);
} }
// Hide all selection controllers used for adjusting selection // Hide all selection controllers used for adjusting selection
// since we are doing so explicitlty by other means and these // since we are doing so explicitly by other means and these
// controllers interact with how selection behaves. // controllers interact with how selection behaves.
hideAccessibilitySelectionControllers();
}
private void hideAccessibilitySelectionControllers() {
if (mEditor != null) { if (mEditor != null) {
mEditor.hideCursorAndSpanControllers(); mEditor.hideCursorAndSpanControllers();
mEditor.stopTextActionMode(); mEditor.stopTextActionMode();