diff options
author | 2024-09-16 05:17:46 +0000 | |
---|---|---|
committer | 2024-09-16 05:17:46 +0000 | |
commit | 32f087ff2bb97556f0cffa4da46f7c78f1d97f56 (patch) | |
tree | 39df0b82e493dd5e984cbc61e4e35e6acc33e094 | |
parent | edc125e3d947dfe74e90dc0b8d3be7a0408d0260 (diff) | |
parent | b8cc0a3c11727d002488a9c15a9b4dfd2f4316bc (diff) |
Merge "Maintain aspect ratio in DragPositioningCallbackUtility.changeBounds()" into main
4 files changed, 124 insertions, 0 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java index cb9781e86c87..cad34621c82a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java @@ -84,22 +84,47 @@ public class DragPositioningCallbackUtility { repositionTaskBounds.set(taskBoundsAtDragStart); + boolean isAspectRatioMaintained = true; // Make sure the new resizing destination in any direction falls within the stable bounds. if ((ctrlType & CTRL_TYPE_LEFT) != 0) { repositionTaskBounds.left = Math.max(repositionTaskBounds.left + (int) delta.x, stableBounds.left); + if (repositionTaskBounds.left == stableBounds.left + && repositionTaskBounds.left + (int) delta.x != stableBounds.left) { + // If the task edge have been set to the stable bounds and not due to the users + // drag, the aspect ratio of the task will not be maintained. + isAspectRatioMaintained = false; + } } if ((ctrlType & CTRL_TYPE_RIGHT) != 0) { repositionTaskBounds.right = Math.min(repositionTaskBounds.right + (int) delta.x, stableBounds.right); + if (repositionTaskBounds.right == stableBounds.right + && repositionTaskBounds.right + (int) delta.x != stableBounds.right) { + // If the task edge have been set to the stable bounds and not due to the users + // drag, the aspect ratio of the task will not be maintained. + isAspectRatioMaintained = false; + } } if ((ctrlType & CTRL_TYPE_TOP) != 0) { repositionTaskBounds.top = Math.max(repositionTaskBounds.top + (int) delta.y, stableBounds.top); + if (repositionTaskBounds.top == stableBounds.top + && repositionTaskBounds.top + (int) delta.y != stableBounds.top) { + // If the task edge have been set to the stable bounds and not due to the users + // drag, the aspect ratio of the task will not be maintained. + isAspectRatioMaintained = false; + } } if ((ctrlType & CTRL_TYPE_BOTTOM) != 0) { repositionTaskBounds.bottom = Math.min(repositionTaskBounds.bottom + (int) delta.y, stableBounds.bottom); + if (repositionTaskBounds.bottom == stableBounds.bottom + && repositionTaskBounds.bottom + (int) delta.y != stableBounds.bottom) { + // If the task edge have been set to the stable bounds and not due to the users + // drag, the aspect ratio of the task will not be maintained. + isAspectRatioMaintained = false; + } } // If width or height are negative or exceeding the width or height constraints, revert the @@ -108,11 +133,24 @@ public class DragPositioningCallbackUtility { windowDecoration)) { repositionTaskBounds.right = oldRight; repositionTaskBounds.left = oldLeft; + isAspectRatioMaintained = false; } if (isExceedingHeightConstraint(repositionTaskBounds, stableBounds, displayController, windowDecoration)) { repositionTaskBounds.top = oldTop; repositionTaskBounds.bottom = oldBottom; + isAspectRatioMaintained = false; + } + + // If the application is unresizeable and any bounds have been set back to their old + // location or to a stable bound edge, reset all the bounds to maintain the applications + // aspect ratio. + if (DesktopModeFlags.SCALED_RESIZING.isEnabled(windowDecoration.mDecorWindowContext) + && !isAspectRatioMaintained && !windowDecoration.mTaskInfo.isResizeable) { + repositionTaskBounds.top = oldTop; + repositionTaskBounds.bottom = oldBottom; + repositionTaskBounds.right = oldRight; + repositionTaskBounds.left = oldLeft; } // If there are no changes to the bounds after checking new bounds against minimum and diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtilityTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtilityTest.kt index 1f33ae69b724..24f6becc3536 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtilityTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtilityTest.kt @@ -39,6 +39,7 @@ import com.android.wm.shell.windowdecor.DragPositioningCallback.CTRL_TYPE_BOTTOM import com.android.wm.shell.windowdecor.DragPositioningCallback.CTRL_TYPE_RIGHT import com.android.wm.shell.windowdecor.DragPositioningCallback.CTRL_TYPE_TOP import com.google.common.truth.Truth.assertThat +import junit.framework.Assert.assertFalse import junit.framework.Assert.assertTrue import org.junit.After import org.junit.Before @@ -105,6 +106,7 @@ class DragPositioningCallbackUtilityTest { initializeTaskInfo() mockWindowDecoration.mDisplay = mockDisplay mockWindowDecoration.mDecorWindowContext = mockContext + mockWindowDecoration.mTaskInfo.isResizeable = true whenever(mockContext.getResources()).thenReturn(mockResources) whenever(mockWindowDecoration.mDecorWindowContext.resources).thenReturn(mockResources) whenever(mockResources.getDimensionPixelSize(R.dimen.desktop_mode_minimum_window_width)) @@ -164,6 +166,60 @@ class DragPositioningCallbackUtilityTest { } @Test + @EnableFlags(Flags.FLAG_ENABLE_WINDOWING_SCALED_RESIZING) + fun testChangeBounds_unresizeableApp_heightLessThanMin_resetToStartingBounds() { + mockWindowDecoration.mTaskInfo.isResizeable = false + val startingPoint = PointF(STARTING_BOUNDS.right.toFloat(), STARTING_BOUNDS.top.toFloat()) + val repositionTaskBounds = Rect(STARTING_BOUNDS) + + // Resize to width of 95px and height of 5px with min width of 10px + val newX = STARTING_BOUNDS.right.toFloat() - 5 + val newY = STARTING_BOUNDS.top.toFloat() + 95 + val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint) + + assertFalse( + DragPositioningCallbackUtility.changeBounds( + CTRL_TYPE_RIGHT or CTRL_TYPE_TOP, + 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(STARTING_BOUNDS.right) + assertThat(repositionTaskBounds.bottom).isEqualTo(STARTING_BOUNDS.bottom) + } + + @Test + @EnableFlags(Flags.FLAG_ENABLE_WINDOWING_SCALED_RESIZING) + fun testChangeBounds_unresizeableApp_widthLessThanMin_resetToStartingBounds() { + mockWindowDecoration.mTaskInfo.isResizeable = false + val startingPoint = PointF(STARTING_BOUNDS.right.toFloat(), STARTING_BOUNDS.top.toFloat()) + val repositionTaskBounds = Rect(STARTING_BOUNDS) + + // Resize to height of 95px and width of 5px with min width of 10px + val newX = STARTING_BOUNDS.right.toFloat() - 95 + val newY = STARTING_BOUNDS.top.toFloat() + 5 + val delta = DragPositioningCallbackUtility.calculateDelta(newX, newY, startingPoint) + + assertFalse( + DragPositioningCallbackUtility.changeBounds( + CTRL_TYPE_RIGHT or CTRL_TYPE_TOP, + 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(STARTING_BOUNDS.right) + assertThat(repositionTaskBounds.bottom).isEqualTo(STARTING_BOUNDS.bottom) + } + + + @Test fun testChangeBoundsDoesNotChangeHeightWhenNegative() { val startingPoint = PointF(STARTING_BOUNDS.right.toFloat(), STARTING_BOUNDS.top.toFloat()) val repositionTaskBounds = Rect(STARTING_BOUNDS) @@ -317,6 +373,34 @@ class DragPositioningCallbackUtilityTest { } @Test + @EnableFlags(Flags.FLAG_ENABLE_WINDOWING_SCALED_RESIZING) + fun testChangeBounds_unresizeableApp_beyondStableBounds_resetToStartingBounds() { + mockWindowDecoration.mTaskInfo.isResizeable = false + 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) + assertFalse( + 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(STARTING_BOUNDS.right) + assertThat(repositionTaskBounds.bottom).isEqualTo(STARTING_BOUNDS.bottom) + } + + @Test @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_SIZE_CONSTRAINTS) fun taskMinWidthHeightUndefined_changeBoundsInDesktopModeLessThanMin_shouldNotChangeBounds() { doReturn(true).`when` { DesktopModeStatus.canEnterDesktopMode(mockContext) } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt index 3a3e965b625e..7543fed4b085 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositionerTest.kt @@ -121,6 +121,7 @@ class FluidResizeTaskPositionerTest : ShellTestCase() { displayId = DISPLAY_ID configuration.windowConfiguration.setBounds(STARTING_BOUNDS) configuration.windowConfiguration.displayRotation = ROTATION_90 + isResizeable = true } `when`(mockWindowDecoration.calculateValidDragArea()).thenReturn(VALID_DRAG_AREA) mockWindowDecoration.mDisplay = mockDisplay diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt index 6ae16edaf3df..7784af6b1111 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositionerTest.kt @@ -141,6 +141,7 @@ class VeiledResizeTaskPositionerTest : ShellTestCase() { displayId = DISPLAY_ID configuration.windowConfiguration.setBounds(STARTING_BOUNDS) configuration.windowConfiguration.displayRotation = ROTATION_90 + isResizeable = true } `when`(mockDesktopWindowDecoration.calculateValidDragArea()).thenReturn(VALID_DRAG_AREA) mockDesktopWindowDecoration.mDisplay = mockDisplay |