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

Commit 56c2d337 authored by Adam Powell's avatar Adam Powell
Browse files

Fix bug 3067895 - Popup menus clip to container windows

ListPopupWindows will now move to fit within the screen, but will not
be constrained by their parent windows.

Change-Id: I2a19ef474926f328466db32874db4191beebf626
parent eb0699ba
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -576,6 +576,7 @@ public class ListPopupWindow {

            mPopup.setWindowLayoutMode(widthSpec, heightSpec);
            mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
            mPopup.setClipToScreenEnabled(true);
            
            // use outside touchable to dismiss drop down when touching outside of it, so
            // only set this if the dropdown is not always visible
+29 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.IBinder;
import android.util.AttributeSet;
import android.util.Log;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -89,6 +89,7 @@ public class PopupWindow {
    private boolean mClippingEnabled = true;
    private boolean mSplitTouchEnabled;
    private boolean mLayoutInScreen;
    private boolean mClipToScreen;

    private OnTouchListener mTouchInterceptor;
    
@@ -581,6 +582,17 @@ public class PopupWindow {
        mClippingEnabled = enabled;
    }

    /**
     * Clip this popup window to the screen, but not to the containing window.
     *
     * @param enabled True to clip to the screen.
     * @hide
     */
    public void setClipToScreenEnabled(boolean enabled) {
        mClipToScreen = enabled;
        setClippingEnabled(!enabled);
    }
    
    /**
     * <p>Indicates whether the popup window supports splitting touches.</p>
     * 
@@ -1059,6 +1071,21 @@ public class PopupWindow {
            }
        }

        if (mClipToScreen) {
            final int displayFrameWidth = displayFrame.right - displayFrame.left;

            int right = p.x + p.width;
            if (right > displayFrameWidth) {
                p.x -= right - displayFrameWidth;
            }
            if (p.x < displayFrame.left) {
                p.x = displayFrame.left;
                p.width = Math.min(p.width, displayFrameWidth);
            }

            p.y = Math.max(p.y, displayFrame.top);
        }

        p.gravity |= Gravity.DISPLAY_CLIP_VERTICAL;
        
        return onTop;