From 21f9a3608d618e3dcd30bc73dc60ebfb18690041 Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Tue, 16 Apr 2013 17:21:41 -0700 Subject: Fixes for setClipBounds() The invalidate region when the clip bounds are set needs to encompass both the old clip bounds and the new bounds, to make sure that the right area of the view gets erased as well as drawn. Also, we need to keep our own internal copy of the bounds, not just use the instance passed into the setter. Issue #8634060 setClipBounds() problems Change-Id: I123c49cff16e3debe8866974a5612a4efd010de4 --- core/java/android/view/View.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'core/java/android/view/View.java') diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 4fb2431..be26d20 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -13380,18 +13380,32 @@ public class View implements Drawable.Callback, KeyEvent.Callback, /** * Sets a rectangular area on this view to which the view will be clipped - * it is drawn. Setting the value to null will remove the clip bounds + * when it is drawn. Setting the value to null will remove the clip bounds * and the view will draw normally, using its full bounds. * * @param clipBounds The rectangular area, in the local coordinates of * this view, to which future drawing operations will be clipped. */ public void setClipBounds(Rect clipBounds) { - mClipBounds = clipBounds; if (clipBounds != null) { - invalidate(clipBounds); + if (clipBounds.equals(mClipBounds)) { + return; + } + if (mClipBounds == null) { + invalidate(); + mClipBounds = new Rect(clipBounds); + } else { + invalidate(Math.min(mClipBounds.left, clipBounds.left), + Math.min(mClipBounds.top, clipBounds.top), + Math.max(mClipBounds.right, clipBounds.right), + Math.max(mClipBounds.bottom, clipBounds.bottom)); + mClipBounds.set(clipBounds); + } } else { - invalidate(); + if (mClipBounds != null) { + invalidate(); + mClipBounds = null; + } } } -- cgit v1.1