Commit 9f582f34 authored by Mei Liang's avatar Mei Liang Committed by Commit Bot

Migrate RootUiCoordinator to use LayoutStateObserver

Change-Id: Id164d3564d3fec41d3c1014d9282e5989b33f8b3
Bug: 1108496
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491444
Commit-Queue: Mei Liang <meiliang@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821879}
parent f99ef034
......@@ -1475,7 +1475,8 @@ public class ChromeTabbedActivity extends ChromeActivity<ChromeActivityComponent
getActivityTabProvider(), mEphemeralTabCoordinatorSupplier,
mTabModelProfileSupplier, mBookmarkBridgeSupplier,
getOverviewModeBehaviorSupplier(), this::getContextualSearchManager,
mTabModelSelectorSupplier, mStartSurfaceSupplier);
mTabModelSelectorSupplier, mStartSurfaceSupplier,
mLayoutStateProviderOneshotSupplier);
}
@Override
......
......@@ -390,7 +390,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
return new RootUiCoordinator(this, null, getShareDelegateSupplier(),
getActivityTabProvider(), mTabModelProfileSupplier, mBookmarkBridgeSupplier,
getOverviewModeBehaviorSupplier(), this::getContextualSearchManager,
mTabModelSelectorSupplier, new OneshotSupplierImpl<>(),
mTabModelSelectorSupplier, new OneshotSupplierImpl<>(), new OneshotSupplierImpl<>(),
new OneshotSupplierImpl<>());
}
......
......@@ -20,8 +20,6 @@ import androidx.browser.customtabs.CustomTabsIntent;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.OneshotSupplierImpl;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.KeyboardShortcuts;
......@@ -29,7 +27,6 @@ import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.browserservices.ui.controller.Verifier;
import org.chromium.chrome.browser.browserservices.ui.trustedwebactivity.TrustedWebActivityCoordinator;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabController;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityTabFactory;
......@@ -79,8 +76,6 @@ public abstract class BaseCustomTabActivity extends ChromeActivity<BaseCustomTab
protected @Nullable WebappActivityCoordinator mWebappActivityCoordinator;
protected @Nullable TrustedWebActivityCoordinator mTwaCoordinator;
protected Verifier mVerifier;
private OneshotSupplier<OverviewModeBehavior> mOverviewModeBehaviorSupplier =
new OneshotSupplierImpl<>();
// This is to give the right package name while using the client's resources during an
// overridePendingTransition call.
......@@ -151,9 +146,7 @@ public abstract class BaseCustomTabActivity extends ChromeActivity<BaseCustomTab
()
-> mNavigationController,
getActivityTabProvider(), mTabModelProfileSupplier, mBookmarkBridgeSupplier,
mOverviewModeBehaviorSupplier, this::getContextualSearchManager,
mTabModelSelectorSupplier, new OneshotSupplierImpl<>(),
new OneshotSupplierImpl<>());
this::getContextualSearchManager, mTabModelSelectorSupplier);
}
@Override
......
......@@ -6,24 +6,21 @@ package org.chromium.chrome.browser.customtabs;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.OneShotCallback;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.OneshotSupplierImpl;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.app.reengagement.ReengagementActivity;
import org.chromium.chrome.browser.bookmarks.BookmarkBridge;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.customtabs.content.CustomTabActivityNavigationController;
import org.chromium.chrome.browser.customtabs.features.toolbar.CustomTabToolbarCoordinator;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.intent.IntentMetadata;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.reengagement.ReengagementNotificationController;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.ui.RootUiCoordinator;
import org.chromium.chrome.features.start_surface.StartSurface;
import org.chromium.components.feature_engagement.Tracker;
/**
......@@ -39,15 +36,13 @@ public class BaseCustomTabRootUiCoordinator extends RootUiCoordinator {
Supplier<CustomTabActivityNavigationController> customTabNavigationController,
ActivityTabProvider tabProvider, ObservableSupplier<Profile> profileSupplier,
ObservableSupplier<BookmarkBridge> bookmarkBridgeSupplier,
OneshotSupplier<OverviewModeBehavior> overviewModeBehaviorSupplier,
Supplier<ContextualSearchManager> contextualSearchManagerSupplier,
ObservableSupplier<TabModelSelector> tabModelSelectorSupplier,
OneshotSupplier<StartSurface> startSurfaceSupplier,
OneshotSupplier<IntentMetadata> intentMetadataOneshotSupplier) {
ObservableSupplier<TabModelSelector> tabModelSelectorSupplier) {
super(activity, null, shareDelegateSupplier, tabProvider, profileSupplier,
bookmarkBridgeSupplier, overviewModeBehaviorSupplier,
contextualSearchManagerSupplier, tabModelSelectorSupplier, startSurfaceSupplier,
intentMetadataOneshotSupplier);
bookmarkBridgeSupplier, new OneshotSupplierImpl<>(),
contextualSearchManagerSupplier, tabModelSelectorSupplier,
new OneshotSupplierImpl<>(), new OneshotSupplierImpl<>(),
new OneshotSupplierImpl<>());
mToolbarCoordinator = customTabToolbarCoordinator;
mNavigationController = customTabNavigationController;
}
......
......@@ -37,6 +37,7 @@ import org.chromium.chrome.browser.gesturenav.TabbedSheetDelegate;
import org.chromium.chrome.browser.history.HistoryManagerUtils;
import org.chromium.chrome.browser.intent.IntentMetadata;
import org.chromium.chrome.browser.language.LanguageAskPrompt;
import org.chromium.chrome.browser.layouts.LayoutStateProvider;
import org.chromium.chrome.browser.locale.LocaleManager;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.offlinepages.indicator.OfflineIndicatorControllerV2;
......@@ -98,6 +99,7 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator {
* @param overviewModeBehaviorSupplier Supplier of the overview mode manager.
* @param contextualSearchManagerSupplier Supplier of the {@link ContextualSearchManager}.
* @param startSurfaceSupplier Supplier of the {@link StartSurface}.
* @param layoutStateProviderOneshotSupplier Supplier of the {@link LayoutStateProvider}.
*/
public TabbedRootUiCoordinator(ChromeActivity activity,
Callback<Boolean> onOmniboxFocusChangedListener,
......@@ -110,11 +112,12 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator {
OneshotSupplier<OverviewModeBehavior> overviewModeBehaviorSupplier,
Supplier<ContextualSearchManager> contextualSearchManagerSupplier,
ObservableSupplier<TabModelSelector> tabModelSelectorSupplier,
OneshotSupplier<StartSurface> startSurfaceSupplier) {
OneshotSupplier<StartSurface> startSurfaceSupplier,
OneshotSupplier<LayoutStateProvider> layoutStateProviderOneshotSupplier) {
super(activity, onOmniboxFocusChangedListener, shareDelegateSupplier, tabProvider,
profileSupplier, bookmarkBridgeSupplier, overviewModeBehaviorSupplier,
contextualSearchManagerSupplier, tabModelSelectorSupplier, startSurfaceSupplier,
intentMetadataOneshotSupplier);
intentMetadataOneshotSupplier, layoutStateProviderOneshotSupplier);
mEphemeralTabCoordinatorSupplier = ephemeralTabCoordinatorSupplier;
mCanAnimateBrowserControls = () -> {
// These null checks prevent any exceptions that may be caused by callbacks after
......
......@@ -33,13 +33,8 @@ import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.bookmarks.BookmarkBridge;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.compositor.layouts.SceneChangeObserver;
import org.chromium.chrome.browser.compositor.layouts.StaticLayout;
import org.chromium.chrome.browser.compositor.layouts.phone.SimpleAnimationLayout;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.crash.PureJavaExceptionReporter;
import org.chromium.chrome.browser.directactions.DirectActionInitializer;
......@@ -52,6 +47,8 @@ import org.chromium.chrome.browser.fullscreen.BrowserControlsManager;
import org.chromium.chrome.browser.identity_disc.IdentityDiscController;
import org.chromium.chrome.browser.image_descriptions.ImageDescriptionsController;
import org.chromium.chrome.browser.intent.IntentMetadata;
import org.chromium.chrome.browser.layouts.LayoutStateProvider;
import org.chromium.chrome.browser.layouts.LayoutType;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.lifecycle.InflationObserver;
import org.chromium.chrome.browser.lifecycle.NativeInitObserver;
......@@ -118,7 +115,6 @@ public class RootUiCoordinator
private final MenuOrKeyboardActionController mMenuOrKeyboardActionController;
private final TabObscuringHandler mTabObscuringHandler;
private final AccessibilityVisibilityHandler mAccessibilityVisibilityHandler;
private final SceneChangeObserver mContextualSearchSceneChangeObserver;
private ActivityTabProvider mActivityTabProvider;
private ObservableSupplier<ShareDelegate> mShareDelegateSupplier;
......@@ -130,9 +126,12 @@ public class RootUiCoordinator
private OverlayPanelManager mOverlayPanelManager;
private OverlayPanelManager.OverlayPanelManagerObserver mOverlayPanelManagerObserver;
private OverviewModeBehavior mOverviewModeBehavior;
private OneshotSupplier<LayoutStateProvider> mLayoutStateProviderOneShotSupplier;
private LayoutStateProvider mLayoutStateProvider;
private LayoutStateProvider.LayoutStateObserver mLayoutStateObserver;
// TODO(crbug.com/1108496): Remove after ToolbarManager migrates to LayoutStateProvider.
private OneshotSupplier<OverviewModeBehavior> mOverviewModeBehaviorSupplier;
private OverviewModeBehavior.OverviewModeObserver mOverviewModeObserver;
/** A means of providing the theme color to different features. */
private TabThemeColorProvider mTabThemeColorProvider;
......@@ -191,6 +190,7 @@ public class RootUiCoordinator
* @param tabModelSelectorSupplier Supplier of the {@link TabModelSelector}.
* @param startSurfaceSupplier Supplier of the {@link StartSurface}.
* @param intentMetadataOneshotSupplier Supplier with information about the launching intent.
* @param layoutStateProviderOneshotSupplier Supplier of the {@link LayoutStateProvider}.
*/
public RootUiCoordinator(ChromeActivity activity,
@Nullable Callback<Boolean> onOmniboxFocusChangedListener,
......@@ -201,7 +201,8 @@ public class RootUiCoordinator
Supplier<ContextualSearchManager> contextualSearchManagerSupplier,
ObservableSupplier<TabModelSelector> tabModelSelectorSupplier,
OneshotSupplier<StartSurface> startSurfaceSupplier,
OneshotSupplier<IntentMetadata> intentMetadataOneshotSupplier) {
OneshotSupplier<IntentMetadata> intentMetadataOneshotSupplier,
OneshotSupplier<LayoutStateProvider> layoutStateProviderOneshotSupplier) {
mCallbackController = new CallbackController();
mActivity = activity;
mOnOmniboxFocusChangedListener = onOmniboxFocusChangedListener;
......@@ -228,27 +229,15 @@ public class RootUiCoordinator
mOmniboxFocusStateSupplier.set(false);
mLayoutStateProviderOneShotSupplier = layoutStateProviderOneshotSupplier;
mLayoutStateProviderOneShotSupplier.onAvailable(
mCallbackController.makeCancelable(this::setLayoutStateProvider));
// TODO(crbug.com/1108496): Remove after ToolbarManager migrates to LayoutStateProvider.
mOverviewModeBehaviorSupplier = overviewModeBehaviorSupplier;
mOverviewModeBehaviorSupplier.onAvailable(
mCallbackController.makeCancelable(this::setOverviewModeBehavior));
mStartSurfaceSupplier = startSurfaceSupplier;
mIntentMetadataOneshotSupplier = intentMetadataOneshotSupplier;
mContextualSearchSceneChangeObserver = new SceneChangeObserver() {
@Override
public void onSceneChange(Layout layout) {
// Check if a layout is showing that should hide the overlay panels.
if (layout instanceof StaticLayout || layout instanceof SimpleAnimationLayout) {
return;
}
if (mContextualSearchManagerSupplier.get() != null) {
mContextualSearchManagerSupplier.get().dismissContextualSearchBar();
}
}
@Override
public void onTabSelectionHinted(int tabId) {}
};
}
// TODO(pnoland, crbug.com/865801): remove this in favor of wiring it directly.
......@@ -258,6 +247,8 @@ public class RootUiCoordinator
@Override
public void destroy() {
// TODO(meiliang): Understand why we need to set most of the class member instances to null
// other than the mActivity. If the nulling calls are not necessary, we can remove them.
mCallbackController.destroy();
mMenuOrKeyboardActionController.unregisterMenuOrKeyboardActionHandler(this);
......@@ -273,19 +264,16 @@ public class RootUiCoordinator
mMessageContainerCoordinator = null;
}
if (mLayoutManager != null) {
mLayoutManager.removeSceneChangeObserver(mContextualSearchSceneChangeObserver);
}
if (mOverlayPanelManager != null) {
mOverlayPanelManager.removeObserver(mOverlayPanelManagerObserver);
}
if (mOverviewModeBehavior != null) {
mOverviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver);
mOverviewModeBehavior = null;
if (mLayoutStateProvider != null) {
mLayoutStateProvider.removeObserver(mLayoutStateObserver);
mLayoutStateProvider = null;
}
// TODO(crbug.com/1108496): Remove after ToolbarManager migrates to LayoutStateProvider.
if (mOverviewModeBehaviorSupplier != null) {
mOverviewModeBehaviorSupplier = null;
}
......@@ -338,7 +326,7 @@ public class RootUiCoordinator
if (mScrimCoordinator != null) mScrimCoordinator.destroy();
mScrimCoordinator = null;
if (mTabModelSelectorSupplier == null) {
if (mTabModelSelectorSupplier != null) {
mTabModelSelectorSupplier = null;
}
......@@ -534,7 +522,6 @@ public class RootUiCoordinator
}
// Protected class methods
protected void onLayoutManagerAvailable(LayoutManager layoutManager) {
mLayoutManager = layoutManager;
if (mOverlayPanelManager != null) {
......@@ -557,7 +544,6 @@ public class RootUiCoordinator
}
mOverlayPanelManager.addObserver(mOverlayPanelManagerObserver);
layoutManager.addSceneChangeObserver(mContextualSearchSceneChangeObserver);
}
/**
......@@ -621,43 +607,59 @@ public class RootUiCoordinator
R.color.omnibox_focused_fading_background_color));
}
private void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {
assert overviewModeBehavior != null;
assert mOverviewModeBehavior
== null
: "TODO(https://crbug.com/1084528): the overview mode manager should set at most once.";
private void setLayoutStateProvider(LayoutStateProvider layoutStateProvider) {
assert layoutStateProvider != null;
assert mLayoutStateProvider == null : "The LayoutStateProvider should set at most once.";
mOverviewModeBehavior = overviewModeBehavior;
mOverviewModeObserver = new EmptyOverviewModeObserver() {
mLayoutStateProvider = layoutStateProvider;
mLayoutStateObserver = new LayoutStateProvider.LayoutStateObserver() {
@Override
public void onOverviewModeStartedShowing(boolean showToolbar) {
if (mFindToolbarManager != null) mFindToolbarManager.hideToolbar();
hideAppMenu();
public void onStartedShowing(int layoutType, boolean showToolbar) {
if (layoutType != LayoutType.BROWSING
&& layoutType != LayoutType.SIMPLE_ANIMATION) {
// Hide contextual search.
if (mContextualSearchManagerSupplier.get() != null) {
mContextualSearchManagerSupplier.get().dismissContextualSearchBar();
}
}
if (layoutType == LayoutType.TAB_SWITCHER) {
// Hide find toolbar and app menu.
if (mFindToolbarManager != null) mFindToolbarManager.hideToolbar();
hideAppMenu();
}
}
@Override
public void onOverviewModeFinishedShowing() {
// Ideally we wouldn't allow the app menu to show while animating the
// overview mode. This is hard to track, however, because in some
// instances #onOverviewModeStartedShowing is called after
// #onOverviewModeFinishedShowing (see https://crbug.com/969047).
// Once that bug is fixed, we can remove this call to hide in favor of
// disallowing app menu shows during animation. Alternatively, we
// could expose a way to query whether an animation is in progress.
hideAppMenu();
public void onFinishedShowing(int layoutType) {
if (layoutType == LayoutType.TAB_SWITCHER) {
// Ideally we wouldn't allow the app menu to show while animating the
// overview mode. This is hard to track, however, because in some
// instances #onOverviewModeStartedShowing is called after
// #onOverviewModeFinishedShowing (see https://crbug.com/969047).
// Once that bug is fixed, we can remove this call to hide in favor of
// disallowing app menu shows during animation. Alternatively, we
// could expose a way to query whether an animation is in progress.
hideAppMenu();
}
}
@Override
public void onOverviewModeStartedHiding(boolean showToolbar, boolean delayAnimation) {
hideAppMenu();
public void onStartedHiding(
int layoutType, boolean showToolbar, boolean delayAnimation) {
if (layoutType == LayoutType.TAB_SWITCHER) {
hideAppMenu();
}
}
@Override
public void onOverviewModeFinishedHiding() {
hideAppMenu();
public void onFinishedHiding(int layoutType) {
if (layoutType != LayoutType.TAB_SWITCHER) {
hideAppMenu();
};
}
};
mOverviewModeBehavior.addOverviewModeObserver(mOverviewModeObserver);
mLayoutStateProvider.addObserver(mLayoutStateObserver);
}
private void initAppMenu() {
......
......@@ -172,7 +172,8 @@ public class ShareIntentTest {
return new RootUiCoordinator(mockActivity, null,
mockActivity.getShareDelegateSupplier(), mockActivity.getActivityTabProvider(),
null, null, mockActivity.getOverviewModeBehaviorSupplier(), null, null,
new OneshotSupplierImpl<>(), new OneshotSupplierImpl<>());
new OneshotSupplierImpl<>(), new OneshotSupplierImpl<>(),
new OneshotSupplierImpl<>());
});
ShareHelper.setLastShareComponentName(new ComponentName("test.package", "test.activity"));
// Skips the capture of screenshot and notifies with an empty file.
......
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