Commit 8c3fc0ed authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Support resizing keyboard in the bottom sheet of Chrome Home.

BUG=735285

Change-Id: I3982cc46b68fecf6b6f82193ad6739be265212e2
Reviewed-on: https://chromium-review.googlesource.com/578469
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488444}
parent 3173af0d
...@@ -700,55 +700,56 @@ public class BottomSheet ...@@ -700,55 +700,56 @@ public class BottomSheet
// Listen to height changes on the root. // Listen to height changes on the root.
root.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { root.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
/** Whether or not the keyboard is currently showing. */ private int mPreviousKeyboardHeight;
private boolean mIsKeyboardShowing;
@Override @Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) { int oldLeft, int oldTop, int oldRight, int oldBottom) {
// Compute the new height taking the keyboard into account. // Compute the new height taking the keyboard into account.
// TODO(mdjones): Share this logic with LocationBarLayout: crbug.com/725725. // TODO(mdjones): Share this logic with LocationBarLayout: crbug.com/725725.
int decorHeight = mActivity.getWindow().getDecorView().getHeight(); float previousWidth = mContainerWidth;
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame( float previousHeight = mContainerHeight;
mVisibleViewportRect); mContainerWidth = right - left;
int heightMinusKeyboard = Math.min(decorHeight, mVisibleViewportRect.height()); mContainerHeight = bottom - top;
boolean isKeyboardShowing = if (previousWidth != mContainerWidth || previousHeight != mContainerHeight) {
UiUtils.isKeyboardShowing(getContext(), BottomSheet.this); updateSheetDimensions();
}
boolean keyboardHeightChanged = isKeyboardShowing != mIsKeyboardShowing; int heightMinusKeyboard = (int) mContainerHeight;
int keyboardHeight = 0;
// Make sure the size of the layout actually changed. // Reset mVisibleViewportRect regardless of sheet open state as it is used outside
if (!keyboardHeightChanged && bottom - top == oldBottom - oldTop // of calculating the keyboard height.
&& right - left == oldRight - oldLeft) { mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(
return; mVisibleViewportRect);
if (isSheetOpen()) {
int decorHeight = mActivity.getWindow().getDecorView().getHeight();
heightMinusKeyboard = Math.min(decorHeight, mVisibleViewportRect.height());
keyboardHeight = (int) (mContainerHeight - heightMinusKeyboard);
} }
mContainerWidth = right - left; if (previousHeight != mContainerHeight
mContainerHeight = bottom - top; || mPreviousKeyboardHeight != keyboardHeight) {
mIsKeyboardShowing = isKeyboardShowing;
int keyboardHeight =
mIsKeyboardShowing ? (int) (mContainerHeight - heightMinusKeyboard) : 0;
updateSheetDimensions();
for (BottomSheetObserver o : mObservers) { for (BottomSheetObserver o : mObservers) {
o.onSheetLayout((int) mContainerHeight, heightMinusKeyboard); o.onSheetLayout((int) mContainerHeight, heightMinusKeyboard);
} }
}
// If the keyboard height changed, recompute the padding for the content area. This if (keyboardHeight != mPreviousKeyboardHeight) {
// shrinks the content size while retaining the default background color where the // If the keyboard height changed, recompute the padding for the content area.
// keyboard is appearing. If the sheet is not showing, resize the sheet to its // This shrinks the content size while retaining the default background color
// default state. // where the keyboard is appearing. If the sheet is not showing, resize the
if (keyboardHeightChanged && isSheetOpen()) { // sheet to its default state.
mBottomSheetContentContainer.setPadding( mBottomSheetContentContainer.setPadding(
0, 0, 0, (int) mBottomNavHeight + keyboardHeight); 0, 0, 0, (int) mBottomNavHeight + keyboardHeight);
} else if (!isSheetOpen()) {
mBottomSheetContentContainer.setPadding(0, 0, 0, (int) mBottomNavHeight);
} }
// If we are in the middle of a touch event stream (i.e. scrolling while keyboard is if (previousHeight != mContainerHeight
// up) don't set the sheet state. Instead allow the gesture detector to position the || mPreviousKeyboardHeight != keyboardHeight) {
// sheet and make sure the keyboard hides. // If we are in the middle of a touch event stream (i.e. scrolling while
// keyboard is up) don't set the sheet state. Instead allow the gesture detector
// to position the sheet and make sure the keyboard hides.
if (mIsScrolling) { if (mIsScrolling) {
UiUtils.hideKeyboard(BottomSheet.this); UiUtils.hideKeyboard(BottomSheet.this);
} else { } else {
...@@ -756,6 +757,9 @@ public class BottomSheet ...@@ -756,6 +757,9 @@ public class BottomSheet
setSheetState(mCurrentState, false); setSheetState(mCurrentState, false);
} }
} }
mPreviousKeyboardHeight = keyboardHeight;
}
}); });
// Listen to height changes on the toolbar. // Listen to height changes on the toolbar.
...@@ -809,6 +813,16 @@ public class BottomSheet ...@@ -809,6 +813,16 @@ public class BottomSheet
}); });
} }
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
// Trigger a relayout on window focus to correct any positioning issues when leaving Chrome
// previously. This is required as a layout is not triggered when coming back to Chrome
// with the keyboard previously shown.
if (hasWindowFocus) requestLayout();
}
/** /**
* Set the color of the pull handle used by the toolbar. * Set the color of the pull handle used by the toolbar.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment