Commit 33f41173 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Remove remaining users of BottomSheetController#getBottomSheet

Bug: 986310, 1002277
Change-Id: I28a871dd5fb196b657978a87c298e40eb75f9fbd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1896080
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713078}
parent efa6bc49
......@@ -33,7 +33,6 @@ import org.chromium.chrome.browser.autofill_assistant.user_data.AssistantCollect
import org.chromium.chrome.browser.autofill_assistant.user_data.AssistantCollectUserDataModel;
import org.chromium.chrome.browser.compositor.CompositorViewResizer;
import org.chromium.chrome.browser.tab.TabViewAndroidDelegate;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
......@@ -200,12 +199,8 @@ class AssistantBottomBarCoordinator
hide();
}
} else if (AssistantModel.ALLOW_TALKBACK_ON_WEBSITE == propertyKey) {
boolean allow = model.get(AssistantModel.ALLOW_TALKBACK_ON_WEBSITE);
if (allow) {
activity.removeViewObscuringAllTabs(controller.getBottomSheet());
} else {
activity.addViewObscuringAllTabs(controller.getBottomSheet());
}
controller.setIsObscuringAllTabs(
activity, !model.get(AssistantModel.ALLOW_TALKBACK_ON_WEBSITE));
} else if (AssistantModel.WEB_CONTENTS == propertyKey) {
mWebContents = model.get(AssistantModel.WEB_CONTENTS);
}
......@@ -383,9 +378,8 @@ class AssistantBottomBarCoordinator
return;
}
BottomSheet bottomSheet = mBottomSheetController.getBottomSheet();
setVisualViewportResizing((int) Math.floor(
bottomSheet.getCurrentOffsetPx() - bottomSheet.getToolbarShadowHeight()));
setVisualViewportResizing((int) Math.floor(mBottomSheetController.getCurrentOffset()
- mBottomSheetController.getTopShadowHeight()));
}
private void resetVisualViewportHeight() {
......
......@@ -4,9 +4,6 @@
package org.chromium.chrome.browser.autofill_assistant;
import android.view.View;
import org.chromium.chrome.autofill_assistant.R;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
......@@ -15,54 +12,6 @@ class BottomSheetUtils {
/** Request {@code controller} to show {@code content} and expand the sheet when it is shown. */
static void showContentAndExpand(BottomSheetController controller,
AssistantBottomSheetContent content, boolean animate) {
// Add an observer that makes sure the bottom sheet content is always shown, even in the
// peek state.
controller.addObserver(new EmptyBottomSheetObserver() {
private boolean mEnabled;
@Override
public void onSheetContentChanged(BottomSheetContent newContent) {
if (newContent == content) {
mEnabled = true;
} else if (mEnabled) {
// Content was shown then hidden: remove this observer.
mEnabled = false;
controller.removeObserver(this);
}
}
@Override
public void onSheetClosed(int reason) {
if (!mEnabled) return;
// When scrolling with y < peekHeight, the BottomSheet will make the content
// invisible. This is a workaround to prevent that as our toolbar is transparent and
// we want to sheet content to stay visible.
if ((controller.getSheetState() == BottomSheetController.SheetState.SCROLLING
|| controller.getSheetState() == BottomSheetController.SheetState.PEEK)
&& controller.getCurrentSheetContent() == content) {
controller.getBottomSheet()
.findViewById(R.id.bottom_sheet_content)
.setVisibility(View.VISIBLE);
}
}
@Override
public void onSheetStateChanged(int newState) {
if (!mEnabled) return;
if (newState == BottomSheetController.SheetState.PEEK
&& controller.getCurrentSheetContent() == content) {
// When in the peek state, the BottomSheet hides the content view. We override
// that because we artificially increase the height of the transparent toolbar
// to show parts of the content view.
controller.getBottomSheet()
.findViewById(R.id.bottom_sheet_content)
.setVisibility(View.VISIBLE);
}
}
});
// Show the content.
if (controller.requestShowContent(content, animate)) {
controller.expandSheet();
......
......@@ -126,7 +126,8 @@ public class AutofillAssistantUiTest {
// Bottom sheet is shown in the BottomSheet when creating the AssistantCoordinator.
ViewGroup bottomSheetContent =
bottomSheetController.getBottomSheet().findViewById(R.id.autofill_assistant);
bottomSheetController.getBottomSheetViewForTesting().findViewById(
R.id.autofill_assistant);
Assert.assertNotNull(bottomSheetContent);
// Disable bottom sheet content animations. This is a workaround for http://crbug/943483.
......@@ -248,7 +249,8 @@ public class AutofillAssistantUiTest {
// Bottom sheet is shown in the BottomSheet when creating the AssistantCoordinator.
ViewGroup bottomSheetContent =
bottomSheetController.getBottomSheet().findViewById(R.id.autofill_assistant);
bottomSheetController.getBottomSheetViewForTesting().findViewById(
R.id.autofill_assistant);
Assert.assertNotNull(bottomSheetContent);
// Disable bottom sheet content animations. This is a workaround for http://crbug/943483.
......
......@@ -291,7 +291,6 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
private BottomSheetController mBottomSheetController;
private EphemeralTabCoordinator mEphemeralTabCoordinator;
private UpdateNotificationController mUpdateNotificationController;
private BottomSheet mBottomSheet;
private ScrimView mScrimView;
private StatusBarColorController mStatusBarColorController;
......@@ -1474,14 +1473,14 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
Supplier<BottomSheet> sheetSupplier = () -> {
ViewGroup coordinator = findViewById(R.id.coordinator);
getLayoutInflater().inflate(R.layout.bottom_sheet, coordinator);
mBottomSheet = coordinator.findViewById(R.id.bottom_sheet);
mBottomSheet.init(coordinator, getActivityTabProvider(), getFullscreenManager(),
getWindow(), getWindowAndroid().getKeyboardDelegate());
BottomSheet sheet = coordinator.findViewById(R.id.bottom_sheet);
sheet.init(coordinator, getActivityTabProvider(), getFullscreenManager(), getWindow(),
getWindowAndroid().getKeyboardDelegate());
mBottomSheetSnackbarManager = new SnackbarManager(
this, mBottomSheet.findViewById(R.id.bottom_sheet_snackbar_container));
this, sheet.findViewById(R.id.bottom_sheet_snackbar_container));
return mBottomSheet;
return sheet;
};
Supplier<OverlayPanelManager> panelManagerSupplier =
......@@ -1505,7 +1504,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
// is responsible for adding itself to the list of obscuring views when applicable.
if (content != null && content.hasCustomScrimLifecycle()) return;
addViewObscuringAllTabs(mBottomSheet);
mBottomSheetController.setIsObscuringAllTabs(ChromeActivity.this, true);
assert mAppModalToken == TokenHolder.INVALID_TOKEN;
assert mTabModalToken == TokenHolder.INVALID_TOKEN;
......@@ -1525,7 +1524,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
return;
}
removeViewObscuringAllTabs(mBottomSheet);
mBottomSheetController.setIsObscuringAllTabs(ChromeActivity.this, false);
if (getModalDialogManager() != null) {
getModalDialogManager().resumeType(
......
......@@ -18,17 +18,13 @@ import org.chromium.base.TraceEvent;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.gesturenav.HistoryNavigationDelegate;
import org.chromium.chrome.browser.gesturenav.HistoryNavigationDelegateFactory;
import org.chromium.chrome.browser.gesturenav.NavigationGlowFactory;
import org.chromium.chrome.browser.gesturenav.NavigationHandler;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabWebContentsUserData;
import org.chromium.components.feature_engagement.EventConstants;
import org.chromium.components.feature_engagement.Tracker;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.WebContents;
import org.chromium.third_party.android.swiperefresh.SwipeRefreshLayout;
......@@ -212,12 +208,6 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
@Override
public boolean start(
@OverscrollAction int type, float startX, float startY, boolean navigateForward) {
if (mTab.getActivity() != null
&& mTab.getActivity().getBottomSheetController().getBottomSheet() != null) {
Tracker tracker = TrackerFactory.getTrackerForProfile(Profile.getLastUsedProfile());
tracker.notifyEvent(EventConstants.PULL_TO_REFRESH);
}
mSwipeType = type;
if (type == OverscrollAction.PULL_TO_REFRESH) {
if (mSwipeRefreshLayout == null) initSwipeRefreshLayout(mTab.getContext());
......
......@@ -17,7 +17,6 @@ import org.chromium.base.Supplier;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.gesturenav.NavigationSheetMediator.ItemProperties;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController.SheetState;
......@@ -263,8 +262,6 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
}
private @SheetState int getTargetOrCurrentState() {
BottomSheet sheet = mBottomSheetController.get().getBottomSheet();
if (sheet == null) return BottomSheetController.SheetState.HIDDEN;
@SheetState
int state = mBottomSheetController.get().getTargetSheetState();
return state != BottomSheetController.SheetState.NONE
......
......@@ -59,8 +59,7 @@ public class PaymentHandlerCoordinator {
bottomSheetController.addObserver(mediator);
webContents.addObserver(mediator);
PaymentHandlerView view = new PaymentHandlerView(
activity, bottomSheetController.getBottomSheet(), webContents, webContentView);
PaymentHandlerView view = new PaymentHandlerView(activity, webContents, webContentView);
PropertyModelChangeProcessor changeProcessor =
PropertyModelChangeProcessor.create(model, view, PaymentHandlerViewBinder::bind);
mHider = () -> {
......
......@@ -18,7 +18,6 @@ import org.chromium.chrome.browser.thinwebview.ThinWebView;
import org.chromium.chrome.browser.thinwebview.ThinWebViewFactory;
import org.chromium.chrome.browser.ui.widget.FadingShadow;
import org.chromium.chrome.browser.ui.widget.FadingShadowView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content_public.browser.WebContents;
......@@ -37,12 +36,11 @@ import org.chromium.ui.base.ActivityWindowAndroid;
* Construct the PaymentHandlerView.
*
* @param activity The activity where the bottome-sheet should be shown.
* @param bottomSheet The bottom-sheet where the web-content should be shown.
* @param webContents The web-content of the payment-handler web-app.
* @param webContentView The {@link ContentView} that has been contructed with the web-content.
*/
/* package */ PaymentHandlerView(ChromeActivity activity, BottomSheet bottomSheet,
WebContents webContents, ContentView webContentView) {
/* package */ PaymentHandlerView(
ChromeActivity activity, WebContents webContents, ContentView webContentView) {
mToolbarHeightPx = activity.getResources().getDimensionPixelSize(
R.dimen.custom_tabs_control_container_height);
mTabHeight = activity.getActivityTab().getHeight();
......
......@@ -11,7 +11,6 @@ import android.widget.FrameLayout;
import org.chromium.chrome.browser.compositor.CompositorViewResizer;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
......@@ -53,20 +52,19 @@ public class BottomContainer
}
/**
* @param sheet The {@link BottomSheet} that interacts with this container.
* @param sheetController The {@link BottomSheetController} that interacts with this container.
*/
public void setBottomSheetController(BottomSheetController sheetController) {
sheetController.addObserver(new EmptyBottomSheetObserver() {
@Override
public void onSheetOffsetChanged(float heightFraction, float offsetPx) {
BottomSheet sheet = sheetController.getBottomSheet();
// We only care about the height of the bottom sheet between its hidden and peeking
// state (the UI should stack). Once the sheet is opened, the bottom container
// stays in place, becoming obscured by the sheet.
if (heightFraction > sheet.getPeekRatio()) return;
mOffsetFromSheet = -(sheet.getSheetContainerHeight() * heightFraction);
if (sheetController.isSheetOpen()) return;
mOffsetFromSheet = -(sheetController.getContainerHeight() * heightFraction);
// Only apply the shadow height if the sheet is actually visible.
if (heightFraction > 0) mOffsetFromSheet += sheet.getToolbarShadowHeight();
if (heightFraction > 0) mOffsetFromSheet += sheetController.getTopShadowHeight();
setTranslationY(mBaseYOffset);
}
});
......
......@@ -20,6 +20,7 @@ import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import androidx.annotation.DimenRes;
import androidx.annotation.Nullable;
import org.chromium.base.ObserverList;
......@@ -207,13 +208,17 @@ public class BottomSheet
mMinHalfFullDistance =
getResources().getDimensionPixelSize(R.dimen.bottom_sheet_min_full_half_distance);
mToolbarShadowHeight =
getResources().getDimensionPixelOffset(R.dimen.bottom_sheet_toolbar_shadow_height);
mToolbarShadowHeight = getResources().getDimensionPixelOffset(getTopShadowResourceId());
mGestureDetector = new BottomSheetSwipeDetector(context, this);
mIsTouchEnabled = true;
}
/** @return The dimen describing the height of the shadow above the bottom sheet. */
static @DimenRes int getTopShadowResourceId() {
return R.dimen.bottom_sheet_toolbar_shadow_height;
}
/**
* Called when the activity containing the {@link BottomSheet} is destroyed.
*/
......
......@@ -4,12 +4,15 @@
package org.chromium.chrome.browser.widget.bottomsheet;
import android.view.View;
import androidx.annotation.IntDef;
import org.chromium.base.Supplier;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.ActivityTabProvider.HintlessActivityTabObserver;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
......@@ -86,6 +89,9 @@ public class BottomSheetController implements Destroyable {
/** A {@link VrModeObserver} that observers events of entering and exiting VR mode. */
private final VrModeObserver mVrModeObserver;
/** The height of the shadow that sits above the toolbar. */
private final int mToolbarShadowHeight;
/** The parameters that control how the scrim behaves while the sheet is open. */
private ScrimParams mScrimParams;
......@@ -135,6 +141,8 @@ public class BottomSheetController implements Destroyable {
mTabProvider = activityTabProvider;
mOverlayPanelManager = overlayManager;
mPendingSheetObservers = new ArrayList<>();
mToolbarShadowHeight =
scrim.getResources().getDimensionPixelOffset(BottomSheet.getTopShadowResourceId());
mVrModeObserver = new VrModeObserver() {
@Override
......@@ -326,6 +334,37 @@ public class BottomSheetController implements Destroyable {
return mBottomSheet == null ? false : mBottomSheet.isHiding();
}
/** @return The current offset from the bottom of the screen that the sheet is in px. */
public int getCurrentOffset() {
return mBottomSheet == null ? 0 : (int) mBottomSheet.getCurrentOffsetPx();
}
/**
* @return The height of the bottom sheet's container in px. This will return 0 if the sheet has
* not been initialized (content has not been requested).
*/
public int getContainerHeight() {
return mBottomSheet != null ? (int) mBottomSheet.getSheetContainerHeight() : 0;
}
/** @return The height of the shadow above the bottom sheet in px. */
public int getTopShadowHeight() {
return mToolbarShadowHeight;
}
/**
* Set whether the bottom sheet is obscuring all tabs.
* @param activity An activity that knows about tabs.
* @param isObscuring Whether the bottom sheet is considered to be obscuring.
*/
public void setIsObscuringAllTabs(ChromeActivity activity, boolean isObscuring) {
if (isObscuring) {
activity.addViewObscuringAllTabs(mBottomSheet);
} else {
activity.removeViewObscuringAllTabs(mBottomSheet);
}
}
/**
* @param observer The observer to add.
*/
......@@ -377,18 +416,16 @@ public class BottomSheetController implements Destroyable {
}
}
/**
* @return The {@link BottomSheet} controlled by this class.
*/
public BottomSheet getBottomSheet() {
return mBottomSheet;
}
@VisibleForTesting
public void setSheetStateForTesting(@SheetState int state, boolean animate) {
mBottomSheet.setSheetState(state, animate);
}
@VisibleForTesting
public View getBottomSheetViewForTesting() {
return mBottomSheet;
}
/**
* Request that some content be shown in the bottom sheet.
* @param content The content to be shown in the bottom sheet.
......@@ -528,7 +565,7 @@ public class BottomSheetController implements Destroyable {
/**
* @return Whether some other UI is preventing the sheet from showing.
*/
protected boolean isOtherUIObscuring() {
private boolean isOtherUIObscuring() {
return mOverlayPanelManager.get() != null
&& mOverlayPanelManager.get().getActivePanel() != null;
}
......
......@@ -83,7 +83,7 @@ public class BottomSheetControllerTest {
/** @return The activity's BottomSheet. */
private BottomSheet getBottomSheet() {
return mSheetController.getBottomSheet();
return (BottomSheet) mSheetController.getBottomSheetViewForTesting();
}
@Test
......
......@@ -144,8 +144,8 @@ class TouchToFillView implements BottomSheetContent {
@Override
public float getHalfHeightRatio() {
return Math.min(mContext.getResources().getDimensionPixelSize(getDesiredSheetHeight()),
(int) mBottomSheetController.getBottomSheet().getSheetContainerHeight())
/ mBottomSheetController.getBottomSheet().getSheetContainerHeight();
(int) mBottomSheetController.getContainerHeight())
/ mBottomSheetController.getContainerHeight();
}
@Override
......
......@@ -117,7 +117,7 @@ public class BottomSheetTestRule extends ChromeTabbedActivityTestRule {
}
public BottomSheet getBottomSheet() {
return mSheetController.getBottomSheet();
return (BottomSheet) mSheetController.getBottomSheetViewForTesting();
}
/**
......
......@@ -28,12 +28,6 @@ public final class EventConstants {
*/
public static final String DOWNLOAD_HOME_OPENED = "download_home_opened";
/**
* The user triggered pull to refresh. Used to help determine when to show the Chrome Home
* in-product help.
*/
public static final String PULL_TO_REFRESH = "pull_to_refresh";
/**
* Screenshot is taken with Chrome in the foreground.
*/
......
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