Skip to content

Commit 99421ae

Browse files
alanvAndroid (Google) Code Review
authored andcommitted
Merge "Invalidate root render node when accessibility focus moves" into lmp-dev
2 parents 33fe1ed + f6cf1a0 commit 99421ae

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
@@ -2458,13 +2458,30 @@ private void draw(boolean fullRedrawNeeded) {
24582458
if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) {
24592459
// Draw with hardware renderer.
24602460
mIsAnimating = false;
2461+
boolean invalidateRoot = false;
24612462
if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) {
24622463
mHardwareYOffset = yOffset;
24632464
mHardwareXOffset = xOffset;
2464-
mAttachInfo.mHardwareRenderer.invalidateRoot();
2465+
invalidateRoot = true;
24652466
}
24662467
mResizeAlpha = resizeAlpha;
24672468

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

24702487
mBlockResizeBuffer = false;
@@ -2619,41 +2636,46 @@ private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, i
26192636
* @param canvas The canvas on which to draw.
26202637
*/
26212638
private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) {
2639+
final Rect bounds = mAttachInfo.mTmpInvalRect;
2640+
if (getAccessibilityFocusedRect(bounds)) {
2641+
final Drawable drawable = getAccessibilityFocusedDrawable();
2642+
if (drawable != null) {
2643+
drawable.setBounds(bounds);
2644+
drawable.draw(canvas);
2645+
}
2646+
}
2647+
}
2648+
2649+
private boolean getAccessibilityFocusedRect(Rect bounds) {
26222650
final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext);
26232651
if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) {
2624-
return;
2652+
return false;
26252653
}
26262654

26272655
final View host = mAccessibilityFocusedHost;
26282656
if (host == null || host.mAttachInfo == null) {
2629-
return;
2630-
}
2631-
2632-
final Drawable drawable = getAccessibilityFocusedDrawable();
2633-
if (drawable == null) {
2634-
return;
2657+
return false;
26352658
}
26362659

26372660
final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider();
2638-
final Rect bounds = mAttachInfo.mTmpInvalRect;
26392661
if (provider == null) {
26402662
host.getBoundsOnScreen(bounds);
26412663
} else if (mAccessibilityFocusedVirtualView != null) {
26422664
mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds);
26432665
} else {
2644-
return;
2666+
return false;
26452667
}
26462668

2647-
bounds.offset(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop);
2648-
bounds.intersect(0, 0, mAttachInfo.mViewRootImpl.mWidth, mAttachInfo.mViewRootImpl.mHeight);
2649-
drawable.setBounds(bounds);
2650-
drawable.draw(canvas);
2669+
final AttachInfo attachInfo = mAttachInfo;
2670+
bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop);
2671+
bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, attachInfo.mViewRootImpl.mHeight);
2672+
return true;
26512673
}
26522674

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

0 commit comments

Comments
 (0)