Skip to content

Commit cf8a3b8

Browse files
committed
Accessibility should not change input focus behavior.
1. Removed a change in the input focus behavior I forgot to take out when submitted the main accessibility focus patch. Ugh.. bug:6320098 Change-Id: Id7942e8aac64ba4bf6df7e19f733fa70b368d1bb
1 parent 427db9b commit cf8a3b8

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,24 +3013,23 @@ private boolean enterTouchMode() {
30133013
// be when the window is first being added, and mFocused isn't
30143014
// set yet.
30153015
final View focused = mView.findFocus();
3016-
if (focused != null) {
3017-
if (focused.isFocusableInTouchMode()) {
3018-
return true;
3019-
}
3016+
if (focused != null && !focused.isFocusableInTouchMode()) {
3017+
30203018
final ViewGroup ancestorToTakeFocus =
30213019
findAncestorToTakeFocusInTouchMode(focused);
30223020
if (ancestorToTakeFocus != null) {
30233021
// there is an ancestor that wants focus after its descendants that
30243022
// is focusable in touch mode.. give it focus
30253023
return ancestorToTakeFocus.requestFocus();
3024+
} else {
3025+
// nothing appropriate to have focus in touch mode, clear it out
3026+
mView.unFocus();
3027+
mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(focused, null);
3028+
mFocusedView = null;
3029+
mOldFocusedView = null;
3030+
return true;
30263031
}
30273032
}
3028-
// nothing appropriate to have focus in touch mode, clear it out
3029-
mView.unFocus();
3030-
mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(focused, null);
3031-
mFocusedView = null;
3032-
mOldFocusedView = null;
3033-
return true;
30343033
}
30353034
}
30363035
return false;
@@ -3061,45 +3060,25 @@ private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) {
30613060

30623061
private boolean leaveTouchMode() {
30633062
if (mView != null) {
3064-
boolean inputFocusValid = false;
30653063
if (mView.hasFocus()) {
30663064
// i learned the hard way to not trust mFocusedView :)
30673065
mFocusedView = mView.findFocus();
30683066
if (!(mFocusedView instanceof ViewGroup)) {
30693067
// some view has focus, let it keep it
3070-
inputFocusValid = true;
3071-
} else if (((ViewGroup) mFocusedView).getDescendantFocusability() !=
3068+
return false;
3069+
} else if (((ViewGroup)mFocusedView).getDescendantFocusability() !=
30723070
ViewGroup.FOCUS_AFTER_DESCENDANTS) {
30733071
// some view group has focus, and doesn't prefer its children
30743072
// over itself for focus, so let them keep it.
3075-
inputFocusValid = true;
3073+
return false;
30763074
}
30773075
}
3078-
// In accessibility mode we always have a view that has the
3079-
// accessibility focus and input focus follows it, i.e. we
3080-
// try to give input focus to the accessibility focused view.
3081-
if (!AccessibilityManager.getInstance(mView.mContext).isEnabled()) {
3082-
// If the current input focus is not valid, find the best view to give
3083-
// focus to in this brave new non-touch-mode world.
3084-
if (!inputFocusValid) {
3085-
final View focused = focusSearch(null, View.FOCUS_DOWN);
3086-
if (focused != null) {
3087-
return focused.requestFocus(View.FOCUS_DOWN);
3088-
}
3089-
}
3090-
} else {
3091-
// If the current input focus is not valid clear it but do not
3092-
// give it to another view since the accessibility focus is
3093-
// leading now and the input one follows.
3094-
if (!inputFocusValid) {
3095-
if (mFocusedView != null) {
3096-
mView.unFocus();
3097-
mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(mFocusedView, null);
3098-
mFocusedView = null;
3099-
mOldFocusedView = null;
3100-
return true;
3101-
}
3102-
}
3076+
3077+
// find the best view to give focus to in this brave new non-touch-mode
3078+
// world
3079+
final View focused = focusSearch(null, View.FOCUS_DOWN);
3080+
if (focused != null) {
3081+
return focused.requestFocus(View.FOCUS_DOWN);
31033082
}
31043083
}
31053084
return false;

0 commit comments

Comments
 (0)