diff options
| -rw-r--r-- | core/java/android/view/InsetsSource.java | 12 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/view/InsetsSourceTest.java | 11 |
2 files changed, 20 insertions, 3 deletions
diff --git a/core/java/android/view/InsetsSource.java b/core/java/android/view/InsetsSource.java index f9eba2948913..4ac78f593530 100644 --- a/core/java/android/view/InsetsSource.java +++ b/core/java/android/view/InsetsSource.java @@ -355,11 +355,17 @@ public class InsetsSource implements Parcelable { final Rect frame = getFrame(); if (mBoundingRects == null) { // No bounding rects set, make a single bounding rect that covers the intersection of - // the |frame| and the |relativeFrame|. + // the |frame| and the |relativeFrame|. Also make it relative to the window origin. return mTmpBoundingRect.setIntersect(frame, relativeFrame) - ? new Rect[]{ new Rect(mTmpBoundingRect) } + ? new Rect[]{ + new Rect( + mTmpBoundingRect.left - relativeFrame.left, + mTmpBoundingRect.top - relativeFrame.top, + mTmpBoundingRect.right - relativeFrame.left, + mTmpBoundingRect.bottom - relativeFrame.top + ) + } : NO_BOUNDING_RECTS; - } // Special treatment for captionBar inset type. During drag-resizing, the |frame| and diff --git a/core/tests/coretests/src/android/view/InsetsSourceTest.java b/core/tests/coretests/src/android/view/InsetsSourceTest.java index 936f4d7d5152..61e05dac2371 100644 --- a/core/tests/coretests/src/android/view/InsetsSourceTest.java +++ b/core/tests/coretests/src/android/view/InsetsSourceTest.java @@ -291,6 +291,17 @@ public class InsetsSourceTest { } @Test + public void testCalculateBoundingRects_noBoundingRectsAndFrameNotAtOrigin_createsSingleRect() { + mSource.setFrame(new Rect(100, 100, 1200, 200)); + mSource.setBoundingRects(null); + + final Rect[] rects = mSource.calculateBoundingRects(new Rect(100, 100, 1100, 1100), false); + + assertEquals(1, rects.length); + assertEquals(new Rect(0, 0, 1000, 100), rects[0]); + } + + @Test public void testCalculateBoundingRects_noBoundingRectsAndLargerFrame_singleRectFitsRelFrame() { mSource.setFrame(new Rect(0, 0, 1000, 100)); mSource.setBoundingRects(null); |