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

Commit 5db0901c authored by Vania Desmonda's avatar Vania Desmonda Committed by Android (Google) Code Review
Browse files

Merge "Limit task bounds to stable bounds if resizing beyond the stable bounds." into main

parents 233574e2 6e241f81
Loading
Loading
Loading
Loading
+15 −23
Original line number Diff line number Diff line
@@ -82,32 +82,26 @@ public class DragPositioningCallbackUtility {
        final int oldRight = repositionTaskBounds.right;
        final int oldBottom = repositionTaskBounds.bottom;


        repositionTaskBounds.set(taskBoundsAtDragStart);

        // Make sure the new resizing destination in any direction falls within the stable bounds.
        // If not, set the bounds back to the old location that was valid to avoid conflicts with
        // some regions such as the gesture area.
        if ((ctrlType & CTRL_TYPE_LEFT) != 0) {
            final int candidateLeft = repositionTaskBounds.left + (int) delta.x;
            repositionTaskBounds.left = (candidateLeft > stableBounds.left)
                    ? candidateLeft : oldLeft;
            repositionTaskBounds.left = Math.max(repositionTaskBounds.left + (int) delta.x,
                    stableBounds.left);
        }
        if ((ctrlType & CTRL_TYPE_RIGHT) != 0) {
            final int candidateRight = repositionTaskBounds.right + (int) delta.x;
            repositionTaskBounds.right = (candidateRight < stableBounds.right)
                    ? candidateRight : oldRight;
            repositionTaskBounds.right = Math.min(repositionTaskBounds.right + (int) delta.x,
                    stableBounds.right);
        }
        if ((ctrlType & CTRL_TYPE_TOP) != 0) {
            final int candidateTop = repositionTaskBounds.top + (int) delta.y;
            repositionTaskBounds.top = (candidateTop > stableBounds.top)
                    ? candidateTop : oldTop;
            repositionTaskBounds.top = Math.max(repositionTaskBounds.top + (int) delta.y,
                    stableBounds.top);
        }
        if ((ctrlType & CTRL_TYPE_BOTTOM) != 0) {
            final int candidateBottom = repositionTaskBounds.bottom + (int) delta.y;
            repositionTaskBounds.bottom = (candidateBottom < stableBounds.bottom)
                    ? candidateBottom : oldBottom;
            repositionTaskBounds.bottom = Math.min(repositionTaskBounds.bottom + (int) delta.y,
                    stableBounds.bottom);
        }

        // If width or height are negative or exceeding the width or height constraints, revert the
        // respective bounds to use previous bound dimensions.
        if (isExceedingWidthConstraint(repositionTaskBounds, stableBounds, displayController,
@@ -120,14 +114,12 @@ public class DragPositioningCallbackUtility {
            repositionTaskBounds.top = oldTop;
            repositionTaskBounds.bottom = oldBottom;
        }
        // If there are no changes to the bounds after checking new bounds against minimum width
        // and height, do not set bounds and return false
        if (oldLeft == repositionTaskBounds.left && oldTop == repositionTaskBounds.top
                && oldRight == repositionTaskBounds.right
                && oldBottom == repositionTaskBounds.bottom) {
            return false;
        }
        return true;

        // If there are no changes to the bounds after checking new bounds against minimum and
        // maximum width and height, do not set bounds and return false
        return oldLeft != repositionTaskBounds.left || oldTop != repositionTaskBounds.top
                || oldRight != repositionTaskBounds.right
                || oldBottom != repositionTaskBounds.bottom;
    }

    /**
+120 −50
Original line number Diff line number Diff line
@@ -129,9 +129,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.top.toFloat() + 95
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )

        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
@@ -149,9 +151,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.top.toFloat() + 5
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )

        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top + 5)
@@ -169,9 +173,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.top.toFloat() + 105
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )

        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
@@ -189,9 +195,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.top.toFloat() + 80
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top + 80)
        assertThat(repositionTaskBounds.right).isEqualTo(STARTING_BOUNDS.right - 80)
@@ -208,9 +216,11 @@ class DragPositioningCallbackUtilityTest {

        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_TOP,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
        assertThat(repositionTaskBounds.right).isEqualTo(STARTING_BOUNDS.right)
@@ -221,15 +231,21 @@ class DragPositioningCallbackUtilityTest {
    fun testDragEndSnapsTaskBoundsWhenOutsideValidDragArea() {
        val startingPoint = PointF(STARTING_BOUNDS.right.toFloat(), STARTING_BOUNDS.top.toFloat())
        val repositionTaskBounds = Rect(STARTING_BOUNDS)
        val validDragArea = Rect(DISPLAY_BOUNDS.left - 100,
        val validDragArea = Rect(
            DISPLAY_BOUNDS.left - 100,
            STABLE_BOUNDS.top,
            DISPLAY_BOUNDS.right - 100,
            DISPLAY_BOUNDS.bottom - 100)
            DISPLAY_BOUNDS.bottom - 100
        )

        DragPositioningCallbackUtility.updateTaskBounds(repositionTaskBounds, STARTING_BOUNDS,
            startingPoint, startingPoint.x - 1000, (DISPLAY_BOUNDS.bottom + 1000).toFloat())
        DragPositioningCallbackUtility.snapTaskBoundsIfNecessary(repositionTaskBounds,
            validDragArea)
        DragPositioningCallbackUtility.updateTaskBounds(
            repositionTaskBounds, STARTING_BOUNDS,
            startingPoint, startingPoint.x - 1000, (DISPLAY_BOUNDS.bottom + 1000).toFloat()
        )
        DragPositioningCallbackUtility.snapTaskBoundsIfNecessary(
            repositionTaskBounds,
            validDragArea
        )
        assertThat(repositionTaskBounds.left).isEqualTo(validDragArea.left)
        assertThat(repositionTaskBounds.top).isEqualTo(validDragArea.bottom)
        assertThat(repositionTaskBounds.right)
@@ -240,27 +256,64 @@ class DragPositioningCallbackUtilityTest {

    @Test
    fun testChangeBounds_toDisallowedBounds_freezesAtLimit() {
        val startingPoint = PointF(STARTING_BOUNDS.right.toFloat(),
            STARTING_BOUNDS.bottom.toFloat())
        val startingPoint = PointF(
            STARTING_BOUNDS.right.toFloat(),
            STARTING_BOUNDS.bottom.toFloat()
        )
        val repositionTaskBounds = Rect(STARTING_BOUNDS)
        // Initial resize to width and height 110px.
        var newX = STARTING_BOUNDS.right.toFloat() + 10
        var newY = STARTING_BOUNDS.bottom.toFloat() + 10
        var delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)
        assertTrue(DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        assertTrue(
            DragPositioningCallbackUtility.changeBounds(
                CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
                repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration))
                mockWindowDecoration
            )
        )
        // Resize width to 120px, height to disallowed area which should not result in a change.
        newX += 10
        newY = DISALLOWED_RESIZE_AREA.top.toFloat()
        delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)
        assertTrue(DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        assertTrue(
            DragPositioningCallbackUtility.changeBounds(
                CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
                repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration))
                mockWindowDecoration
            )
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
        assertThat(repositionTaskBounds.right).isEqualTo(STARTING_BOUNDS.right + 20)
        assertThat(repositionTaskBounds.bottom).isEqualTo(STARTING_BOUNDS.bottom + 10)
        assertThat(repositionTaskBounds.bottom).isEqualTo(STABLE_BOUNDS.bottom)
    }


    @Test
    fun testChangeBounds_beyondStableBounds_freezesAtStableBounds() {
        val startingPoint = PointF(
            STARTING_BOUNDS.right.toFloat(),
            STARTING_BOUNDS.bottom.toFloat()
        )
        val repositionTaskBounds = Rect(STARTING_BOUNDS)

        // Resize to beyond stable bounds.
        val newX = STARTING_BOUNDS.right.toFloat() + STABLE_BOUNDS.width()
        val newY = STARTING_BOUNDS.bottom.toFloat() + STABLE_BOUNDS.height()

        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)
        assertTrue(
            DragPositioningCallbackUtility.changeBounds(
                CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
                repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
                mockWindowDecoration
            )
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
        assertThat(repositionTaskBounds.right).isEqualTo(STABLE_BOUNDS.right)
        assertThat(repositionTaskBounds.bottom).isEqualTo(STABLE_BOUNDS.bottom)
    }

    @Test
@@ -277,9 +330,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.bottom.toFloat() - 99
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
        assertThat(repositionTaskBounds.right).isEqualTo(STARTING_BOUNDS.right)
@@ -300,9 +355,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.bottom.toFloat() - 80
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
        assertThat(repositionTaskBounds.right).isEqualTo(STARTING_BOUNDS.right - 80)
@@ -321,9 +378,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.bottom.toFloat() - 99
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
        assertThat(repositionTaskBounds.right).isEqualTo(STARTING_BOUNDS.right)
@@ -342,9 +401,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STARTING_BOUNDS.bottom.toFloat() - 50
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
            repositionTaskBounds, STARTING_BOUNDS, STABLE_BOUNDS, delta, mockDisplayController,
            mockWindowDecoration)
            mockWindowDecoration
        )
        assertThat(repositionTaskBounds.left).isEqualTo(STARTING_BOUNDS.left)
        assertThat(repositionTaskBounds.top).isEqualTo(STARTING_BOUNDS.top)
        assertThat(repositionTaskBounds.right).isEqualTo(STARTING_BOUNDS.right - 50)
@@ -355,8 +416,10 @@ class DragPositioningCallbackUtilityTest {
    @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_SIZE_CONSTRAINTS)
    fun testChangeBounds_windowSizeExceedsStableBounds_shouldBeAllowedToChangeBounds() {
        val startingPoint =
            PointF(OFF_CENTER_STARTING_BOUNDS.right.toFloat(),
                OFF_CENTER_STARTING_BOUNDS.bottom.toFloat())
            PointF(
                OFF_CENTER_STARTING_BOUNDS.right.toFloat(),
                OFF_CENTER_STARTING_BOUNDS.bottom.toFloat()
            )
        val repositionTaskBounds = Rect(OFF_CENTER_STARTING_BOUNDS)
        // Increase height and width by STABLE_BOUNDS. Subtract by 5px so that it doesn't reach
        // the disallowed drag area.
@@ -365,9 +428,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STABLE_BOUNDS.bottom.toFloat() - offset
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
            repositionTaskBounds, OFF_CENTER_STARTING_BOUNDS, STABLE_BOUNDS, delta,
            mockDisplayController, mockWindowDecoration)
            mockDisplayController, mockWindowDecoration
        )
        assertThat(repositionTaskBounds.width()).isGreaterThan(STABLE_BOUNDS.right)
        assertThat(repositionTaskBounds.height()).isGreaterThan(STABLE_BOUNDS.bottom)
    }
@@ -377,8 +442,10 @@ class DragPositioningCallbackUtilityTest {
    fun testChangeBoundsInDesktopMode_windowSizeExceedsStableBounds_shouldBeLimitedToDisplaySize() {
        doReturn(true).`when` { DesktopModeStatus.canEnterDesktopMode(mockContext) }
        val startingPoint =
            PointF(OFF_CENTER_STARTING_BOUNDS.right.toFloat(),
                OFF_CENTER_STARTING_BOUNDS.bottom.toFloat())
            PointF(
                OFF_CENTER_STARTING_BOUNDS.right.toFloat(),
                OFF_CENTER_STARTING_BOUNDS.bottom.toFloat()
            )
        val repositionTaskBounds = Rect(OFF_CENTER_STARTING_BOUNDS)
        // Increase height and width by STABLE_BOUNDS. Subtract by 5px so that it doesn't reach
        // the disallowed drag area.
@@ -387,9 +454,11 @@ class DragPositioningCallbackUtilityTest {
        val newY = STABLE_BOUNDS.bottom.toFloat() - offset
        val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint)

        DragPositioningCallbackUtility.changeBounds(CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
        DragPositioningCallbackUtility.changeBounds(
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM,
            repositionTaskBounds, OFF_CENTER_STARTING_BOUNDS, STABLE_BOUNDS, delta,
            mockDisplayController, mockWindowDecoration)
            mockDisplayController, mockWindowDecoration
        )
        assertThat(repositionTaskBounds.width()).isLessThan(STABLE_BOUNDS.right)
        assertThat(repositionTaskBounds.height()).isLessThan(STABLE_BOUNDS.bottom)
    }
@@ -423,7 +492,8 @@ class DragPositioningCallbackUtilityTest {
            DISPLAY_BOUNDS.left,
            DISPLAY_BOUNDS.bottom - NAVBAR_HEIGHT,
            DISPLAY_BOUNDS.right,
            DISPLAY_BOUNDS.bottom)
            DISPLAY_BOUNDS.bottom
        )
        private val STABLE_BOUNDS = Rect(
            DISPLAY_BOUNDS.left,
            DISPLAY_BOUNDS.top,
+3 −2
Original line number Diff line number Diff line
@@ -678,6 +678,7 @@ class FluidResizeTaskPositionerTest : ShellTestCase() {
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM)
        val rectAfterDrag = Rect(STARTING_BOUNDS)
        rectAfterDrag.right += 2000
        rectAfterDrag.bottom = STABLE_BOUNDS_LANDSCAPE.bottom
        // First drag; we should fetch stable bounds.
        verify(mockDisplayLayout, Mockito.times(1)).getStableBounds(any())
        verify(mockShellTaskOrganizer).applyTransaction(argThat { wct ->
@@ -705,8 +706,8 @@ class FluidResizeTaskPositionerTest : ShellTestCase() {
            STARTING_BOUNDS.right.toFloat(), STARTING_BOUNDS.bottom.toFloat(),
            STARTING_BOUNDS.right.toFloat() + 2000, STARTING_BOUNDS.bottom.toFloat() + 2000,
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM)
        rectAfterDrag.right -= 2000
        rectAfterDrag.bottom += 2000
        rectAfterDrag.right = STABLE_BOUNDS_PORTRAIT.right
        rectAfterDrag.bottom = STARTING_BOUNDS.bottom + 2000

        verify(mockShellTaskOrganizer).applyTransaction(argThat { wct ->
            return@argThat wct.changes.any { (token, change) ->
+3 −2
Original line number Diff line number Diff line
@@ -372,6 +372,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM)
        val rectAfterDrag = Rect(STARTING_BOUNDS)
        rectAfterDrag.right += 2000
        rectAfterDrag.bottom = STABLE_BOUNDS_LANDSCAPE.bottom
        // First drag; we should fetch stable bounds.
        verify(mockDisplayLayout, times(1)).getStableBounds(any())
        verify(mockTransitions).startTransition(eq(TRANSIT_CHANGE), argThat { wct ->
@@ -396,8 +397,8 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() {
        performDrag(STARTING_BOUNDS.right.toFloat(), STARTING_BOUNDS.bottom.toFloat(),
            STARTING_BOUNDS.right.toFloat() + 2000, STARTING_BOUNDS.bottom.toFloat() + 2000,
            CTRL_TYPE_RIGHT or CTRL_TYPE_BOTTOM)
        rectAfterDrag.right -= 2000
        rectAfterDrag.bottom += 2000
        rectAfterDrag.right = STABLE_BOUNDS_PORTRAIT.right
        rectAfterDrag.bottom = STARTING_BOUNDS.bottom + 2000

        verify(mockTransitions).startTransition(eq(TRANSIT_CHANGE), argThat { wct ->
            return@argThat wct.changes.any { (token, change) ->