Commit 77f7f6f7 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Disable peek mode in lite scripts.

Instead, users will be able to swipe down the sheet to dismiss the lite
script entirely. Example video is in the linked bug.

Bug: b/168706237
Change-Id: Ib0e584bd4186a861cde045aa3a9e8938858009b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421892
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809338}
parent 38ef961b
......@@ -204,6 +204,13 @@ class AssistantBottomBarCoordinator implements AssistantPeekHeightCoordinator.De
if (newState != BottomSheetController.SheetState.SCROLLING) {
maybeShowHeaderChips();
}
if (newState == BottomSheetController.SheetState.HIDDEN) {
AssistantBottomBarDelegate delegate = mModel.getBottomBarDelegate();
if (delegate != null) {
delegate.onBottomSheetDismissed();
}
}
}
@Override
......@@ -241,6 +248,8 @@ class AssistantBottomBarCoordinator implements AssistantPeekHeightCoordinator.De
mRootViewContainer.setTalkbackViewSizeFraction(
model.get(AssistantModel.TALKBACK_SHEET_SIZE_FRACTION));
updateVisualViewportHeight();
} else if (AssistantModel.PEEK_MODE_DISABLED == propertyKey) {
mContent.setPeekModeDisabled(model.get(AssistantModel.PEEK_MODE_DISABLED));
}
});
......
......@@ -8,4 +8,11 @@ package org.chromium.chrome.browser.autofill_assistant;
public interface AssistantBottomBarDelegate {
/** The back button has been pressed. */
boolean onBackButtonPressed();
// TODO(micantox): Instead of a dedicated notification, we should just notify the controller of
// the new bottom sheet state and have the logic to shutdown there. Currently, this would be
// tricky to do because it would interfere with the existing Controller::SetBottomSheetState
// method and in particular tab switching.
/** The bottom sheet was dismissed. */
void onBottomSheetDismissed();
}
......@@ -31,6 +31,14 @@ public class AssistantBottomBarNativeDelegate implements AssistantBottomBarDeleg
return false;
}
@Override
public void onBottomSheetDismissed() {
if (mNativeAssistantBottomBarDelegate != 0) {
AssistantBottomBarNativeDelegateJni.get().onBottomSheetDismissed(
mNativeAssistantBottomBarDelegate, AssistantBottomBarNativeDelegate.this);
}
}
@CalledByNative
private void clearNativePtr() {
mNativeAssistantBottomBarDelegate = 0;
......@@ -40,5 +48,7 @@ public class AssistantBottomBarNativeDelegate implements AssistantBottomBarDeleg
interface Natives {
boolean onBackButtonClicked(
long nativeAssistantBottomBarDelegate, AssistantBottomBarNativeDelegate caller);
void onBottomSheetDismissed(
long nativeAssistantBottomBarDelegate, AssistantBottomBarNativeDelegate caller);
}
}
......@@ -27,6 +27,7 @@ class AssistantBottomSheetContent implements BottomSheetContent {
@Nullable
private ScrollView mContentScrollableView;
private Supplier<AssistantBottomBarDelegate> mBottomBarDelegateSupplier;
private boolean mPeekModeDisabled;
public AssistantBottomSheetContent(
Context context, Supplier<AssistantBottomBarDelegate> supplier) {
......@@ -49,6 +50,10 @@ class AssistantBottomSheetContent implements BottomSheetContent {
mContentScrollableView = scrollableView;
}
void setPeekModeDisabled(boolean disabled) {
mPeekModeDisabled = disabled;
}
@Override
public View getContentView() {
return mContentView;
......@@ -103,6 +108,12 @@ class AssistantBottomSheetContent implements BottomSheetContent {
return true;
}
@Override
public int getPeekHeight() {
return mPeekModeDisabled ? BottomSheetContent.HeightMode.DISABLED
: BottomSheetContent.HeightMode.DEFAULT;
}
@Override
public boolean hideOnScroll() {
return false;
......
......@@ -32,6 +32,7 @@ class AssistantModel extends PropertyModel {
static final WritableFloatPropertyKey TALKBACK_SHEET_SIZE_FRACTION =
new WritableFloatPropertyKey();
static final WritableBooleanPropertyKey VISIBLE = new WritableBooleanPropertyKey();
static final WritableBooleanPropertyKey PEEK_MODE_DISABLED = new WritableBooleanPropertyKey();
/** The web contents the Autofill Assistant is associated with. */
static final WritableObjectPropertyKey<WebContents> WEB_CONTENTS =
......@@ -53,7 +54,8 @@ class AssistantModel extends PropertyModel {
AssistantModel(AssistantOverlayModel overlayModel) {
super(ALLOW_SOFT_KEYBOARD, ALLOW_TALKBACK_ON_WEBSITE, BOTTOM_BAR_DELEGATE,
BOTTOM_SHEET_STATE, TALKBACK_SHEET_SIZE_FRACTION, VISIBLE, WEB_CONTENTS);
BOTTOM_SHEET_STATE, TALKBACK_SHEET_SIZE_FRACTION, VISIBLE, PEEK_MODE_DISABLED,
WEB_CONTENTS);
mOverlayModel = overlayModel;
}
......@@ -138,6 +140,11 @@ class AssistantModel extends PropertyModel {
return get(VISIBLE);
}
@CalledByNative
private void setPeekModeDisabled(boolean disabled) {
set(PEEK_MODE_DISABLED, disabled);
}
@CalledByNative
private void setWebContents(WebContents contents) {
set(WEB_CONTENTS, contents);
......
......@@ -109,6 +109,9 @@ class AssistantOnboardingCoordinator {
DropOutReason.ONBOARDING_BACK_BUTTON_CLICKED);
return true;
}
@Override
public void onBottomSheetDismissed() {}
});
initContent(callback);
BottomSheetUtils.showContentAndMaybeExpand(
......
......@@ -30,6 +30,12 @@ bool AssistantBottomBarDelegate::OnBackButtonClicked(
return ui_controller_->OnBackButtonClicked();
}
void AssistantBottomBarDelegate::OnBottomSheetDismissed(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
ui_controller_->OnBottomSheetDismissed();
}
base::android::ScopedJavaGlobalRef<jobject>
AssistantBottomBarDelegate::GetJavaObject() {
return java_assistant_bottom_bar_delegate_;
......
......@@ -19,6 +19,10 @@ class AssistantBottomBarDelegate {
bool OnBackButtonClicked(JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller);
void OnBottomSheetDismissed(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller);
base::android::ScopedJavaGlobalRef<jobject> GetJavaObject();
private:
......
......@@ -334,6 +334,8 @@ void UiControllerAndroid::Attach(content::WebContents* web_contents,
Java_AssistantCollectUserDataModel_setWebContents(
env, GetCollectUserDataModel(), java_web_contents);
OnClientSettingsChanged(ui_delegate_->GetClientSettings());
Java_AssistantModel_setPeekModeDisabled(env, GetModel(),
ui_delegate->IsRunningLiteScript());
if (ui_delegate->GetState() != AutofillAssistantState::INACTIVE &&
ui_delegate->IsTabSelected()) {
......@@ -920,6 +922,14 @@ bool UiControllerAndroid::OnBackButtonClicked() {
return true;
}
void UiControllerAndroid::OnBottomSheetDismissed() {
if (ui_delegate_->IsTabSelected() && ui_delegate_->IsRunningLiteScript()) {
// Destroying UI here because Shutdown does not do so in all cases.
DestroySelf();
Shutdown(Metrics::DropOutReason::SHEET_CLOSED);
}
}
void UiControllerAndroid::CloseOrCancel(
int action_index,
std::unique_ptr<TriggerContext> trigger_context,
......
......@@ -168,6 +168,7 @@ class UiControllerAndroid : public ControllerObserver {
// Called by AssistantBottomBarNativeDelegate:
bool OnBackButtonClicked();
void OnBottomSheetDismissed();
// Called by Java.
void SnackbarResult(JNIEnv* env,
......
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