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

Commit f6e801da authored by Robert Carr's avatar Robert Carr
Browse files

PopupWindow. Don't use -1 width/height for calculations.

In findDropDownPosition it's entirely possible for width/height
to be -1. If this is so, and the popup is anchored to the right,
we could fail to see that it is offscreen (since we think the width
is -1), and so fail to do our position adjustment to move it to the
left. I think this was previously covered up by window manager bugs
with child windows that requested coordinates outside of their
parent frame. To fix this, we ontinue to pass the same value to
the window manager, but use the width/height we expect to receive
for local layout calculations.

Bug: 28085451
Change-Id: Ia04ca3fcd17ad8819615b5ff42f7923462ce4b42
parent 4b925948
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -1514,6 +1514,24 @@ public class PopupWindow {
        outParams.x = drawingLocation[0] + xOffset;
        outParams.y = drawingLocation[1] + anchorHeight + yOffset;

        // Let the window manager know to align the top to y.
        outParams.gravity = Gravity.LEFT | Gravity.TOP;
        outParams.width = width;
        outParams.height = height;

        // If width or height is unspecified. We can leave it to the window manager to match
        // to the parent size, but for our local purposes of calculating positioning, we need
        // to fill in real width and height values.
        final Rect displayFrame = new Rect();
        anchor.getWindowVisibleDisplayFrame(displayFrame);
        if (width < 0) {
            width = displayFrame.right - displayFrame.left;
        }
        if (height < 0) {
            height = displayFrame.bottom - displayFrame.top;
        }


        // If we need to adjust for gravity RIGHT, align to the bottom-right
        // corner of the anchor (still accounting for offsets).
        final int hgrav = Gravity.getAbsoluteGravity(gravity, anchor.getLayoutDirection())
@@ -1522,17 +1540,9 @@ public class PopupWindow {
            outParams.x -= width - anchorWidth;
        }

        // Let the window manager know to align the top to y.
        outParams.gravity = Gravity.LEFT | Gravity.TOP;
        outParams.width = width;
        outParams.height = height;

        final int[] screenLocation = mTmpScreenLocation;
        anchor.getLocationOnScreen(screenLocation);

        final Rect displayFrame = new Rect();
        anchor.getWindowVisibleDisplayFrame(displayFrame);

        // First, attempt to fit the popup vertically without resizing.
        final boolean fitsVertical = tryFitVertical(outParams, yOffset, height,
                anchorHeight, drawingLocation[1], screenLocation[1], displayFrame.top,
@@ -2116,10 +2126,10 @@ public class PopupWindow {

        // If an explicit width/height has not specified, use the most recent
        // explicitly specified value (either from setWidth/Height or update).
        if (width == -1) {
        if (width < 0) {
            width = mWidth;
        }
        if (height == -1) {
        if (height < 0) {
            height = mHeight;
        }