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

Commit 19cadc20 authored by Selim Cinek's avatar Selim Cinek
Browse files

ViewGroup now applies clipBounds to its children

Fixed a bug where a ViewGroup did not clip its children to the
set clipBounds unless willNotDraw was set to true.

Bug: 14104527
Change-Id: I4892639bb860c1767f1ae6892f3e69525691e55e
parent 781c55fd
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -719,6 +719,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static boolean sIgnoreMeasureCache = false;
    /**
     * Ignore the clipBounds of this view for the children.
     */
    static boolean sIgnoreClipBoundsForChildren = false;
    /**
     * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
     * calling setFlags.
@@ -2963,7 +2968,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    /**
     * Current clip bounds. to which all drawing of this view are constrained.
     */
    private Rect mClipBounds = null;
    Rect mClipBounds = null;
    private boolean mLastIsOpaque;
@@ -3511,6 +3516,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // of whether a layout was requested on that View.
            sIgnoreMeasureCache = targetSdkVersion < KITKAT;
            // Older apps may need this to ignore the clip bounds
            sIgnoreClipBoundsForChildren = targetSdkVersion < L;
            sCompatibilityDone = true;
        }
    }
+14 −4
Original line number Diff line number Diff line
@@ -2960,14 +2960,24 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            }
        }

        int saveCount = 0;
        int clipSaveCount = 0;
        final boolean clipToPadding = (flags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK;
        boolean hasClipBounds = mClipBounds != null && !sIgnoreClipBoundsForChildren;
        boolean clippingNeeded = clipToPadding || hasClipBounds;

        if (clippingNeeded) {
            clipSaveCount = canvas.save();
        }

        if (clipToPadding) {
            saveCount = canvas.save();
            canvas.clipRect(mScrollX + mPaddingLeft, mScrollY + mPaddingTop,
                    mScrollX + mRight - mLeft - mPaddingRight,
                    mScrollY + mBottom - mTop - mPaddingBottom);
        }

        if (hasClipBounds) {
            canvas.clipRect(mClipBounds.left, mClipBounds.top, mClipBounds.right,
                    mClipBounds.bottom);
        }

        // We will draw our child's animation, let's reset the flag
@@ -3008,8 +3018,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            onDebugDraw(canvas);
        }

        if (clipToPadding) {
            canvas.restoreToCount(saveCount);
        if (clippingNeeded) {
            canvas.restoreToCount(clipSaveCount);
        }

        // mGroupFlags might have been updated by drawChild()