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

Commit 5286e0c3 authored by Alp Yalcin's avatar Alp Yalcin
Browse files

[2/n] Inherit parent's bounds on tab tearing

When a tab is detached, the new window now inherits the exact dimensions of the parent window (from which it was separated). Previously, the new window would open with a default size.

Flag: com.android.window.flags.enable_interaction_dependent_tab_tearing_bounds
Bug: 421794493
Test: atest WMShellUnitTests:DesktopTasksControllerTest
Change-Id: I59ae22de7c56371762de466e79ee0932a9e745ea
parent 18794f0a
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -5600,6 +5600,13 @@ class DesktopTasksController(
        when (indicatorType) {
            IndicatorType.TO_DESKTOP_INDICATOR,
            IndicatorType.NO_INDICATOR -> {
                if (
                    DesktopExperienceFlags.ENABLE_INTERACTION_DEPENDENT_TAB_TEARING_BOUNDS.isTrue()
                ) {
                    // Inherit parent's bounds.
                    newWindowBounds.set(taskInfo.configuration.windowConfiguration.bounds)
                    // TODO: (b/436504714) - Implement the new positioning logic here.
                } else {
                    // Use default bounds, but with the top-center at the drop point.
                    newWindowBounds.set(calculateDefaultDesktopTaskBounds(displayLayout))
                    newWindowBounds.offsetTo(
@@ -5607,6 +5614,7 @@ class DesktopTasksController(
                        dragEvent.y.toInt(),
                    )
                }
            }
            IndicatorType.TO_SPLIT_RIGHT_INDICATOR -> {
                newWindowBounds.set(getSnapBounds(destinationDisplay, SnapPosition.RIGHT))
            }
+64 −0
Original line number Diff line number Diff line
@@ -9993,6 +9993,70 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            )
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_MINIMIZE_ANIMATION_BUGFIX,
        Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_LAUNCH_ANIMATION,
        Flags.FLAG_ENABLE_INTERACTION_DEPENDENT_TAB_TEARING_BOUNDS,
    )
    fun onUnhandledDrag_newWindowFromTabIntent_tabTearingAnimationBugfixFlagEnabled_tabTearingLaunchAnimationFlagEnabled() {
        testOnUnhandledDrag(
            DesktopModeVisualIndicator.IndicatorType.TO_DESKTOP_INDICATOR,
            PointF(1200f, 700f),
            Rect(100, 100, 300, 300),
            tabTearingMinimizeAnimationFlagEnabled = true,
            tabTearingLaunchAnimationFlagEnabled = true,
        )
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_MINIMIZE_ANIMATION_BUGFIX,
        Flags.FLAG_ENABLE_INTERACTION_DEPENDENT_TAB_TEARING_BOUNDS,
    )
    @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_LAUNCH_ANIMATION)
    fun onUnhandledDrag_newWindowFromTabIntent_tabTearingAnimationBugfixFlagEnabled_tabTearingLaunchAnimationFlagDisabled() {
        testOnUnhandledDrag(
            DesktopModeVisualIndicator.IndicatorType.TO_DESKTOP_INDICATOR,
            PointF(1200f, 700f),
            Rect(100, 100, 300, 300),
            tabTearingMinimizeAnimationFlagEnabled = true,
            tabTearingLaunchAnimationFlagEnabled = false,
        )
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_LAUNCH_ANIMATION,
        Flags.FLAG_ENABLE_INTERACTION_DEPENDENT_TAB_TEARING_BOUNDS,
        )
    @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_MINIMIZE_ANIMATION_BUGFIX)
    fun onUnhandledDrag_newWindowFromTabIntent_tabTearingAnimationBugfixFlagDisabled_tabTearingLaunchAnimationFlagEnabled() {
        testOnUnhandledDrag(
            DesktopModeVisualIndicator.IndicatorType.TO_DESKTOP_INDICATOR,
            PointF(1200f, 700f),
            Rect(100, 100, 300, 300),
            tabTearingMinimizeAnimationFlagEnabled = false,
            tabTearingLaunchAnimationFlagEnabled = true,
        )
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_INTERACTION_DEPENDENT_TAB_TEARING_BOUNDS)
    @DisableFlags(
        Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_MINIMIZE_ANIMATION_BUGFIX,
        Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_LAUNCH_ANIMATION,
    )
    fun onUnhandledDrag_newWindowFromTabIntent_tabTearingAnimationBugfixFlagDisabled_tabTearingLaunchAnimationFlagDisabled() {
        testOnUnhandledDrag(
            DesktopModeVisualIndicator.IndicatorType.TO_DESKTOP_INDICATOR,
            PointF(1200f, 700f),
            Rect(100, 100, 300, 300),
            tabTearingMinimizeAnimationFlagEnabled = false,
            tabTearingLaunchAnimationFlagEnabled = false,
        )
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_TAB_TEARING_MINIMIZE_ANIMATION_BUGFIX,
+27 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ import java.util.concurrent.atomic.AtomicInteger;
 * The class that defines default launch params for tasks in desktop mode
 */
class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
    private static final String ACTION_DRAG_DROP_VIEW =
            "org.chromium.chrome.browser.dragdrop.action.VIEW";
    private StringBuilder mLogBuilder;

    @NonNull
@@ -233,6 +235,10 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
                // ignore the source windowing mode and set the windowing mode to freeform.
                outParams.mWindowingMode = WINDOWING_MODE_FREEFORM;
                appendLog("freeform window mode applied to task trampoline");
                if (persisitSourceBoundsForTabTearingTrampoline(source, activity)) {
                    outParams.mBounds.set(sourceTask.getBounds());
                    return RESULT_DONE;
                }
            } else {
                // In Proto2, trampoline task launches of an existing background task can result in
                // the previous windowing mode to be restored even if the desktop mode state has
@@ -479,6 +485,27 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
                && isClosingExitingInstance(launchingTask.getBaseIntent().getFlags());
    }

    /**
     * Returns true if the bounds should be persisted from the source activity for
     * tab tearing trampoline launches.
     */
    private boolean persisitSourceBoundsForTabTearingTrampoline(
            @NonNull ActivityRecord source,
            @Nullable ActivityRecord activity) {
        return DesktopExperienceFlags.ENABLE_INTERACTION_DEPENDENT_TAB_TEARING_BOUNDS.isTrue()
                && activity != null
                && source.isNoDisplay()
                && source.packageName.equals(activity.packageName)
                && isChromiumDragAndDropAction(activity);
    }

    /**
     * Returns true if the given activity action is a chromium drag and drop.
     */
    private boolean isChromiumDragAndDropAction(@NonNull ActivityRecord activity) {
        return ACTION_DRAG_DROP_VIEW.equals(activity.intent.getAction());
    }

    /**
     * Returns true if the launch mode will result in a single new task being created for the
     * activity.