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

Commit a1200911 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix PiP being out of bounds when launched into forced orientation"

parents 2fe57526 47f2bf60
Loading
Loading
Loading
Loading
+29 −24
Original line number Diff line number Diff line
@@ -230,32 +230,37 @@ class PinnedStackController {
    }

    /**
     * @param preChangeTargetBounds The final bounds of the stack if it is currently animating
     * @return the repositioned PIP bounds given it's pre-change bounds, and the new display
     *         content.
     * Updates the display info, calculating and returning the new stack and movement bounds in the
     * new orientation of the device if necessary.
     */
    Rect onDisplayChanged(Rect preChangeStackBounds, Rect preChangeTargetBounds,
            DisplayContent displayContent) {
        final Rect postChangeStackBounds = new Rect(preChangeTargetBounds);
        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
        if (!mDisplayInfo.equals(displayInfo)) {
            // Calculate the snap fraction of the current stack along the old movement bounds, and
            // then update the stack bounds to the same fraction along the rotated movement bounds.
            final Rect preChangeMovementBounds = getMovementBounds(preChangeStackBounds);
            final float snapFraction = mSnapAlgorithm.getSnapFraction(preChangeStackBounds,
    void onTaskStackBoundsChanged(Rect targetBounds, Rect outBounds) {
        final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
        if (mDisplayInfo.equals(displayInfo)) {
            return;
        }

        mTmpRect.set(targetBounds);
        final Rect postChangeStackBounds = mTmpRect;

        // Calculate the snap fraction of the current stack along the old movement bounds
        final Rect preChangeMovementBounds = getMovementBounds(postChangeStackBounds);
        final float snapFraction = mSnapAlgorithm.getSnapFraction(postChangeStackBounds,
                preChangeMovementBounds);
        mDisplayInfo.copyFrom(displayInfo);

            final Rect postChangeMovementBounds = getMovementBounds(preChangeStackBounds,
        // Calculate the stack bounds in the new orientation to the same same fraction along the
        // rotated movement bounds.
        final Rect postChangeMovementBounds = getMovementBounds(postChangeStackBounds,
                false /* adjustForIme */);
        mSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
                snapFraction);
        if (mIsMinimized) {
            applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds);
        }

        notifyMovementBoundsChanged(false /* fromImeAdjustment */);
        }
        return postChangeStackBounds;

        outBounds.set(postChangeStackBounds);
    }

    /**
+15 −16
Original line number Diff line number Diff line
@@ -262,6 +262,12 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye

        if (mDisplayContent != null) {
            mDisplayContent.mDimLayerController.updateDimLayer(this);
            if (mStackId == PINNED_STACK_ID) {
                // Update the bounds based on any changes to the display info
                getAnimatingBounds(mTmpRect2);
                mDisplayContent.mPinnedStackControllerLocked.onTaskStackBoundsChanged(mTmpRect2,
                        bounds);
            }
            mAnimationBackgroundSurface.setBounds(bounds);
        }

@@ -391,15 +397,18 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
            return false;
        }

        if (StackId.tasksAreFloating(mStackId)) {
            // Update stack bounds again since the display info has changed since updateDisplayInfo,
            // however, for floating tasks, we don't need to apply the new rotation to the bounds,
            // we can just update and return them here
            setBounds(mBounds);
            mBoundsAfterRotation.set(mBounds);
            return true;
        }

        mTmpRect2.set(mBounds);
        mDisplayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
        switch (mStackId) {
            case PINNED_STACK_ID:
                Rect targetBounds = new Rect();
                getAnimatingBounds(targetBounds);
                mTmpRect2 = mDisplayContent.getPinnedStackController().onDisplayChanged(mBounds,
                        targetBounds, mDisplayContent);
                break;
            case DOCKED_STACK_ID:
                repositionDockedStackAfterRotation(mTmpRect2);
                snapDockedStackAfterRotation(mTmpRect2);
@@ -651,7 +660,6 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
        mAnimationBackgroundSurface = new DimLayer(mService, this, mDisplayContent.getDisplayId(),
                "animation background stackId=" + mStackId);

        final Rect oldBounds = new Rect(mBounds);
        Rect bounds = null;
        final TaskStack dockedStack = dc.getDockedStackIgnoringVisibility();
        if (mStackId == DOCKED_STACK_ID
@@ -675,15 +683,6 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
        }

        updateDisplayInfo(bounds);

        // Update the pinned stack controller after the display info is updated
        if (mStackId == PINNED_STACK_ID) {
            Rect targetBounds = new Rect();
            getAnimatingBounds(targetBounds);
            mDisplayContent.getPinnedStackController().onDisplayChanged(oldBounds, targetBounds,
                    mDisplayContent);
        }

        super.onDisplayChanged(dc);
    }