Merge "Ensure that a11y window state change event is sent on focus change"

This commit is contained in:
TreeHugger Robot
2022-12-07 23:51:11 +00:00
committed by Android (Google) Code Review

View File

@@ -471,16 +471,6 @@ public final class ViewRootImpl implements ViewParent,
private boolean mAppVisibilityChanged;
int mOrigWindowType = -1;
/** Whether the window had focus during the most recent traversal. */
boolean mHadWindowFocus;
/**
* Whether the window lost focus during a previous traversal and has not
* yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE
* accessibility events should be sent during traversal.
*/
boolean mLostWindowFocus;
// Set to true if the owner of this window is in the stopped state,
// so the window should no longer be active.
@UnsupportedAppUsage
@@ -3630,20 +3620,8 @@ public final class ViewRootImpl implements ViewParent,
}
final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible;
final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible;
final boolean regainedFocus = hasWindowFocus && mLostWindowFocus;
if (regainedFocus) {
mLostWindowFocus = false;
} else if (!hasWindowFocus && mHadWindowFocus) {
mLostWindowFocus = true;
}
if (changedVisibility || regainedFocus) {
// Toasts are presented as notifications - don't present them as windows as well
boolean isToast = mWindowAttributes.type == TYPE_TOAST;
if (!isToast) {
host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
if (changedVisibility) {
maybeFireAccessibilityWindowStateChangedEvent();
}
mFirst = false;
@@ -3651,8 +3629,8 @@ public final class ViewRootImpl implements ViewParent,
mNewSurfaceNeeded = false;
mActivityRelaunched = false;
mViewVisibility = viewVisibility;
mHadWindowFocus = hasWindowFocus;
final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible;
mImeFocusController.onTraversal(hasWindowFocus, mWindowAttributes);
if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) {
@@ -3895,6 +3873,8 @@ public final class ViewRootImpl implements ViewParent,
~WindowManager.LayoutParams
.SOFT_INPUT_IS_FORWARD_NAVIGATION;
maybeFireAccessibilityWindowStateChangedEvent();
// Refocusing a window that has a focused view should fire a
// focus event for the view since the global focused view changed.
fireAccessibilityFocusEventIfHasFocusedNode();
@@ -3922,6 +3902,14 @@ public final class ViewRootImpl implements ViewParent,
ensureTouchModeLocally(inTouchMode);
}
private void maybeFireAccessibilityWindowStateChangedEvent() {
// Toasts are presented as notifications - don't present them as windows as well.
boolean isToast = mWindowAttributes != null && (mWindowAttributes.type == TYPE_TOAST);
if (!isToast && mView != null) {
mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
}
private void fireAccessibilityFocusEventIfHasFocusedNode() {
if (!AccessibilityManager.getInstance(mContext).isEnabled()) {
return;