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

Commit 99421aed authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Invalidate root render node when accessibility focus moves" into lmp-dev

parents 33fe1ed5 f6cf1a02
Loading
Loading
Loading
Loading
+37 −15
Original line number Diff line number Diff line
@@ -2458,13 +2458,30 @@ public final class ViewRootImpl implements ViewParent,
            if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) {
                // Draw with hardware renderer.
                mIsAnimating = false;
                boolean invalidateRoot = false;
                if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) {
                    mHardwareYOffset = yOffset;
                    mHardwareXOffset = xOffset;
                    mAttachInfo.mHardwareRenderer.invalidateRoot();
                    invalidateRoot = true;
                }
                mResizeAlpha = resizeAlpha;

                if (!invalidateRoot) {
                    // If accessibility focus moved, invalidate the root.
                    final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable;
                    if (drawable != null) {
                        final Rect bounds = mAttachInfo.mTmpInvalRect;
                        if (getAccessibilityFocusedRect(bounds)
                                && !bounds.equals(drawable.getBounds())) {
                            invalidateRoot = true;
                        }
                    }
                }

                if (invalidateRoot) {
                    mAttachInfo.mHardwareRenderer.invalidateRoot();
                }

                dirty.setEmpty();

                mBlockResizeBuffer = false;
@@ -2619,41 +2636,46 @@ public final class ViewRootImpl implements ViewParent,
     * @param canvas The canvas on which to draw.
     */
    private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) {
        final Rect bounds = mAttachInfo.mTmpInvalRect;
        if (getAccessibilityFocusedRect(bounds)) {
            final Drawable drawable = getAccessibilityFocusedDrawable();
            if (drawable != null) {
                drawable.setBounds(bounds);
                drawable.draw(canvas);
            }
        }
    }

    private boolean getAccessibilityFocusedRect(Rect bounds) {
        final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext);
        if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) {
            return;
            return false;
        }

        final View host = mAccessibilityFocusedHost;
        if (host == null || host.mAttachInfo == null) {
            return;
        }

        final Drawable drawable = getAccessibilityFocusedDrawable();
        if (drawable == null) {
            return;
            return false;
        }

        final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider();
        final Rect bounds = mAttachInfo.mTmpInvalRect;
        if (provider == null) {
            host.getBoundsOnScreen(bounds);
        } else if (mAccessibilityFocusedVirtualView != null) {
            mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds);
        } else {
            return;
            return false;
        }

        bounds.offset(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop);
        bounds.intersect(0, 0, mAttachInfo.mViewRootImpl.mWidth, mAttachInfo.mViewRootImpl.mHeight);
        drawable.setBounds(bounds);
        drawable.draw(canvas);
        final AttachInfo attachInfo = mAttachInfo;
        bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop);
        bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, attachInfo.mViewRootImpl.mHeight);
        return true;
    }

    private Drawable getAccessibilityFocusedDrawable() {
        // Lazily load the accessibility focus drawable.
        if (mAttachInfo.mAccessibilityFocusDrawable == null) {
            TypedValue value = new TypedValue();
            final TypedValue value = new TypedValue();
            final boolean resolved = mView.mContext.getTheme().resolveAttribute(
                    R.attr.accessibilityFocusedDrawable, value, true);
            if (resolved) {