Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb68fdb9 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "Accessibility should not change input focus behavior." into jb-dev

parents f2dc6fc4 cf8a3b82
Loading
Loading
Loading
Loading
+18 −39
Original line number Original line Diff line number Diff line
@@ -3019,18 +3019,15 @@ public final class ViewRootImpl implements ViewParent,
                // be when the window is first being added, and mFocused isn't
                // be when the window is first being added, and mFocused isn't
                // set yet.
                // set yet.
                final View focused = mView.findFocus();
                final View focused = mView.findFocus();
                if (focused != null) {
                if (focused != null && !focused.isFocusableInTouchMode()) {
                    if (focused.isFocusableInTouchMode()) {

                        return true;
                    }
                    final ViewGroup ancestorToTakeFocus =
                    final ViewGroup ancestorToTakeFocus =
                            findAncestorToTakeFocusInTouchMode(focused);
                            findAncestorToTakeFocusInTouchMode(focused);
                    if (ancestorToTakeFocus != null) {
                    if (ancestorToTakeFocus != null) {
                        // there is an ancestor that wants focus after its descendants that
                        // there is an ancestor that wants focus after its descendants that
                        // is focusable in touch mode.. give it focus
                        // is focusable in touch mode.. give it focus
                        return ancestorToTakeFocus.requestFocus();
                        return ancestorToTakeFocus.requestFocus();
                    }
                    } else {
                }
                        // nothing appropriate to have focus in touch mode, clear it out
                        // nothing appropriate to have focus in touch mode, clear it out
                        mView.unFocus();
                        mView.unFocus();
                        mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(focused, null);
                        mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(focused, null);
@@ -3039,6 +3036,8 @@ public final class ViewRootImpl implements ViewParent,
                        return true;
                        return true;
                    }
                    }
                }
                }
            }
        }
        return false;
        return false;
    }
    }


@@ -3067,47 +3066,27 @@ public final class ViewRootImpl implements ViewParent,


    private boolean leaveTouchMode() {
    private boolean leaveTouchMode() {
        if (mView != null) {
        if (mView != null) {
            boolean inputFocusValid = false;
            if (mView.hasFocus()) {
            if (mView.hasFocus()) {
                // i learned the hard way to not trust mFocusedView :)
                // i learned the hard way to not trust mFocusedView :)
                mFocusedView = mView.findFocus();
                mFocusedView = mView.findFocus();
                if (!(mFocusedView instanceof ViewGroup)) {
                if (!(mFocusedView instanceof ViewGroup)) {
                    // some view has focus, let it keep it
                    // some view has focus, let it keep it
                    inputFocusValid = true;
                    return false;
                } else if (((ViewGroup)mFocusedView).getDescendantFocusability() !=
                } else if (((ViewGroup)mFocusedView).getDescendantFocusability() !=
                        ViewGroup.FOCUS_AFTER_DESCENDANTS) {
                        ViewGroup.FOCUS_AFTER_DESCENDANTS) {
                    // some view group has focus, and doesn't prefer its children
                    // some view group has focus, and doesn't prefer its children
                    // over itself for focus, so let them keep it.
                    // over itself for focus, so let them keep it.
                    inputFocusValid = true;
                    return false;
                }
                }
            }
            }
            // In accessibility mode we always have a view that has the

            // accessibility focus and input focus follows it, i.e. we
            // find the best view to give focus to in this brave new non-touch-mode
            // try to give input focus to the accessibility focused view.
            // world
            if (!AccessibilityManager.getInstance(mView.mContext).isEnabled()) {
                // If the current input focus is not valid, find the best view to give
                // focus to in this brave new non-touch-mode world.
                if (!inputFocusValid) {
            final View focused = focusSearch(null, View.FOCUS_DOWN);
            final View focused = focusSearch(null, View.FOCUS_DOWN);
            if (focused != null) {
            if (focused != null) {
                return focused.requestFocus(View.FOCUS_DOWN);
                return focused.requestFocus(View.FOCUS_DOWN);
            }
            }
        }
        }
            } else {
                // If the current input focus is not valid clear it but do not
                // give it to another view since the accessibility focus is
                // leading now and the input one follows.
                if (!inputFocusValid) {
                    if (mFocusedView != null) {
                        mView.unFocus();
                        mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(mFocusedView, null);
                        mFocusedView = null;
                        mOldFocusedView = null;
                        return true;
                    }
                }
            }
        }
        return false;
        return false;
    }
    }