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

Commit 22360845 authored by Yao Qijing's avatar Yao Qijing Committed by Qijing Yao
Browse files

Add displayId to DragPositioningCallback

Adds a `displayId` parameter to `DragPositioningCallback` methods
(`onDragPositioningStart`, `onDragPositioningMove`, `onDragPositioningEnd`).

This allows the callback to be aware of the display on which the drag
operation is occurring, which is necessary for multi-display window dragging.

Bug: 381172757
Test: run unit tests for related classes
Flag: EXEMPT no functional change
Change-Id: I3308968211c727e5c26d47d1335375e9bcbe0e86
parent 0dc2c494
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -468,7 +468,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel, FocusT
                case MotionEvent.ACTION_DOWN: {
                    mDragPointerId = e.getPointerId(0);
                    mDragPositioningCallback.onDragPositioningStart(
                            0 /* ctrlType */, e.getRawX(0), e.getRawY(0));
                            0 /* ctrlType */, e.getDisplayId(), e.getRawX(0), e.getRawY(0));
                    mIsDragging = false;
                    return false;
                }
@@ -481,6 +481,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel, FocusT
                    if (decoration.isHandlingDragResize()) break;
                    final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
                    mDragPositioningCallback.onDragPositioningMove(
                            e.getDisplayId(),
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    mIsDragging = true;
                    return true;
@@ -492,6 +493,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel, FocusT
                    }
                    final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
                    final Rect newTaskBounds = mDragPositioningCallback.onDragPositioningEnd(
                            e.getDisplayId(),
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    DragPositioningCallbackUtility.snapTaskBoundsIfNecessary(newTaskBounds,
                            mWindowDecorByTaskId.get(mTaskId).calculateValidDragArea());
+3 −1
Original line number Diff line number Diff line
@@ -1121,7 +1121,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                    if (dragAllowed) {
                        mDragPointerId = e.getPointerId(0);
                        final Rect initialBounds = mDragPositioningCallback.onDragPositioningStart(
                                0 /* ctrlType */, e.getRawX(0),
                                0 /* ctrlType */, e.getDisplayId(), e.getRawX(0),
                                e.getRawY(0));
                        updateDragStatus(e.getActionMasked());
                        mOnDragStartInitialBounds.set(initialBounds);
@@ -1142,6 +1142,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                    }
                    final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
                    final Rect newTaskBounds = mDragPositioningCallback.onDragPositioningMove(
                            e.getDisplayId(),
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    mDesktopTasksController.onDragPositioningMove(taskInfo,
                            decoration.mTaskSurface,
@@ -1172,6 +1173,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                            (int) (e.getRawX(dragPointerIdx) - e.getX(dragPointerIdx)),
                            (int) (e.getRawY(dragPointerIdx) - e.getY(dragPointerIdx)));
                    final Rect newTaskBounds = mDragPositioningCallback.onDragPositioningEnd(
                            e.getDisplayId(),
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    // Tasks bounds haven't actually been updated (only its leash), so pass to
                    // DesktopTasksController to allow secondary transformations (i.e. snap resizing
+8 −3
Original line number Diff line number Diff line
@@ -41,25 +41,30 @@ public interface DragPositioningCallback {
     *
     * @param ctrlType {@link CtrlType} indicating the direction of resizing, use
     *                 {@code 0} to indicate it's a move
     * @param displayId the ID of the display where the drag starts
     * @param x x coordinate in window decoration coordinate system where the drag starts
     * @param y y coordinate in window decoration coordinate system where the drag starts
     * @return the starting task bounds
     */
    Rect onDragPositioningStart(@CtrlType int ctrlType, float x, float y);
    Rect onDragPositioningStart(@CtrlType int ctrlType, int displayId, float x, float y);

    /**
     * Called when the pointer moves during a drag-resize or drag-move.
     *
     * @param displayId the ID of the display where the pointer is currently located
     * @param x x coordinate in window decoration coordinate system of the new pointer location
     * @param y y coordinate in window decoration coordinate system of the new pointer location
     * @return the updated task bounds
     */
    Rect onDragPositioningMove(float x, float y);
    Rect onDragPositioningMove(int displayId, float x, float y);

    /**
     * Called when a drag-resize or drag-move stops.
     *
     * @param displayId the ID of the display where the pointer is located when drag stops
     * @param x x coordinate in window decoration coordinate system where the drag resize stops
     * @param y y coordinate in window decoration coordinate system where the drag resize stops
     * @return the final bounds for the dragged task
     */
    Rect onDragPositioningEnd(float x, float y);
    Rect onDragPositioningEnd(int displayId, float x, float y);
}
+4 −3
Original line number Diff line number Diff line
@@ -454,7 +454,7 @@ class DragResizeInputListener implements AutoCloseable {
                        ProtoLog.d(WM_SHELL_DESKTOP_MODE,
                                "%s: Handling action down, update ctrlType to %d", TAG, ctrlType);
                        mDragStartTaskBounds = mCallback.onDragPositioningStart(ctrlType,
                                rawX, rawY);
                                e.getDisplayId(), rawX, rawY);
                        mLastMotionEventOnDown = e;
                        mResizeTrigger = (ctrlType == CTRL_TYPE_BOTTOM || ctrlType == CTRL_TYPE_TOP
                                || ctrlType == CTRL_TYPE_RIGHT || ctrlType == CTRL_TYPE_LEFT)
@@ -489,7 +489,8 @@ class DragResizeInputListener implements AutoCloseable {
                    }
                    final float rawX = e.getRawX(dragPointerIndex);
                    final float rawY = e.getRawY(dragPointerIndex);
                    final Rect taskBounds = mCallback.onDragPositioningMove(rawX, rawY);
                    final Rect taskBounds = mCallback.onDragPositioningMove(e.getDisplayId(),
                            rawX, rawY);
                    updateInputSinkRegionForDrag(taskBounds);
                    result = true;
                    break;
@@ -505,7 +506,7 @@ class DragResizeInputListener implements AutoCloseable {
                                    TAG, e.getActionMasked());
                            break;
                        }
                        final Rect taskBounds = mCallback.onDragPositioningEnd(
                        final Rect taskBounds = mCallback.onDragPositioningEnd(e.getDisplayId(),
                                e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex));
                        // If taskBounds has changed, setGeometry will be called and update the
                        // sink region. Otherwise, we should revert it here.
+27 −26
Original line number Diff line number Diff line
@@ -47,10 +47,11 @@ class FixedAspectRatioTaskPositionerDecorator (
    private var startingAspectRatio = 0f
    private var isTaskPortrait = false

    override fun onDragPositioningStart(@CtrlType ctrlType: Int, x: Float, y: Float): Rect {
    override fun onDragPositioningStart(
        @CtrlType ctrlType: Int, displayId: Int, x: Float, y: Float): Rect {
        originalCtrlType = ctrlType
        if (!requiresFixedAspectRatio()) {
            return super.onDragPositioningStart(originalCtrlType, x, y)
            return super.onDragPositioningStart(originalCtrlType, displayId, x, y)
        }

        lastRepositionedBounds.set(getBounds(windowDecoration.mTaskInfo))
@@ -72,27 +73,27 @@ class FixedAspectRatioTaskPositionerDecorator (
                    val verticalMidPoint = lastRepositionedBounds.top + (startingBoundHeight / 2)
                    edgeResizeCtrlType = originalCtrlType +
                            if (y < verticalMidPoint) CTRL_TYPE_TOP else CTRL_TYPE_BOTTOM
                    super.onDragPositioningStart(edgeResizeCtrlType, x, y)
                    super.onDragPositioningStart(edgeResizeCtrlType, displayId, x, y)
                }
                CTRL_TYPE_TOP, CTRL_TYPE_BOTTOM -> {
                    val horizontalMidPoint = lastRepositionedBounds.left + (startingBoundWidth / 2)
                    edgeResizeCtrlType = originalCtrlType +
                            if (x < horizontalMidPoint) CTRL_TYPE_LEFT else CTRL_TYPE_RIGHT
                    super.onDragPositioningStart(edgeResizeCtrlType, x, y)
                    super.onDragPositioningStart(edgeResizeCtrlType, displayId, x, y)
                }
                // If resize is corner resize, no alteration to the ctrlType needs to be made.
                else -> {
                    edgeResizeCtrlType = CTRL_TYPE_UNDEFINED
                    super.onDragPositioningStart(originalCtrlType, x, y)
                    super.onDragPositioningStart(originalCtrlType, displayId, x, y)
                }
            }
        )
        return lastRepositionedBounds
    }

    override fun onDragPositioningMove(x: Float, y: Float): Rect {
    override fun onDragPositioningMove(displayId: Int, x: Float, y: Float): Rect {
        if (!requiresFixedAspectRatio()) {
            return super.onDragPositioningMove(x, y)
            return super.onDragPositioningMove(displayId, x, y)
        }

        val diffX = x - lastValidPoint.x
@@ -103,7 +104,7 @@ class FixedAspectRatioTaskPositionerDecorator (
                    // Drag coordinate falls within valid region (90 - 180 degrees or 270- 360
                    // degrees from the corner the previous valid point). Allow resize with adjusted
                    // coordinates to maintain aspect ratio.
                    lastRepositionedBounds.set(dragAdjustedMove(x, y))
                    lastRepositionedBounds.set(dragAdjustedMove(displayId, x, y))
                }
            }
            CTRL_TYPE_BOTTOM + CTRL_TYPE_LEFT, CTRL_TYPE_TOP + CTRL_TYPE_RIGHT -> {
@@ -111,28 +112,28 @@ class FixedAspectRatioTaskPositionerDecorator (
                    // Drag coordinate falls within valid region (180 - 270 degrees or 0 - 90
                    // degrees from the corner the previous valid point). Allow resize with adjusted
                    // coordinates to maintain aspect ratio.
                    lastRepositionedBounds.set(dragAdjustedMove(x, y))
                    lastRepositionedBounds.set(dragAdjustedMove(displayId, x, y))
                }
            }
            CTRL_TYPE_LEFT, CTRL_TYPE_RIGHT -> {
                // If resize is on left or right edge, always adjust the y coordinate.
                val adjustedY = getScaledChangeForY(x)
                lastValidPoint.set(x, adjustedY)
                lastRepositionedBounds.set(super.onDragPositioningMove(x, adjustedY))
                lastRepositionedBounds.set(super.onDragPositioningMove(displayId, x, adjustedY))
            }
            CTRL_TYPE_TOP, CTRL_TYPE_BOTTOM -> {
                // If resize is on top or bottom edge, always adjust the x coordinate.
                val adjustedX = getScaledChangeForX(y)
                lastValidPoint.set(adjustedX, y)
                lastRepositionedBounds.set(super.onDragPositioningMove(adjustedX, y))
                lastRepositionedBounds.set(super.onDragPositioningMove(displayId, adjustedX, y))
            }
        }
        return lastRepositionedBounds
    }

    override fun onDragPositioningEnd(x: Float, y: Float): Rect {
    override fun onDragPositioningEnd(displayId: Int, x: Float, y: Float): Rect {
        if (!requiresFixedAspectRatio()) {
            return super.onDragPositioningEnd(x, y)
            return super.onDragPositioningEnd(displayId, x, y)
        }

        val diffX = x - lastValidPoint.x
@@ -144,55 +145,55 @@ class FixedAspectRatioTaskPositionerDecorator (
                    // Drag coordinate falls within valid region (90 - 180 degrees or 270- 360
                    // degrees from the corner the previous valid point). End resize with adjusted
                    // coordinates to maintain aspect ratio.
                    return dragAdjustedEnd(x, y)
                    return dragAdjustedEnd(displayId, x, y)
                }
                // If end of resize is not within valid region, end resize from last valid
                // coordinates.
                return super.onDragPositioningEnd(lastValidPoint.x, lastValidPoint.y)
                return super.onDragPositioningEnd(displayId, lastValidPoint.x, lastValidPoint.y)
            }
            CTRL_TYPE_BOTTOM + CTRL_TYPE_LEFT, CTRL_TYPE_TOP + CTRL_TYPE_RIGHT -> {
                if ((diffX > 0 && diffY < 0) || (diffX < 0 && diffY > 0)) {
                    // Drag coordinate falls within valid region (180 - 260 degrees or 0 - 90
                    // degrees from the corner the previous valid point). End resize with adjusted
                    // coordinates to maintain aspect ratio.
                    return dragAdjustedEnd(x, y)
                    return dragAdjustedEnd(displayId, x, y)
                }
                // If end of resize is not within valid region, end resize from last valid
                // coordinates.
                return super.onDragPositioningEnd(lastValidPoint.x, lastValidPoint.y)
                return super.onDragPositioningEnd(displayId, lastValidPoint.x, lastValidPoint.y)
            }
            CTRL_TYPE_LEFT, CTRL_TYPE_RIGHT -> {
                // If resize is on left or right edge, always adjust the y coordinate.
                return super.onDragPositioningEnd(x, getScaledChangeForY(x))
                return super.onDragPositioningEnd(displayId, x, getScaledChangeForY(x))
            }
            CTRL_TYPE_TOP, CTRL_TYPE_BOTTOM -> {
                // If resize is on top or bottom edge, always adjust the x coordinate.
                return super.onDragPositioningEnd(getScaledChangeForX(y), y)
                return super.onDragPositioningEnd(displayId, getScaledChangeForX(y), y)
            }
            else -> {
                return super.onDragPositioningEnd(x, y)
                return super.onDragPositioningEnd(displayId, x, y)
            }
        }
    }

    private fun dragAdjustedMove(x: Float, y: Float): Rect {
    private fun dragAdjustedMove(displayId: Int, x: Float, y: Float): Rect {
        val absDiffX = abs(x - lastValidPoint.x)
        val absDiffY = abs(y - lastValidPoint.y)
        if (absDiffY < absDiffX) {
            lastValidPoint.set(getScaledChangeForX(y), y)
            return super.onDragPositioningMove(getScaledChangeForX(y), y)
            return super.onDragPositioningMove(displayId, getScaledChangeForX(y), y)
        }
        lastValidPoint.set(x, getScaledChangeForY(x))
        return super.onDragPositioningMove(x, getScaledChangeForY(x))
        return super.onDragPositioningMove(displayId, x, getScaledChangeForY(x))
    }

    private fun dragAdjustedEnd(x: Float, y: Float): Rect {
    private fun dragAdjustedEnd(displayId: Int, x: Float, y: Float): Rect {
        val absDiffX = abs(x - lastValidPoint.x)
        val absDiffY = abs(y - lastValidPoint.y)
        if (absDiffY < absDiffX) {
            return super.onDragPositioningEnd(getScaledChangeForX(y), y)
            return super.onDragPositioningEnd(displayId, getScaledChangeForX(y), y)
        }
        return super.onDragPositioningEnd(x, getScaledChangeForY(x))
        return super.onDragPositioningEnd(displayId, x, getScaledChangeForY(x))
    }

    /**
Loading