Skip to content

Commit

Permalink
ApplicationViewportInsetSupplier sizes WebContents
Browse files Browse the repository at this point in the history
Moves the logic in CompositorViewHolder that considers how much to
inset/outset the View size to size the WebContents into
ApplicationViewportInsetSupplier. Do this by adding a new value,
webContentsHeightInset, in ViewportInsets which allows clients to go
from CompositorViewHolder to WebContents size.

A related simplification is removing the RESIZES_CONTENT condition from
the fullscreen path in getViewport. This prevented getViewport from
resizing the given View height in other VirtualKeyboardModes only to be
matched by a similar special case in updateWebContentsSize to then
prevent outsetting by the keyboard size. By removing them both the
behavior is unchanged.

This change also allows us to remove the dependency in
ManualFillingMediator on the VirtualKeyboardMode by using the new
inset instead.

Change-Id: Ia4a907d276d7d70240e2d41d77795aefe199b7cd
Bug: 1211066
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4330441
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: Friedrich Horschig <fhorschig@chromium.org>
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1118668}
  • Loading branch information
bokand authored and Chromium LUCI CQ committed Mar 17, 2023
1 parent bb5f8ac commit f0b5fde
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 142 deletions.
Expand Up @@ -77,7 +77,6 @@
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyObservable;
import org.chromium.ui.mojom.VirtualKeyboardMode;

import java.util.HashSet;

Expand Down Expand Up @@ -386,31 +385,22 @@ void resume() {

private boolean hasSufficientSpace() {
if (mActivity == null) return false;
// TODO(bokan): Once mApplicationViewportInsetSupplier includes browser controls, we can use
// CompositorViewHolder instead of WebContents and simply apply the viewVisibleHeightInset
// to it, rather than awkwardly undoing the webContentsHeightInset.
WebContents webContents = mActivity.getCurrentWebContents();
if (webContents == null || webContents.isDestroyed()) return false;
float height = webContents.getHeight(); // In dip. Already insetted by top/bottom controls.

// TODO(https://crbug.com/1211066): This class shouldn't know about virtual keyboard mode.
// Move the browser controls into ApplicationViewportInsetSupplier and then do a simple
// inset on the CompositorViewHolder size (rather than WebContents) to remove this
// dependency.
if (mApplicationViewportInsetSupplier.getVirtualKeyboardMode()
== VirtualKeyboardMode.RESIZES_CONTENT) {
// If RESIZES_CONTENT is set, the soft keyboard and accessory *do* resize the
// webContents. Don't consider the impact of the accessory as shown already. If we have
// space for a bar, we continue to have it. The sheet is never bigger than an open
// keyboard — so if an open sheet affects the inset, we can safely ignore it, too.
height += mBottomInsetSupplier.get() / mWindowAndroid.getDisplay().getDipScale();
} else {
// If the mode is RESIZES_VISUAL or OVERLAYS_CONTENT then WebContents is not resized by
// the soft keyboard or the accessory. Subtract the keyboard height to get the visible
// area but ignore the accessory height for the reasons in the above comment.
if (getContentView() != null && getContentView().getRootView() != null) {
height -= mSoftKeyboardDelegate.calculateSoftKeyboardHeight(
getContentView().getRootView())
/ mWindowAndroid.getDisplay().getDipScale();
}
}
// Un-inset the keyboard-related WebContents inset to get back to the CompositorViewHolder
// viewport height (minus browser controls). This will correctly account for the virtual
// keyboard mode which is baked into webContents' height. The CompositorViewHolder is
// resized by the soft keyboard. Don't consider the impact of the accessory as
// shown already. If we have space for a bar, we continue to have it. The sheet is never
// bigger than an open keyboard — so if an open sheet affects the inset, we can safely
// ignore it, too.
height += mApplicationViewportInsetSupplier.get().webContentsHeightInset
/ mWindowAndroid.getDisplay().getDipScale();

return height >= MINIMAL_AVAILABLE_VERTICAL_SPACE // Allows for a bar if not shown yet.
&& webContents.getWidth() >= MINIMAL_AVAILABLE_HORIZONTAL_SPACE;
Expand Down Expand Up @@ -723,27 +713,28 @@ private boolean isSoftKeyboardShowing(@Nullable View view) {
*/
private void restrictAccessorySheetHeight() {
if (!is(FLOATING_SHEET) && !is(REPLACING_KEYBOARD)) return;
// TODO(bokan): Once mApplicationViewportInsetSupplier includes browser controls, we can use
// CompositorViewHolder instead of WebContents and simply apply the viewVisibleHeightInset
// to it, rather than awkwardly undoing the webContentsHeightInset.
WebContents webContents = mActivity.getCurrentWebContents();
if (webContents == null || webContents.isDestroyed()) return;
float density = mWindowAndroid.getDisplay().getDipScale();
// The maximal height for the sheet ensures a minimal amount of WebContents space.
// Ensure the sheet height is adjusted, if needed, to leave a minimal amount of WebContents
// space.
@Px
int visibleViewportHeightPx = Math.round(density * webContents.getHeight());
// TODO(bokan): This class shouldn't know about virtual keyboard mode. Move the browser
// controls into ApplicationViewportInsetSupplier and then do a simple inset on the
// CompositorViewHolder size (rather than WebContents) to remove this dependency.
// https://crbug.com/1211066.
if (mApplicationViewportInsetSupplier.getVirtualKeyboardMode()
!= VirtualKeyboardMode.RESIZES_CONTENT) {
// If the mode is RESIZES_VISUAL or OVERLAYS_CONTENT then WebContents is not resized by
// the soft keyboard or the accessory.
if (getContentView() != null && getContentView().getRootView() != null) {
visibleViewportHeightPx -= mSoftKeyboardDelegate.calculateSoftKeyboardHeight(
getContentView().getRootView());
visibleViewportHeightPx -= mBottomInsetSupplier.get();
}
}

// Un-inset the keyboard-related WebContents inset to get back to the CompositorViewHolder
// viewport height (minus browser controls). This will correctly account for the virtual
// keyboard mode which is baked into webContents' height. The CompositorViewHolder is
// resized by the soft keyboard.
visibleViewportHeightPx += mApplicationViewportInsetSupplier.get().webContentsHeightInset;

// Now remove the insets coming from this class. This will already include the sheet height.
visibleViewportHeightPx -= mBottomInsetSupplier.get();

int minimumVerticalSpacePx = Math.round(density * MINIMAL_AVAILABLE_VERTICAL_SPACE);

if (visibleViewportHeightPx >= minimumVerticalSpacePx) return; // Sheet height needs no adjustment!

// Adjust the height such that the new visible height will be exactly
Expand Down

0 comments on commit f0b5fde

Please sign in to comment.