Commit 3ee27067 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Android][Mfill] Any BottomSheet suppresses the keyboard accessory

With this CL, the manual filling UI listens to the bottom sheet
controller and suppresses any keyboard accessory or accessory sheet as
soon as a BottomSheet of any kind is opened.

This solution has the following constraints:
* _Any_ bottomsheet will suppress the filling UI, always.
* If the bottomsheet is closed, the filling UI will require another
  interaction (an opened keyboard, focusing a field, rotation) to reopen
  the filling UI.
* The autofill dropdown is not affected in any way. Only if the keyboard
  accessory V2 is active (i.e. flag \#autofill-keyboard-accessory-view),
  the popup will be replaced by chips in the suppressed accessory.
  Launch of V2 has an uncertain target as of this writing.

Bug: 1033849
Change-Id: I55fffa1bb7dd62a08af95705085c4884d38d9877
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036103
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738494}
parent 1cb0d64a
......@@ -16,6 +16,7 @@ import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProper
import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.KeyboardExtensionState.WAITING_TO_REPLACE;
import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.PORTRAIT_ORIENTATION;
import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.SHOW_WHEN_VISIBLE;
import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.SUPPRESSED_BY_BOTTOM_SHEET;
import android.view.Surface;
import android.view.View;
......@@ -58,6 +59,9 @@ import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tabmodel.TabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabModelObserver;
import org.chromium.chrome.browser.vr.VrModuleProvider;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController.SheetState;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.components.autofill.AutofillDelegate;
import org.chromium.components.autofill.AutofillSuggestion;
import org.chromium.content_public.browser.WebContents;
......@@ -126,6 +130,13 @@ class ManualFillingMediator extends EmptyTabObserver
}
};
private final BottomSheetObserver mBottomSheetObserver = new EmptyBottomSheetObserver() {
@Override
public void onSheetStateChanged(@SheetState int newState) {
mModel.set(SUPPRESSED_BY_BOTTOM_SHEET, newState != SheetState.HIDDEN);
}
};
void initialize(KeyboardAccessoryCoordinator keyboardAccessory,
AccessorySheetCoordinator accessorySheet, WindowAndroid windowAndroid) {
mActivity = (ChromeActivity) windowAndroid.getActivity().get();
......@@ -159,6 +170,7 @@ class ManualFillingMediator extends EmptyTabObserver
}
};
mActivity.getFullscreenManager().addListener(mFullscreenListener);
mActivity.getBottomSheetController().addObserver(mBottomSheetObserver);
ensureObserverRegistered(getActiveBrowserTab());
refreshTabs();
}
......@@ -239,6 +251,7 @@ class ManualFillingMediator extends EmptyTabObserver
LayoutManager manager = getLayoutManager();
if (manager != null) manager.removeSceneChangeObserver(mTabSwitcherObserver);
mActivity.getFullscreenManager().removeListener(mFullscreenListener);
mActivity.getBottomSheetController().removeObserver(mBottomSheetObserver);
mWindowAndroid = null;
mActivity = null;
}
......@@ -327,6 +340,11 @@ class ManualFillingMediator extends EmptyTabObserver
} else if (property == KEYBOARD_EXTENSION_STATE) {
transitionIntoState(mModel.get(KEYBOARD_EXTENSION_STATE));
return;
} else if (property == SUPPRESSED_BY_BOTTOM_SHEET) {
if (isInitialized() && mModel.get(SUPPRESSED_BY_BOTTOM_SHEET)) {
mModel.set(KEYBOARD_EXTENSION_STATE, HIDDEN);
}
return;
}
throw new IllegalArgumentException("Unhandled property: " + property);
}
......@@ -357,7 +375,7 @@ class ManualFillingMediator extends EmptyTabObserver
}
// Intentional fallthrough.
case EXTENDING_KEYBOARD:
if (!canExtendKeyboard()) {
if (!canExtendKeyboard() || mModel.get(SUPPRESSED_BY_BOTTOM_SHEET)) {
mModel.set(KEYBOARD_EXTENSION_STATE, HIDDEN);
return false;
}
......@@ -375,7 +393,7 @@ class ManualFillingMediator extends EmptyTabObserver
}
// Intentional fallthrough.
case WAITING_TO_REPLACE:
if (!hasSufficientSpace()) {
if (!hasSufficientSpace() || mModel.get(SUPPRESSED_BY_BOTTOM_SHEET)) {
mModel.set(KEYBOARD_EXTENSION_STATE, HIDDEN);
return false;
}
......
......@@ -32,6 +32,8 @@ class ManualFillingProperties {
new PropertyModel.WritableBooleanPropertyKey("portrait_orientation");
static final PropertyModel.WritableIntPropertyKey KEYBOARD_EXTENSION_STATE =
new PropertyModel.WritableIntPropertyKey("keyboard_extension_state");
static final PropertyModel.WritableBooleanPropertyKey SUPPRESSED_BY_BOTTOM_SHEET =
new PropertyModel.WritableBooleanPropertyKey("suppressed_by_bottom_sheet");
/**
* Properties that a given state enforces. Must be between 0x0 and 0x100.
......@@ -69,10 +71,12 @@ class ManualFillingProperties {
static PropertyModel createFillingModel() {
return new PropertyModel
.Builder(SHOW_WHEN_VISIBLE, KEYBOARD_EXTENSION_STATE, PORTRAIT_ORIENTATION)
.Builder(SHOW_WHEN_VISIBLE, KEYBOARD_EXTENSION_STATE, PORTRAIT_ORIENTATION,
SUPPRESSED_BY_BOTTOM_SHEET)
.with(SHOW_WHEN_VISIBLE, false)
.with(KEYBOARD_EXTENSION_STATE, HIDDEN)
.with(PORTRAIT_ORIENTATION, true)
.with(SUPPRESSED_BY_BOTTOM_SHEET, false)
.build();
}
......
......@@ -75,6 +75,7 @@ import org.chromium.chrome.browser.keyboard_accessory.sheet_tabs.AccessorySheetT
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabHidingType;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.components.embedder_support.view.ContentView;
......@@ -115,6 +116,8 @@ public class ManualFillingControllerTest {
private AccessorySheetCoordinator mMockAccessorySheet;
@Mock
private CompositorViewHolder mMockCompositorViewHolder;
@Mock
private BottomSheetController mMockBottomSheetController;
@Rule
public Features.JUnitProcessor mFeaturesProcessor = new Features.JUnitProcessor();
......@@ -278,6 +281,7 @@ public class ManualFillingControllerTest {
ShadowRecordHistogram.reset();
MockitoAnnotations.initMocks(this);
KeyboardVisibilityDelegate.setInstance(mMockKeyboard);
when(mMockActivity.getBottomSheetController()).thenReturn(mMockBottomSheetController);
when(mMockWindow.getKeyboardDelegate()).thenReturn(mMockKeyboard);
when(mMockWindow.getActivity()).thenReturn(new WeakReference<>(mMockActivity));
when(mMockKeyboard.calculateKeyboardHeight(any())).thenReturn(0);
......
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