Skip to content

Commit

Permalink
[PCCT] Fix a visual glitch after exiting fullscreen mode
Browse files Browse the repository at this point in the history
Restoring the window/view dimension after exiting fullscreen mode had
a bug resulting in a wrong navigation bar height. This CL correctly
restores the dimensions that were altered in fullscreen mode.

(cherry picked from commit ca3e0be)

Bug: 1385148
Change-Id: I2cf8f20401bfd5043b1bb3e00dd47b4158909350
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4034586
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1073587}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4080666
Cr-Commit-Position: refs/branch-heads/5414@{#451}
Cr-Branched-From: 4417ee5-refs/heads/main@{#1070088}
  • Loading branch information
JinsukKim authored and Chromium LUCI CQ committed Dec 5, 2022
1 parent ad4dd93 commit 323e3e6
Showing 1 changed file with 33 additions and 5 deletions.
Expand Up @@ -14,9 +14,11 @@
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
Expand Down Expand Up @@ -119,6 +121,7 @@ public class PartialCustomTabHeightStrategy extends CustomTabHeightStrategy
private final @Px int mUnclampedInitialHeight;
private final FullscreenManager mFullscreenManager;
private final boolean mAlwaysShowNavbarButtons;
private final Rect mFullscreenRestoreRect = new Rect();

private static boolean sHasLoggedImmersiveModeConfirmationSetting;

Expand Down Expand Up @@ -603,6 +606,12 @@ private boolean isFixedHeight() {
return mIsFixedHeight;
}

private boolean isFullscreen() {
WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
return attrs.x == 0 && attrs.y == 0 && attrs.width == MATCH_PARENT
&& attrs.height == MATCH_PARENT;
}

private boolean canInteractWithBackground() {
return mInteractWithBackground;
}
Expand Down Expand Up @@ -898,20 +907,39 @@ public boolean onDragEnd(int flingDistance) {

@Override
public void onEnterFullscreen(Tab tab, FullscreenOptions options) {
WindowManager.LayoutParams attrs = new WindowManager.LayoutParams();
attrs.copyFrom(mActivity.getWindow().getAttributes());
if (isFullscreen()) return;
WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
mFullscreenRestoreRect.set(attrs.x, attrs.y, attrs.width, attrs.height);
attrs.x = 0;
attrs.y = 0;
attrs.height = MATCH_PARENT;
attrs.width = MATCH_PARENT;
attrs.height = MATCH_PARENT;
mActivity.getWindow().setAttributes(attrs);
setTopMargins(0, 0);
}

@Override
public void onExitFullscreen(Tab tab) {
setTopMargins(mShadowOffset, getHandleHeight() + mShadowOffset);
initializeHeight();
if (!isFullscreen()) return;
WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
attrs.x = mFullscreenRestoreRect.left;
attrs.y = mFullscreenRestoreRect.top;
attrs.width = mFullscreenRestoreRect.right;
attrs.height = mFullscreenRestoreRect.bottom;
mActivity.getWindow().setAttributes(attrs);
updateShadowOffset();

// Status/navigation bar are not restored on T+. This makes host app visible
// at the area. To work around this, simulate user dragging the tab by 1 pixel
// upon exiting fullscreen.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S) {
int startY = attrs.y;
new Handler().post(() -> {
onDragStart(startY);
onDragMove(startY + 1);
onDragEnd(0);
});
}
}

@Override
Expand Down

0 comments on commit 323e3e6

Please sign in to comment.