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

Commit 9aab53d8 authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Allow a frame to receive insets when a side is partially covered" into main

parents 2a39a0c6 9e881932
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -357,6 +357,31 @@ public class InsetsSource implements Parcelable {
            } else if (mTmpFrame.right == relativeFrame.right) {
                return Insets.of(0, 0, mTmpFrame.width(), 0);
            }
        } else {
            // The source doesn't cover the width or the height of relativeFrame, but just parts of
            // them. Here uses mSideHint to decide which side should be inset.
            switch (mSideHint) {
                case SIDE_LEFT:
                    if (mTmpFrame.left == relativeFrame.left) {
                        return Insets.of(mTmpFrame.width(), 0, 0, 0);
                    }
                    break;
                case SIDE_TOP:
                    if (mTmpFrame.top == relativeFrame.top) {
                        return Insets.of(0, mTmpFrame.height(), 0, 0);
                    }
                    break;
                case SIDE_RIGHT:
                    if (mTmpFrame.right == relativeFrame.right) {
                        return Insets.of(0, 0, mTmpFrame.width(), 0);
                    }
                    break;
                case SIDE_BOTTOM:
                    if (mTmpFrame.bottom == relativeFrame.bottom) {
                        return Insets.of(0, 0, 0, mTmpFrame.height());
                    }
                    break;
            }
        }
        return Insets.NONE;
    }
+96 −0
Original line number Diff line number Diff line
@@ -210,6 +210,102 @@ public class InsetsSourceTest {
        assertEquals(Insets.of(100, 0, 0, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_leftCenter() {
        mSource.setFrame(new Rect(0, 0, 100, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 400), false);
        assertEquals(Insets.of(100, 0, 0, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_leftTop() {
        mSource.setFrame(new Rect(0, 0, 100, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(0, -100, 500, 400), false);
        assertEquals(Insets.of(100, 0, 0, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_leftBottom() {
        mSource.setFrame(new Rect(0, 0, 100, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 600), false);
        assertEquals(Insets.of(100, 0, 0, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_topCenter() {
        mSource.setFrame(new Rect(0, 0, 500, 100));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(-100, 0, 600, 500), false);
        assertEquals(Insets.of(0, 100, 0, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_topLeft() {
        mSource.setFrame(new Rect(0, 0, 500, 100));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(-100, 0, 400, 500), false);
        assertEquals(Insets.of(0, 100, 0, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_topRight() {
        mSource.setFrame(new Rect(0, 0, 500, 100));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(100, 0, 600, 500), false);
        assertEquals(Insets.of(0, 100, 0, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_rightCenter() {
        mSource.setFrame(new Rect(400, 0, 500, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 400), false);
        assertEquals(Insets.of(0, 0, 100, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_rightTop() {
        mSource.setFrame(new Rect(400, 0, 500, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(0, -100, 500, 400), false);
        assertEquals(Insets.of(0, 0, 100, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_rightBottom() {
        mSource.setFrame(new Rect(400, 0, 500, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 600), false);
        assertEquals(Insets.of(0, 0, 100, 0), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_bottomCenter() {
        mSource.setFrame(new Rect(0, 400, 500, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(-100, 0, 600, 500), false);
        assertEquals(Insets.of(0, 0, 0, 100), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_bottomLeft() {
        mSource.setFrame(new Rect(0, 400, 500, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(-100, 0, 400, 500), false);
        assertEquals(Insets.of(0, 0, 0, 100), insets);
    }

    @Test
    public void testCalculateInsets_partialSideIntersection_bottomRight() {
        mSource.setFrame(new Rect(0, 400, 500, 500));
        mSource.updateSideHint(new Rect(0, 0, 500, 500));
        Insets insets = mSource.calculateInsets(new Rect(100, 0, 600, 500), false);
        assertEquals(Insets.of(0, 0, 0, 100), insets);
    }

    @Test
    public void testCalculateVisibleInsets_override() {
        mSource.setFrame(new Rect(0, 0, 500, 100));