OSDN Git Service

Fix getChildVisibleRect to clip correctly.
authorGeorge Mount <mount@google.com>
Tue, 11 Nov 2014 20:54:43 +0000 (12:54 -0800)
committerGeorge Mount <mount@google.com>
Wed, 12 Nov 2014 16:04:34 +0000 (08:04 -0800)
Bug 18292516

getClipVisibleRect now takes into account clipChildren,
clipBounds, and clipToPadding.

Change-Id: I181cd68354e70767868e9edd56bf82a58357391d

core/java/android/view/ViewGroup.java

index 654a8ed..2f8698e 100644 (file)
@@ -5017,7 +5017,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
         rect.set(r);
 
         if (!child.hasIdentityMatrix()) {
-           child.getMatrix().mapRect(rect);
+            child.getMatrix().mapRect(rect);
         }
 
         int dx = child.mLeft - mScrollX;
@@ -5039,14 +5039,30 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
             offset.y += dy;
         }
 
-        if (rect.intersect(0, 0, mRight - mLeft, mBottom - mTop)) {
-            if (mParent == null) return true;
-            r.set((int) (rect.left + 0.5f), (int) (rect.top + 0.5f),
-                    (int) (rect.right + 0.5f), (int) (rect.bottom + 0.5f));
-            return mParent.getChildVisibleRect(this, r, offset);
+        boolean rectIsVisible = true;
+        if (mParent instanceof ViewGroup && ((ViewGroup)mParent).getClipChildren()) {
+            // clipChildren clips to the child's bounds
+            rectIsVisible = rect.intersect(0, 0, mRight - mLeft, mBottom - mTop);
         }
 
-        return false;
+        if (rectIsVisible && (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK) {
+            // Clip to padding
+            rectIsVisible = rect.intersect(mPaddingLeft, mPaddingTop,
+                    mRight - mLeft - mPaddingLeft - mPaddingRight,
+                    mBottom - mTop - mPaddingTop - mPaddingBottom);
+        }
+
+        if (rectIsVisible && mClipBounds != null) {
+            // Clip to clipBounds
+            rectIsVisible = rect.intersect(mClipBounds.left, mClipBounds.top, mClipBounds.right,
+                    mClipBounds.bottom);
+        }
+        r.set((int) (rect.left + 0.5f), (int) (rect.top + 0.5f), (int) (rect.right + 0.5f),
+                (int) (rect.bottom + 0.5f));
+        if (rectIsVisible && mParent != null) {
+            rectIsVisible = mParent.getChildVisibleRect(this, r, offset);
+        }
+        return rectIsVisible;
     }
 
     /**