summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jorge Gil <jorgegil@google.com> 2024-03-08 02:11:53 +0000
committer Jorge Gil <jorgegil@google.com> 2024-03-08 19:17:45 +0000
commitcceb6b31f14f8fa8580afb437b70dfba82810d6e (patch)
tree573fbf06a0f0d0867140b5af7f8202f7a3c559a2
parent10fe5e6e4af7d05af4a0e860d76e4fef0356ebd8 (diff)
Make single bounding rect when none set relative to window origin
When a source doesn't have any bounding rects set it means that the entire source frame should be treated as one single rect. This change makes that rect relative to the |relativeFrame|, which is what the API is promising. Bug: 328667331 Test: atest FrameworksCoreTests:InsetsSourceTest Change-Id: I5669895f15bfc6e1e8dad8aa32191e48b06bfbbb
-rw-r--r--core/java/android/view/InsetsSource.java12
-rw-r--r--core/tests/coretests/src/android/view/InsetsSourceTest.java11
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);