Skip to content

Commit f6cf1a0

Browse files
committed
Invalidate root render node when accessibility focus moves
BUG: 16796647 Change-Id: Ibfc6ec4aa50c6354ea095a35470dd54e768d911b
1 parent 61da0fd commit f6cf1a0

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,13 +2460,30 @@ private void draw(boolean fullRedrawNeeded) {
24602460
if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) {
24612461
// Draw with hardware renderer.
24622462
mIsAnimating = false;
2463+
boolean invalidateRoot = false;
24632464
if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) {
24642465
mHardwareYOffset = yOffset;
24652466
mHardwareXOffset = xOffset;
2466-
mAttachInfo.mHardwareRenderer.invalidateRoot();
2467+
invalidateRoot = true;
24672468
}
24682469
mResizeAlpha = resizeAlpha;
24692470

2471+
if (!invalidateRoot) {
2472+
// If accessibility focus moved, invalidate the root.
2473+
final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable;
2474+
if (drawable != null) {
2475+
final Rect bounds = mAttachInfo.mTmpInvalRect;
2476+
if (getAccessibilityFocusedRect(bounds)
2477+
&& !bounds.equals(drawable.getBounds())) {
2478+
invalidateRoot = true;
2479+
}
2480+
}
2481+
}
2482+
2483+
if (invalidateRoot) {
2484+
mAttachInfo.mHardwareRenderer.invalidateRoot();
2485+
}
2486+
24702487
dirty.setEmpty();
24712488

24722489
mBlockResizeBuffer = false;
@@ -2621,41 +2638,46 @@ private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, i
26212638
* @param canvas The canvas on which to draw.
26222639
*/
26232640
private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) {
2641+
final Rect bounds = mAttachInfo.mTmpInvalRect;
2642+
if (getAccessibilityFocusedRect(bounds)) {
2643+
final Drawable drawable = getAccessibilityFocusedDrawable();
2644+
if (drawable != null) {
2645+
drawable.setBounds(bounds);
2646+
drawable.draw(canvas);
2647+
}
2648+
}
2649+
}
2650+
2651+
private boolean getAccessibilityFocusedRect(Rect bounds) {
26242652
final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext);
26252653
if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) {
2626-
return;
2654+
return false;
26272655
}
26282656

26292657
final View host = mAccessibilityFocusedHost;
26302658
if (host == null || host.mAttachInfo == null) {
2631-
return;
2632-
}
2633-
2634-
final Drawable drawable = getAccessibilityFocusedDrawable();
2635-
if (drawable == null) {
2636-
return;
2659+
return false;
26372660
}
26382661

26392662
final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider();
2640-
final Rect bounds = mAttachInfo.mTmpInvalRect;
26412663
if (provider == null) {
26422664
host.getBoundsOnScreen(bounds);
26432665
} else if (mAccessibilityFocusedVirtualView != null) {
26442666
mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds);
26452667
} else {
2646-
return;
2668+
return false;
26472669
}
26482670

2649-
bounds.offset(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop);
2650-
bounds.intersect(0, 0, mAttachInfo.mViewRootImpl.mWidth, mAttachInfo.mViewRootImpl.mHeight);
2651-
drawable.setBounds(bounds);
2652-
drawable.draw(canvas);
2671+
final AttachInfo attachInfo = mAttachInfo;
2672+
bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop);
2673+
bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, attachInfo.mViewRootImpl.mHeight);
2674+
return true;
26532675
}
26542676

26552677
private Drawable getAccessibilityFocusedDrawable() {
26562678
// Lazily load the accessibility focus drawable.
26572679
if (mAttachInfo.mAccessibilityFocusDrawable == null) {
2658-
TypedValue value = new TypedValue();
2680+
final TypedValue value = new TypedValue();
26592681
final boolean resolved = mView.mContext.getTheme().resolveAttribute(
26602682
R.attr.accessibilityFocusedDrawable, value, true);
26612683
if (resolved) {

0 commit comments

Comments
 (0)