Commit e618e15f authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Mfill Android] Increase vertical threshold before showing the accessory

By increasing the vertical threshold, we ensure that the user has 80dp
left even if the keyboard accessory is showing. Since we considered the
accessory height in addition to that threshold in our sheet height
calculations, the latter needed an update.

FYI: I intend to merge this CL into M78.

Bug: 1002002
Change-Id: I447667e69a493ca9da238a8a38ada012733dabf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790883Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694766}
parent 3915512d
......@@ -73,7 +73,7 @@ import java.util.HashSet;
*/
class ManualFillingMediator extends EmptyTabObserver
implements KeyboardAccessoryCoordinator.VisibilityDelegate, View.OnLayoutChangeListener {
static private final int MINIMAL_AVAILABLE_VERTICAL_SPACE = 80; // in DP.
static private final int MINIMAL_AVAILABLE_VERTICAL_SPACE = 128; // in DP.
static private final int MINIMAL_AVAILABLE_HORIZONTAL_SPACE = 180; // in DP.
private PropertyModel mModel = ManualFillingProperties.createFillingModel();
......@@ -582,18 +582,11 @@ class ManualFillingMediator extends EmptyTabObserver
int maxHeight = mKeyboardExtensionViewResizer.getHeight();
maxHeight += Math.round(density * webContents.getHeight());
maxHeight -= Math.round(density * MINIMAL_AVAILABLE_VERTICAL_SPACE);
maxHeight -= calculateAccessoryBarHeight();
if (mAccessorySheet.getHeight() <= maxHeight) return; // Sheet height needs no adjustment!
mAccessorySheet.setHeight(maxHeight);
changeBottomControlSpaceForState(mModel.get(KEYBOARD_EXTENSION_STATE));
}
private @Px int calculateAccessoryBarHeight() {
if (!mKeyboardAccessory.isShown()) return 0;
return mActivity.getResources().getDimensionPixelSize(
R.dimen.keyboard_accessory_suggestion_height);
}
private void refreshTabs() {
if (!isInitialized()) return;
ManualFillingState state = mStateCache.getStateFor(mActivity.getCurrentWebContents());
......
......@@ -645,12 +645,12 @@ public class ManualFillingControllerTest {
when(mMockKeyboard.isSoftKeyboardShowing(any(), any())).thenReturn(true);
when(mMockKeyboardAccessory.empty()).thenReturn(false);
// Show the accessory bar for the default dimensions (300x80@2.f).
// Show the accessory bar for the default dimensions (300x128@2.f).
mController.showWhenKeyboardIsVisible();
verify(mMockKeyboardAccessory).show();
// The accessory is shown and the content area plus bar size don't exceed the threshold.
simulateLayoutSizeChange(3.f, 180, 80);
simulateLayoutSizeChange(3.f, 180, 128);
verify(mMockKeyboardAccessory, never()).dismiss();
}
......@@ -673,7 +673,7 @@ public class ManualFillingControllerTest {
assertThat(mModel.get(KEYBOARD_EXTENSION_STATE), not(is(HIDDEN)));
// Rotating the screen causes a relayout:
setContentAreaDimensions(2.f, 320, 80, Surface.ROTATION_90);
setContentAreaDimensions(2.f, 320, 128, Surface.ROTATION_90);
mMediator.onLayoutChange(mMockContentView, 0, 0, 160, 640, 0, 0, 540, 360);
assertThat(mModel.get(KEYBOARD_EXTENSION_STATE), is(HIDDEN));
}
......@@ -688,18 +688,18 @@ public class ManualFillingControllerTest {
when(mMockKeyboard.isSoftKeyboardShowing(eq(mMockActivity), any())).thenReturn(true);
when(mMockKeyboardAccessory.empty()).thenReturn(false);
// Show the accessory bar for the dimensions exactly at the threshold: 300x80@2.f.
simulateLayoutSizeChange(2.0f, 300, 80);
// Show the accessory bar for the dimensions exactly at the threshold: 300x128@2.f.
simulateLayoutSizeChange(2.0f, 300, 128);
mController.showWhenKeyboardIsVisible();
assertThat(mModel.get(KEYBOARD_EXTENSION_STATE), not(is(HIDDEN)));
verify(mMockKeyboardAccessory).show();
// The height is now reduced by the 48dp high accessory -- it should remain visible.
simulateLayoutSizeChange(2.0f, 300, 32);
simulateLayoutSizeChange(2.0f, 300, 80);
assertThat(mModel.get(KEYBOARD_EXTENSION_STATE), not(is(HIDDEN)));
// Use a height that is too small but with a valid width (e.g. resized multi-window window).
simulateLayoutSizeChange(2.0f, 300, 31);
simulateLayoutSizeChange(2.0f, 300, 79);
assertThat(mModel.get(KEYBOARD_EXTENSION_STATE), is(HIDDEN));
}
......@@ -714,22 +714,22 @@ public class ManualFillingControllerTest {
when(mMockKeyboard.isSoftKeyboardShowing(eq(mMockActivity), any())).thenReturn(true);
when(mMockKeyboardAccessory.empty()).thenReturn(false);
// Show the accessory bar for the dimensions exactly at the threshold: 180x100@2.f.
simulateLayoutSizeChange(2.0f, 180, 100);
// Show the accessory bar for the dimensions exactly at the threshold: 180x128@2.f.
simulateLayoutSizeChange(2.0f, 180, 128);
mController.showWhenKeyboardIsVisible();
assertThat(mModel.get(KEYBOARD_EXTENSION_STATE), not(is(HIDDEN)));
// Use a width that is too small but with a valid height (e.g. resized multi-window window).
simulateLayoutSizeChange(2.0f, 179, 100);
simulateLayoutSizeChange(2.0f, 179, 128);
assertThat(mModel.get(KEYBOARD_EXTENSION_STATE), is(HIDDEN));
}
@Test
public void testRestrictsSheetSizeIfVerticalSpaceChanges() {
addBrowserTab(mMediator, 1234, null);
// Resize the screen from 300x80@2.f to 300x200@2.f.
// Resize the screen from 300x128@2.f to 300x200@2.f.
setContentAreaDimensions(2.f, 200, 300);
mMediator.onLayoutChange(mMockContentView, 0, 0, 400, 600, 0, 0, 160, 600);
mMediator.onLayoutChange(mMockContentView, 0, 0, 400, 600, 0, 0, 256, 600);
when(mMockKeyboardAccessory.empty()).thenReturn(false);
when(mMockKeyboardAccessory.isShown()).thenReturn(true);
......@@ -748,8 +748,8 @@ public class ManualFillingControllerTest {
// Set layout as if it was rotated: 200x300@2f minus the 100dp+48dp high filling ui.
setContentAreaDimensions(2.f, 300, 52);
mMediator.onLayoutChange(mMockContentView, 0, 0, 600, 102, 0, 0, 320, 600);
verify(mMockAccessorySheet).setHeight(144); // == 2f * (200dp - (80dp - 48dp))
mMediator.onLayoutChange(mMockContentView, 0, 0, 600, 104, 0, 0, 400, 600);
verify(mMockAccessorySheet).setHeight(144); // == 2f * (200dp - 128dp)
}
@Test
......@@ -1067,7 +1067,7 @@ public class ManualFillingControllerTest {
mediator.getTabModelObserverForTesting().didAddTab(tab, FROM_BROWSER_ACTIONS);
mediator.getTabObserverForTesting().onShown(tab, FROM_NEW);
mediator.getTabModelObserverForTesting().didSelectTab(tab, FROM_NEW, lastId);
setContentAreaDimensions(2.f, 300, 80);
setContentAreaDimensions(2.f, 300, 128);
return tab;
}
......
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