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

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

PopupWindow: Resolve measure specs before passing to WM.

For the setClipToScreen case we need constraint to
the available display area, but not to the parent window.
If we don't pass FLAG_LAYOUT_NO_LIMITS, we will be constrained
to the parent window. However when we do pass it, we will
not be constrained to the system insets. So, we can pass
FLAG_LAYOUT_NO_LIMITS and constrain ourselves to the insets
via getWindowVisibleDisplayFrame. We also need to avoid
calling setWidth/Height with these resolved values
so we can preserve the indeterminate values in case
layout changes (e.g. rotation).

Bug: 29166136
Change-Id: I4c7c6204e6bc1cdcf4ad86f7e99e3511d4312ae4
parent e4b1fb94
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -1451,7 +1451,7 @@ public class PopupWindow {
        if (mOutsideTouchable) {
            curFlags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
        }
        if (!mClippingEnabled) {
        if (!mClippingEnabled || mClipToScreen) {
            curFlags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
        }
        if (isSplitTouchEnabled()) {
@@ -1513,14 +1513,6 @@ 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 == MATCH_PARENT) {
@@ -1534,6 +1526,11 @@ public class PopupWindow {
            height = mContentView.getMeasuredHeight();
        }

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

        // 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())
@@ -2143,7 +2140,10 @@ public class PopupWindow {

        final boolean paramsChanged = oldGravity != p.gravity || oldX != p.x || oldY != p.y
                || oldWidth != p.width || oldHeight != p.height;
        update(p.x, p.y, p.width, p.height, paramsChanged);
        // If width and mWidth were both < 0 then we have a MATCH_PARENT/WRAP_CONTENT case.
        // findDropDownPosition will have resolved this to absolute values,
        // but we don't want to update mWidth/mHeight to these absolute values.
        update(p.x, p.y, width < 0 ? width : p.width, height < 0 ? height : p.height, paramsChanged);
    }

    /**