Commit e1059908 authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Reimplement keyboard hiding

This re-adds the hiding of keyboard if it shows up in an unexpected
state.

Bug: b/159113241
Bug: b/153625351
Change-Id: Iea7cdc1ffa97a4edf3fe8c4a602b7960dad19bba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2253978
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Cr-Commit-Position: refs/heads/master@{#781780}
parent 2e7e1e19
...@@ -50,7 +50,8 @@ class AssistantCoordinator { ...@@ -50,7 +50,8 @@ class AssistantCoordinator {
tabObscuringHandler, bottomSheetDelegate); tabObscuringHandler, bottomSheetDelegate);
mKeyboardCoordinator = new AssistantKeyboardCoordinator(activity, mKeyboardCoordinator = new AssistantKeyboardCoordinator(activity,
activity.getWindowAndroid().getKeyboardDelegate(), activity.getWindowAndroid().getKeyboardDelegate(),
activity.getCompositorViewHolder(), mModel, keyboardCoordinatorDelegate); activity.getCompositorViewHolder(), mModel, keyboardCoordinatorDelegate,
controller);
mModel.setVisible(true); mModel.setVisible(true);
} }
......
...@@ -8,6 +8,8 @@ import android.app.Activity; ...@@ -8,6 +8,8 @@ import android.app.Activity;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.chrome.browser.compositor.CompositorViewHolder; import org.chromium.chrome.browser.compositor.CompositorViewHolder;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController.SheetState;
import org.chromium.ui.KeyboardVisibilityDelegate.KeyboardVisibilityListener; import org.chromium.ui.KeyboardVisibilityDelegate.KeyboardVisibilityListener;
import org.chromium.ui.base.ActivityKeyboardVisibilityDelegate; import org.chromium.ui.base.ActivityKeyboardVisibilityDelegate;
...@@ -20,7 +22,9 @@ class AssistantKeyboardCoordinator { ...@@ -20,7 +22,9 @@ class AssistantKeyboardCoordinator {
private final CompositorViewHolder mCompositorViewHolder; private final CompositorViewHolder mCompositorViewHolder;
private final KeyboardVisibilityListener mKeyboardVisibilityListener = private final KeyboardVisibilityListener mKeyboardVisibilityListener =
this::onKeyboardVisibilityChanged; this::onKeyboardVisibilityChanged;
private boolean mAllowShowingSoftKeyboard = true;
private Delegate mDelegate; private Delegate mDelegate;
private final BottomSheetController mBottomSheetController;
interface Delegate { interface Delegate {
void onKeyboardVisibilityChanged(boolean visible); void onKeyboardVisibilityChanged(boolean visible);
...@@ -28,11 +32,13 @@ class AssistantKeyboardCoordinator { ...@@ -28,11 +32,13 @@ class AssistantKeyboardCoordinator {
AssistantKeyboardCoordinator(Activity activity, AssistantKeyboardCoordinator(Activity activity,
ActivityKeyboardVisibilityDelegate keyboardVisibilityDelegate, ActivityKeyboardVisibilityDelegate keyboardVisibilityDelegate,
CompositorViewHolder compositorViewHolder, AssistantModel model, Delegate delegate) { CompositorViewHolder compositorViewHolder, AssistantModel model, Delegate delegate,
BottomSheetController controller) {
mActivity = activity; mActivity = activity;
mKeyboardDelegate = keyboardVisibilityDelegate; mKeyboardDelegate = keyboardVisibilityDelegate;
mCompositorViewHolder = compositorViewHolder; mCompositorViewHolder = compositorViewHolder;
mDelegate = delegate; mDelegate = delegate;
mBottomSheetController = controller;
model.addObserver((source, propertyKey) -> { model.addObserver((source, propertyKey) -> {
if (AssistantModel.VISIBLE == propertyKey) { if (AssistantModel.VISIBLE == propertyKey) {
...@@ -41,6 +47,8 @@ class AssistantKeyboardCoordinator { ...@@ -41,6 +47,8 @@ class AssistantKeyboardCoordinator {
} else { } else {
enableListenForKeyboardVisibility(false); enableListenForKeyboardVisibility(false);
} }
} else if (AssistantModel.ALLOW_SOFT_KEYBOARD == propertyKey) {
allowShowingSoftKeyboard(model.get(AssistantModel.ALLOW_SOFT_KEYBOARD));
} }
}); });
} }
...@@ -50,6 +58,11 @@ class AssistantKeyboardCoordinator { ...@@ -50,6 +58,11 @@ class AssistantKeyboardCoordinator {
return mKeyboardDelegate.isKeyboardShowing(mActivity, mCompositorViewHolder); return mKeyboardDelegate.isKeyboardShowing(mActivity, mCompositorViewHolder);
} }
/** Returns whether the BottomSheet is currently shown. */
private boolean isBottomSheetShown() {
return mBottomSheetController.getSheetState() != SheetState.HIDDEN;
}
/** Hides the keyboard. */ /** Hides the keyboard. */
void hideKeyboard() { void hideKeyboard() {
mKeyboardDelegate.hideKeyboard(mCompositorViewHolder); mKeyboardDelegate.hideKeyboard(mCompositorViewHolder);
...@@ -62,9 +75,7 @@ class AssistantKeyboardCoordinator { ...@@ -62,9 +75,7 @@ class AssistantKeyboardCoordinator {
} }
} }
/** /** Start or stop listening for keyboard visibility changes. */
* Start or stop listening for keyboard visibility changes.
*/
private void enableListenForKeyboardVisibility(boolean enabled) { private void enableListenForKeyboardVisibility(boolean enabled) {
if (enabled) { if (enabled) {
mKeyboardDelegate.addKeyboardVisibilityListener(mKeyboardVisibilityListener); mKeyboardDelegate.addKeyboardVisibilityListener(mKeyboardVisibilityListener);
...@@ -73,7 +84,19 @@ class AssistantKeyboardCoordinator { ...@@ -73,7 +84,19 @@ class AssistantKeyboardCoordinator {
} }
} }
/** Set soft keyboard allowed state. */
private void allowShowingSoftKeyboard(boolean allowed) {
mAllowShowingSoftKeyboard = allowed;
if (!allowed && isBottomSheetShown()) {
hideKeyboard();
}
}
/** If the keyboard shows up and is not allowed, hide it. */
private void onKeyboardVisibilityChanged(boolean isShowing) { private void onKeyboardVisibilityChanged(boolean isShowing) {
mDelegate.onKeyboardVisibilityChanged(isShowing); mDelegate.onKeyboardVisibilityChanged(isShowing);
if (isShowing && !mAllowShowingSoftKeyboard && isBottomSheetShown()) {
hideKeyboard();
}
} }
} }
...@@ -22,6 +22,7 @@ import org.chromium.ui.modelutil.PropertyModel; ...@@ -22,6 +22,7 @@ import org.chromium.ui.modelutil.PropertyModel;
*/ */
@JNINamespace("autofill_assistant") @JNINamespace("autofill_assistant")
class AssistantModel extends PropertyModel { class AssistantModel extends PropertyModel {
static final WritableBooleanPropertyKey ALLOW_SOFT_KEYBOARD = new WritableBooleanPropertyKey();
static final WritableBooleanPropertyKey ALLOW_TALKBACK_ON_WEBSITE = static final WritableBooleanPropertyKey ALLOW_TALKBACK_ON_WEBSITE =
new WritableBooleanPropertyKey(); new WritableBooleanPropertyKey();
static final WritableFloatPropertyKey TALKBACK_SHEET_SIZE_FRACTION = static final WritableFloatPropertyKey TALKBACK_SHEET_SIZE_FRACTION =
...@@ -47,7 +48,8 @@ class AssistantModel extends PropertyModel { ...@@ -47,7 +48,8 @@ class AssistantModel extends PropertyModel {
} }
AssistantModel(AssistantOverlayModel overlayModel) { AssistantModel(AssistantOverlayModel overlayModel) {
super(VISIBLE, WEB_CONTENTS, ALLOW_TALKBACK_ON_WEBSITE, TALKBACK_SHEET_SIZE_FRACTION); super(ALLOW_SOFT_KEYBOARD, VISIBLE, WEB_CONTENTS, ALLOW_TALKBACK_ON_WEBSITE,
TALKBACK_SHEET_SIZE_FRACTION);
mOverlayModel = overlayModel; mOverlayModel = overlayModel;
} }
...@@ -90,6 +92,11 @@ class AssistantModel extends PropertyModel { ...@@ -90,6 +92,11 @@ class AssistantModel extends PropertyModel {
return mGenericUiModel; return mGenericUiModel;
} }
@CalledByNative
private void setAllowSoftKeyboard(boolean allowed) {
set(ALLOW_SOFT_KEYBOARD, allowed);
}
@CalledByNative @CalledByNative
private void setAllowTalkbackOnWebsite(boolean allowed) { private void setAllowTalkbackOnWebsite(boolean allowed) {
set(ALLOW_TALKBACK_ON_WEBSITE, allowed); set(ALLOW_TALKBACK_ON_WEBSITE, allowed);
......
...@@ -44,6 +44,7 @@ import org.junit.runner.RunWith; ...@@ -44,6 +44,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.autofill_assistant.R; import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.autofill_assistant.proto.ActionProto; import org.chromium.chrome.browser.autofill_assistant.proto.ActionProto;
import org.chromium.chrome.browser.autofill_assistant.proto.ChipProto; import org.chromium.chrome.browser.autofill_assistant.proto.ChipProto;
import org.chromium.chrome.browser.autofill_assistant.proto.ElementAreaProto; import org.chromium.chrome.browser.autofill_assistant.proto.ElementAreaProto;
...@@ -485,10 +486,15 @@ public class AutofillAssistantChromeTabIntegrationTest { ...@@ -485,10 +486,15 @@ public class AutofillAssistantChromeTabIntegrationTest {
waitUntilViewMatchesCondition(withText("Prompt"), isCompletelyDisplayed()); waitUntilViewMatchesCondition(withText("Prompt"), isCompletelyDisplayed());
// Clicking location bar hides UI. // Clicking location bar hides UI and shows the keyboard.
onView(withId(org.chromium.chrome.R.id.url_bar)).perform(click()); onView(withId(org.chromium.chrome.R.id.url_bar)).perform(click());
waitUntilViewAssertionTrue(withText("Prompt"), doesNotExist(), 3000L); waitUntilViewAssertionTrue(withText("Prompt"), doesNotExist(), 3000L);
ChromeTabbedActivity activity = mTestRule.getActivity();
assertThat(activity.getWindowAndroid().getKeyboardDelegate().isKeyboardShowing(
activity, activity.getCompositorViewHolder()),
is(true));
// Closing keyboard brings it back. // Closing keyboard brings it back.
Espresso.pressBack(); Espresso.pressBack();
waitUntilViewMatchesCondition(withText("Prompt"), isCompletelyDisplayed()); waitUntilViewMatchesCondition(withText("Prompt"), isCompletelyDisplayed());
......
...@@ -242,6 +242,23 @@ base::Optional<bool> GetPreviousFormSelectionResult( ...@@ -242,6 +242,23 @@ base::Optional<bool> GetPreviousFormSelectionResult(
return input_result.selection().selected(selection_index); return input_result.selection().selected(selection_index);
} }
bool ShouldAllowSoftKeyboardForState(AutofillAssistantState state) {
switch (state) {
case AutofillAssistantState::STARTING:
case AutofillAssistantState::RUNNING:
return false;
case AutofillAssistantState::AUTOSTART_FALLBACK_PROMPT:
case AutofillAssistantState::PROMPT:
case AutofillAssistantState::BROWSE:
case AutofillAssistantState::MODAL_DIALOG:
case AutofillAssistantState::STOPPED:
case AutofillAssistantState::TRACKING:
case AutofillAssistantState::INACTIVE:
return true;
}
}
} // namespace } // namespace
// static // static
...@@ -388,6 +405,7 @@ void UiControllerAndroid::SetupForState() { ...@@ -388,6 +405,7 @@ void UiControllerAndroid::SetupForState() {
UpdateActions(ui_delegate_->GetUserActions()); UpdateActions(ui_delegate_->GetUserActions());
AutofillAssistantState state = ui_delegate_->GetState(); AutofillAssistantState state = ui_delegate_->GetState();
AllowShowingSoftKeyboard(ShouldAllowSoftKeyboardForState(state));
bool should_prompt_action_expand_sheet = bool should_prompt_action_expand_sheet =
ui_delegate_->ShouldPromptActionExpandSheet(); ui_delegate_->ShouldPromptActionExpandSheet();
switch (state) { switch (state) {
...@@ -510,6 +528,11 @@ void UiControllerAndroid::OnOverlayColorsChanged( ...@@ -510,6 +528,11 @@ void UiControllerAndroid::OnOverlayColorsChanged(
ui_controller_android_utils::GetJavaColor(env, colors.highlight_border)); ui_controller_android_utils::GetJavaColor(env, colors.highlight_border));
} }
void UiControllerAndroid::AllowShowingSoftKeyboard(bool enabled) {
Java_AssistantModel_setAllowSoftKeyboard(AttachCurrentThread(), GetModel(),
enabled);
}
void UiControllerAndroid::ShowContentAndExpandBottomSheet() { void UiControllerAndroid::ShowContentAndExpandBottomSheet() {
Java_AutofillAssistantUiController_showContentAndExpandBottomSheet( Java_AutofillAssistantUiController_showContentAndExpandBottomSheet(
AttachCurrentThread(), java_object_); AttachCurrentThread(), java_object_);
......
...@@ -220,6 +220,7 @@ class UiControllerAndroid : public ControllerObserver { ...@@ -220,6 +220,7 @@ class UiControllerAndroid : public ControllerObserver {
base::android::ScopedJavaLocalRef<jobject> GetGenericUiModel(); base::android::ScopedJavaLocalRef<jobject> GetGenericUiModel();
void SetOverlayState(OverlayState state); void SetOverlayState(OverlayState state);
void AllowShowingSoftKeyboard(bool enabled);
void ShowContentAndExpandBottomSheet(); void ShowContentAndExpandBottomSheet();
void SetSpinPoodle(bool enabled); void SetSpinPoodle(bool enabled);
std::string GetDebugContext(); std::string GetDebugContext();
......
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