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

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

Merge "Fix bounds clipping to be based on app bounds" into main

parents c8e11e11 b4a4d814
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -530,8 +530,26 @@ public final class LocalFloatingToolbarPopup implements FloatingToolbarPopup {
        int rootViewTopOnWindow = mTmpCoords[1];
        int windowLeftOnScreen = rootViewLeftOnScreen - rootViewLeftOnWindow;
        int windowTopOnScreen = rootViewTopOnScreen - rootViewTopOnWindow;
        mCoordsOnWindow.set(
                Math.max(0, x - windowLeftOnScreen), Math.max(0, y - windowTopOnScreen));
        // In some cases, app can have specific Window for Android UI components such as EditText.
        // In this case, Window bounds != App bounds. Hence, instead of ensuring non-negative
        // PopupWindow coords, app bounds should be used to limit the coords. For instance,
        //  ____  <- |
        // |   |     |W1 & App bounds
        // |___|    |
        // |W2 |    | W2 has smaller bounds and contain EditText where PopupWindow will be opened.
        // ----  <-|
        // Here, we'll open PopupWindow upwards, but as PopupWindow is anchored based on W2, it
        // will have negative Y coords. This negative Y is safe to use because it's still within app
        // bounds. However, if it gets out of app bounds, we should clamp it to 0.
        Rect appBounds = mContext
                .getResources().getConfiguration().windowConfiguration.getAppBounds();
        mCoordsOnWindow.set(x - windowLeftOnScreen, y - windowTopOnScreen);
        if (rootViewLeftOnScreen + mCoordsOnWindow.x < appBounds.left) {
            mCoordsOnWindow.x = 0;
        }
        if (rootViewTopOnScreen + mCoordsOnWindow.y < appBounds.top) {
            mCoordsOnWindow.y = 0;
        }
    }

    /**