Commit a1c1507e authored by spdonghao's avatar spdonghao Committed by Commit Bot

Make the toolbar scroll with start surface and pin the omnibox.

This CL makes startSurfaceToolbar act as if it's scrolling with start
surface. And once the omnibox is scrolled up to the top, the real search
box is pinned.
Please see this doc for more information:
http://doc/1m7MBIKFt1qPuv7grxgllAhb6Umaur_T6pwegeWHuDNI#heading=h.xcr03ehfori3

Following work needed to do:
- Add an animation for showing the toolbar container view when
  omnibox is disappearing.
- Remove the progress bar that sometimes shows. crbug.com//1136599

Bug: 1113852, 1041123
Change-Id: I7909bc2fe3caa46758c73e5a4d952ccfdec4fd96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426730
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821406}
parent 429d80f2
...@@ -7,6 +7,8 @@ package org.chromium.chrome.features.start_surface; ...@@ -7,6 +7,8 @@ package org.chromium.chrome.features.start_surface;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.ActivityState; import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
import org.chromium.base.supplier.OneshotSupplierImpl; import org.chromium.base.supplier.OneshotSupplierImpl;
...@@ -153,6 +155,23 @@ public class StartSurfaceCoordinator implements StartSurface { ...@@ -153,6 +155,23 @@ public class StartSurfaceCoordinator implements StartSurface {
} }
} }
@Override
public void addHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
// TODO (crbug.com/1113852): Add a header offset change listener for incognito homepage.
if (mTasksSurface != null) {
mTasksSurface.addHeaderOffsetChangeListener(onOffsetChangedListener);
}
}
@Override
public void removeHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
if (mTasksSurface != null) {
mTasksSurface.removeHeaderOffsetChangeListener(onOffsetChangedListener);
}
}
@Override @Override
public void addStateChangeObserver(StateObserver observer) { public void addStateChangeObserver(StateObserver observer) {
mStartSurfaceMediator.addStateChangeObserver(observer); mStartSurfaceMediator.addStateChangeObserver(observer);
......
...@@ -6,6 +6,8 @@ package org.chromium.chrome.features.start_surface; ...@@ -6,6 +6,8 @@ package org.chromium.chrome.features.start_surface;
import android.os.SystemClock; import android.os.SystemClock;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher; import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
...@@ -36,6 +38,20 @@ public interface StartSurface { ...@@ -36,6 +38,20 @@ public interface StartSurface {
@StartSurfaceState int overviewModeState, boolean shouldShowTabSwitcherToolbar); @StartSurfaceState int overviewModeState, boolean shouldShowTabSwitcherToolbar);
} }
/**
* @param onOffsetChangedListener Registers listener for the offset changes on top of the start
* surface.
*/
void addHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener);
/**
* @param onOffsetChangedListener Unregisters listener for the offset changes on top of the
* start surface.
*/
void removeHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener);
/** /**
* @param observer Registers {@code observer} for the {@link StartSurfaceState} changes. * @param observer Registers {@code observer} for the {@link StartSurfaceState} changes.
*/ */
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
android:layout_height="@dimen/toolbar_height_no_shadow" android:layout_height="@dimen/toolbar_height_no_shadow"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:orientation="vertical" android:orientation="vertical"
app:layout_scrollFlags="scroll"> app:layout_scrollFlags="scroll|enterAlways|snap">
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/scroll_component_container" android:id="@+id/scroll_component_container"
......
...@@ -10,6 +10,8 @@ import android.view.ViewGroup; ...@@ -10,6 +10,8 @@ import android.view.ViewGroup;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.compositor.layouts.Layout; import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.ntp.FakeboxDelegate; import org.chromium.chrome.browser.ntp.FakeboxDelegate;
...@@ -75,4 +77,17 @@ public interface TasksSurface { ...@@ -75,4 +77,17 @@ public interface TasksSurface {
* require native initialization should be constructed here. * require native initialization should be constructed here.
*/ */
void onFinishNativeInitialization(Context context, FakeboxDelegate fakeboxDelegate); void onFinishNativeInitialization(Context context, FakeboxDelegate fakeboxDelegate);
/**
* @param onOffsetChangedListener Registers listener for the offset changes of the header view.
*/
void addHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener);
/**
* @param onOffsetChangedListener Unregisters listener for the offset changes of the header
* view.
*/
void removeHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener);
} }
...@@ -12,6 +12,8 @@ import android.widget.LinearLayout; ...@@ -12,6 +12,8 @@ import android.widget.LinearLayout;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.app.ChromeActivity; import org.chromium.chrome.browser.app.ChromeActivity;
...@@ -163,4 +165,16 @@ public class TasksSurfaceCoordinator implements TasksSurface { ...@@ -163,4 +165,16 @@ public class TasksSurfaceCoordinator implements TasksSurface {
TrendyTermsCache.maybeFetch(Profile.getLastUsedRegularProfile()); TrendyTermsCache.maybeFetch(Profile.getLastUsedRegularProfile());
} }
} }
@Override
public void addHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
mView.addHeaderOffsetChangeListener(onOffsetChangedListener);
}
@Override
public void removeHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
mView.removeHeaderOffsetChangeListener(onOffsetChangedListener);
}
} }
...@@ -338,4 +338,26 @@ class TasksView extends CoordinatorLayoutForPointer { ...@@ -338,4 +338,26 @@ class TasksView extends CoordinatorLayoutForPointer {
void setTrendyTermsVisibility(boolean isVisible) { void setTrendyTermsVisibility(boolean isVisible) {
findViewById(R.id.trendy_terms_recycler_view).setVisibility(isVisible ? VISIBLE : GONE); findViewById(R.id.trendy_terms_recycler_view).setVisibility(isVisible ? VISIBLE : GONE);
} }
/**
* Add a header offset change listener.
* @param onOffsetChangedListener The given header offset change listener.
*/
void addHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
if (mHeaderView != null) {
mHeaderView.addOnOffsetChangedListener(onOffsetChangedListener);
}
}
/**
* Remove the given header offset change listener.
* @param onOffsetChangedListener The header offset change listener which should be removed.
*/
void removeHeaderOffsetChangeListener(
AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
if (mHeaderView != null) {
mHeaderView.removeOnOffsetChangedListener(onOffsetChangedListener);
}
}
} }
...@@ -20,6 +20,8 @@ import androidx.annotation.Nullable; ...@@ -20,6 +20,8 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.CallbackController; import org.chromium.base.CallbackController;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
...@@ -214,6 +216,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -214,6 +216,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
private StartSurface mStartSurface; private StartSurface mStartSurface;
private StartSurface.StateObserver mStartSurfaceStateObserver; private StartSurface.StateObserver mStartSurfaceStateObserver;
private AppBarLayout.OnOffsetChangedListener mStartSurfaceHeaderOffsetChangeListener;
private OneshotSupplier<IntentMetadata> mIntentMetadataOneshotSupplier; private OneshotSupplier<IntentMetadata> mIntentMetadataOneshotSupplier;
private OneshotSupplier<Boolean> mPromoShownOneshotSupplier; private OneshotSupplier<Boolean> mPromoShownOneshotSupplier;
...@@ -357,7 +360,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -357,7 +360,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mToolbar = createTopToolbarCoordinator(controlContainer, toolbarLayout, buttonDataProviders, mToolbar = createTopToolbarCoordinator(controlContainer, toolbarLayout, buttonDataProviders,
browsingModeThemeColorProvider, startSurfaceMenuButtonCoordinator, invalidator, browsingModeThemeColorProvider, startSurfaceMenuButtonCoordinator, invalidator,
identityDiscController, startSurfaceSupplier); identityDiscController);
mActionModeController = mActionModeController =
new ActionModeController(mActivity, mActionBarDelegate, toolbarActionModeCallback); new ActionModeController(mActivity, mActionBarDelegate, toolbarActionModeCallback);
...@@ -666,9 +669,16 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -666,9 +669,16 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mStartSurface = startSurface; mStartSurface = startSurface;
mStartSurfaceStateObserver = (newState, shouldShowToolbar) -> { mStartSurfaceStateObserver = (newState, shouldShowToolbar) -> {
assert StartSurfaceConfiguration.isStartSurfaceEnabled(); assert StartSurfaceConfiguration.isStartSurfaceEnabled();
mToolbar.updateTabSwitcherToolbarState(shouldShowToolbar); mStartSurfaceState = newState;
mToolbar.updateStartSurfaceToolbarState(newState, shouldShowToolbar);
}; };
mStartSurface.addStateChangeObserver(mStartSurfaceStateObserver); mStartSurface.addStateChangeObserver(mStartSurfaceStateObserver);
mStartSurfaceHeaderOffsetChangeListener = (appbarLayout, verticalOffset) -> {
assert StartSurfaceConfiguration.isStartSurfaceEnabled();
mToolbar.onStartSurfaceHeaderOffsetChanged(verticalOffset);
};
mStartSurface.addHeaderOffsetChangeListener(mStartSurfaceHeaderOffsetChangeListener);
})); }));
TraceEvent.end("ToolbarManager.ToolbarManager"); TraceEvent.end("ToolbarManager.ToolbarManager");
...@@ -679,26 +689,20 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -679,26 +689,20 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
List<ButtonDataProvider> buttonDataProviders, List<ButtonDataProvider> buttonDataProviders,
ThemeColorProvider browsingModeThemeColorProvider, ThemeColorProvider browsingModeThemeColorProvider,
MenuButtonCoordinator startSurfaceMenuButtonCoordinator, Invalidator invalidator, MenuButtonCoordinator startSurfaceMenuButtonCoordinator, Invalidator invalidator,
IdentityDiscController identityDiscController, IdentityDiscController identityDiscController) {
OneshotSupplier<StartSurface> startSurfaceSupplier) {
TopToolbarCoordinator toolbar = new TopToolbarCoordinator(controlContainer, toolbarLayout, TopToolbarCoordinator toolbar = new TopToolbarCoordinator(controlContainer, toolbarLayout,
mLocationBarModel, mToolbarTabController, mLocationBarModel, mToolbarTabController,
new UserEducationHelper(mActivity, mHandler, TrackerFactory::getTrackerForProfile), new UserEducationHelper(mActivity, mHandler, TrackerFactory::getTrackerForProfile),
buttonDataProviders, mOverviewModeBehaviorSupplier, browsingModeThemeColorProvider, buttonDataProviders, mOverviewModeBehaviorSupplier, browsingModeThemeColorProvider,
mAppThemeColorProvider, mMenuButtonCoordinator, startSurfaceMenuButtonCoordinator, mAppThemeColorProvider, mMenuButtonCoordinator, startSurfaceMenuButtonCoordinator,
mMenuButtonCoordinator.getMenuButtonHelperSupplier(), mTabModelSelectorSupplier, mMenuButtonCoordinator.getMenuButtonHelperSupplier(), mTabModelSelectorSupplier,
mHomeButtonVisibilitySupplier, mIdentityDiscStateSupplier, mHomeButtonVisibilitySupplier, mIdentityDiscStateSupplier, (client) -> {
(client)
-> {
if (invalidator != null) { if (invalidator != null) {
invalidator.invalidate(client); invalidator.invalidate(client);
} else { } else {
client.run(); client.run();
} }
}, }, () -> identityDiscController.getForStartSurface(mStartSurfaceState));
()
-> identityDiscController.getForStartSurface(mStartSurfaceState),
startSurfaceSupplier);
mHomepageStateListener = () -> { mHomepageStateListener = () -> {
mHomeButtonVisibilitySupplier.set(HomepageManager.isHomepageEnabled()); mHomeButtonVisibilitySupplier.set(HomepageManager.isHomepageEnabled());
mHomepageManagedByPolicySupplier.set(HomepagePolicyManager.isHomepageManagedByPolicy()); mHomepageManagedByPolicySupplier.set(HomepagePolicyManager.isHomepageManagedByPolicy());
...@@ -1026,8 +1030,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -1026,8 +1030,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
if (mStartSurface != null) { if (mStartSurface != null) {
mStartSurface.removeStateChangeObserver(mStartSurfaceStateObserver); mStartSurface.removeStateChangeObserver(mStartSurfaceStateObserver);
mStartSurface.removeHeaderOffsetChangeListener(mStartSurfaceHeaderOffsetChangeListener);
mStartSurface = null; mStartSurface = null;
mStartSurfaceStateObserver = null; mStartSurfaceStateObserver = null;
mStartSurfaceHeaderOffsetChangeListener = null;
} }
mActivity.unregisterComponentCallbacks(mComponentCallbacks); mActivity.unregisterComponentCallbacks(mComponentCallbacks);
......
...@@ -28,8 +28,8 @@ import org.chromium.chrome.browser.toolbar.TabSwitcherButtonView; ...@@ -28,8 +28,8 @@ import org.chromium.chrome.browser.toolbar.TabSwitcherButtonView;
import org.chromium.chrome.browser.toolbar.ThemeColorProvider; import org.chromium.chrome.browser.toolbar.ThemeColorProvider;
import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator; import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator;
import org.chromium.chrome.browser.user_education.UserEducationHelper; import org.chromium.chrome.browser.user_education.UserEducationHelper;
import org.chromium.chrome.features.start_surface.StartSurface;
import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration; import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration;
import org.chromium.chrome.features.start_surface.StartSurfaceState;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor; import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
...@@ -60,8 +60,7 @@ public class StartSurfaceToolbarCoordinator { ...@@ -60,8 +60,7 @@ public class StartSurfaceToolbarCoordinator {
OneshotSupplier<OverviewModeBehavior> overviewModeBehaviorSupplier, OneshotSupplier<OverviewModeBehavior> overviewModeBehaviorSupplier,
ObservableSupplier<Boolean> identityDiscStateSupplier, ThemeColorProvider provider, ObservableSupplier<Boolean> identityDiscStateSupplier, ThemeColorProvider provider,
MenuButtonCoordinator menuButtonCoordinator, MenuButtonCoordinator menuButtonCoordinator,
Supplier<ButtonData> identityDiscButtonSupplier, Supplier<ButtonData> identityDiscButtonSupplier) {
OneshotSupplier<StartSurface> startSurfaceSupplier) {
mStub = startSurfaceToolbarStub; mStub = startSurfaceToolbarStub;
overviewModeBehaviorSupplier.onAvailable( overviewModeBehaviorSupplier.onAvailable(
...@@ -96,8 +95,7 @@ public class StartSurfaceToolbarCoordinator { ...@@ -96,8 +95,7 @@ public class StartSurfaceToolbarCoordinator {
StartSurfaceConfiguration.START_SURFACE_HIDE_INCOGNITO_SWITCH_NO_TAB.getValue(), StartSurfaceConfiguration.START_SURFACE_HIDE_INCOGNITO_SWITCH_NO_TAB.getValue(),
StartSurfaceConfiguration.START_SURFACE_HIDE_INCOGNITO_SWITCH.getValue(), StartSurfaceConfiguration.START_SURFACE_HIDE_INCOGNITO_SWITCH.getValue(),
StartSurfaceConfiguration.START_SURFACE_SHOW_STACK_TAB_SWITCHER.getValue(), StartSurfaceConfiguration.START_SURFACE_SHOW_STACK_TAB_SWITCHER.getValue(),
menuButtonCoordinator, identityDiscStateSupplier, identityDiscButtonSupplier, menuButtonCoordinator, identityDiscStateSupplier, identityDiscButtonSupplier);
startSurfaceSupplier);
mThemeColorProvider = provider; mThemeColorProvider = provider;
mMenuButtonCoordinator = menuButtonCoordinator; mMenuButtonCoordinator = menuButtonCoordinator;
...@@ -161,14 +159,6 @@ public class StartSurfaceToolbarCoordinator { ...@@ -161,14 +159,6 @@ public class StartSurfaceToolbarCoordinator {
mToolbarMediator.setIncognitoStateProvider(provider); mToolbarMediator.setIncognitoStateProvider(provider);
} }
/**
* Called to set the visibility in Start Surface mode.
* @param shouldShowStartSurfaceToolbar whether the toolbar should be visible.
*/
void setStartSurfaceToolbarVisibility(boolean shouldShowStartSurfaceToolbar) {
mToolbarMediator.setStartSurfaceToolbarVisibility(shouldShowStartSurfaceToolbar);
}
/** /**
* Called when accessibility status changes. * Called when accessibility status changes.
* @param enabled whether accessibility status is enabled. * @param enabled whether accessibility status is enabled.
...@@ -219,6 +209,32 @@ public class StartSurfaceToolbarCoordinator { ...@@ -219,6 +209,32 @@ public class StartSurfaceToolbarCoordinator {
} }
} }
/**
* Called when start surface state is changed.
* @param newState The new {@link StartSurfaceState}.
* @param shouldShowStartSurfaceToolbar Whether or not should show start surface toolbar.
*/
void onStartSurfaceStateChanged(
@StartSurfaceState int newState, boolean shouldShowStartSurfaceToolbar) {
mToolbarMediator.onStartSurfaceStateChanged(newState, shouldShowStartSurfaceToolbar);
}
/**
* Triggered when the offset of start surface header view is changed.
* @param verticalOffset The start surface header view's offset.
*/
void onStartSurfaceHeaderOffsetChanged(int verticalOffset) {
mToolbarMediator.onStartSurfaceHeaderOffsetChanged(verticalOffset);
}
/**
* @param toolbarHeight The height of start surface toolbar.
* @return Whether or not toolbar container view should be hidden.
*/
boolean shouldHideToolbarContainer(int toolbarHeight) {
return mToolbarMediator.shouldHideToolbarContainer(toolbarHeight);
}
void onNativeLibraryReady() { void onNativeLibraryReady() {
// It is possible that the {@link mIncognitoSwitchCoordinator} isn't created because // It is possible that the {@link mIncognitoSwitchCoordinator} isn't created because
// inflate() is called when the native library isn't ready. So create it now. // inflate() is called when the native library isn't ready. So create it now.
......
...@@ -21,6 +21,7 @@ import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarPropert ...@@ -21,6 +21,7 @@ import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarPropert
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_HIGHLIGHT; import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_HIGHLIGHT;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_IS_VISIBLE; import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER; import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.TRANSLATION_Y;
import android.view.View; import android.view.View;
...@@ -29,7 +30,6 @@ import androidx.annotation.VisibleForTesting; ...@@ -29,7 +30,6 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.CallbackController; import org.chromium.base.CallbackController;
import org.chromium.base.supplier.ObservableSupplier; import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver; import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
...@@ -44,7 +44,6 @@ import org.chromium.chrome.browser.toolbar.ButtonData; ...@@ -44,7 +44,6 @@ import org.chromium.chrome.browser.toolbar.ButtonData;
import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator; import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator;
import org.chromium.chrome.browser.user_education.IPHCommandBuilder; import org.chromium.chrome.browser.user_education.IPHCommandBuilder;
import org.chromium.chrome.browser.util.ChromeAccessibilityUtil; import org.chromium.chrome.browser.util.ChromeAccessibilityUtil;
import org.chromium.chrome.features.start_surface.StartSurface;
import org.chromium.chrome.features.start_surface.StartSurfaceState; import org.chromium.chrome.features.start_surface.StartSurfaceState;
import org.chromium.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver; import org.chromium.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -68,16 +67,14 @@ class StartSurfaceToolbarMediator { ...@@ -68,16 +67,14 @@ class StartSurfaceToolbarMediator {
private int mOverviewModeState; private int mOverviewModeState;
private boolean mIsGoogleSearchEngine; private boolean mIsGoogleSearchEngine;
private StartSurface mStartSurface;
private StartSurface.StateObserver mStartSurfaceStateObserver;
private CallbackController mCallbackController = new CallbackController(); private CallbackController mCallbackController = new CallbackController();
private float mNonIncognitoHomepageTranslationY;
StartSurfaceToolbarMediator(PropertyModel model, Callback<IPHCommandBuilder> showIPHCallback, StartSurfaceToolbarMediator(PropertyModel model, Callback<IPHCommandBuilder> showIPHCallback,
boolean hideIncognitoSwitchWhenNoTabs, boolean hideIncognitoSwitchOnHomePage, boolean hideIncognitoSwitchWhenNoTabs, boolean hideIncognitoSwitchOnHomePage,
boolean showNewTabAndIdentityDiscAtStart, MenuButtonCoordinator menuButtonCoordinator, boolean showNewTabAndIdentityDiscAtStart, MenuButtonCoordinator menuButtonCoordinator,
ObservableSupplier<Boolean> identityDiscStateSupplier, ObservableSupplier<Boolean> identityDiscStateSupplier,
Supplier<ButtonData> identityDiscButtonSupplier, Supplier<ButtonData> identityDiscButtonSupplier) {
OneshotSupplier<StartSurface> startSurfaceSupplier) {
mPropertyModel = model; mPropertyModel = model;
mOverviewModeState = StartSurfaceState.NOT_SHOWN; mOverviewModeState = StartSurfaceState.NOT_SHOWN;
mShowIPHCallback = showIPHCallback; mShowIPHCallback = showIPHCallback;
...@@ -91,20 +88,6 @@ class StartSurfaceToolbarMediator { ...@@ -91,20 +88,6 @@ class StartSurfaceToolbarMediator {
if (!canShowHint && !mPropertyModel.get(IDENTITY_DISC_IS_VISIBLE)) return; if (!canShowHint && !mPropertyModel.get(IDENTITY_DISC_IS_VISIBLE)) return;
updateIdentityDisc(mIdentityDiscButtonSupplier.get()); updateIdentityDisc(mIdentityDiscButtonSupplier.get());
}); });
startSurfaceSupplier.onAvailable(mCallbackController.makeCancelable(this::setStartSurface));
}
void setStartSurface(StartSurface startSurface) {
mStartSurface = startSurface;
mStartSurfaceStateObserver = (newState, shouldShowToolbar) -> {
mOverviewModeState = newState;
updateIncognitoSwitchVisibility();
updateNewTabButtonVisibility();
updateLogoVisibility(mIsGoogleSearchEngine);
updateIdentityDisc(mIdentityDiscButtonSupplier.get());
};
startSurface.addStateChangeObserver(mStartSurfaceStateObserver);
} }
void onNativeLibraryReady() { void onNativeLibraryReady() {
...@@ -132,15 +115,37 @@ class StartSurfaceToolbarMediator { ...@@ -132,15 +115,37 @@ class StartSurfaceToolbarMediator {
if (mOverviewModeObserver != null) { if (mOverviewModeObserver != null) {
mOverviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver); mOverviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver);
} }
if (mStartSurface != null) {
mStartSurface.removeStateChangeObserver(mStartSurfaceStateObserver);
}
if (mCallbackController != null) { if (mCallbackController != null) {
mCallbackController.destroy(); mCallbackController.destroy();
mCallbackController = null; mCallbackController = null;
} }
} }
void onStartSurfaceStateChanged(
@StartSurfaceState int newState, boolean shouldShowStartSurfaceToolbar) {
mOverviewModeState = newState;
setStartSurfaceToolbarVisibility(shouldShowStartSurfaceToolbar);
updateIncognitoSwitchVisibility();
updateNewTabButtonVisibility();
updateLogoVisibility(mIsGoogleSearchEngine);
updateIdentityDisc(mIdentityDiscButtonSupplier.get());
updateTranslationY(mNonIncognitoHomepageTranslationY);
}
void onStartSurfaceHeaderOffsetChanged(int verticalOffset) {
updateTranslationY(verticalOffset);
}
boolean shouldHideToolbarContainer(int toolbarHeight) {
// If it's on the non-incognito homepage, start surface toolbar is visible (omnibox has no
// focus), and scrolling offset is smaller than toolbar's height, we need to hide toolbar
// container until start surface toolbar is disappearing.
return mOverviewModeState == StartSurfaceState.SHOWN_HOMEPAGE
&& !mPropertyModel.get(IS_INCOGNITO) && mPropertyModel.get(IS_VISIBLE)
&& -mPropertyModel.get(TRANSLATION_Y) != 0
&& -mPropertyModel.get(TRANSLATION_Y) < toolbarHeight;
}
void setOnNewTabClickHandler(View.OnClickListener listener) { void setOnNewTabClickHandler(View.OnClickListener listener) {
mPropertyModel.set(NEW_TAB_CLICK_HANDLER, listener); mPropertyModel.set(NEW_TAB_CLICK_HANDLER, listener);
} }
...@@ -286,6 +291,19 @@ class StartSurfaceToolbarMediator { ...@@ -286,6 +291,19 @@ class StartSurfaceToolbarMediator {
mPropertyModel.set(NEW_TAB_BUTTON_IS_VISIBLE, isShownTabswitcherState); mPropertyModel.set(NEW_TAB_BUTTON_IS_VISIBLE, isShownTabswitcherState);
} }
private void updateTranslationY(float transY) {
if (mOverviewModeState == StartSurfaceState.SHOWN_HOMEPAGE
&& !mPropertyModel.get(IS_INCOGNITO)) {
// If it's on the non-incognito homepage, document the homepage translationY.
mNonIncognitoHomepageTranslationY = transY;
// Update the translationY of the toolbarView.
mPropertyModel.set(TRANSLATION_Y, transY);
} else {
// If it's not on the non-incognito homepage, set the translationY as 0.
mPropertyModel.set(TRANSLATION_Y, 0);
}
}
@VisibleForTesting @VisibleForTesting
@StartSurfaceState @StartSurfaceState
int getOverviewModeStateForTesting() { int getOverviewModeStateForTesting() {
......
...@@ -66,10 +66,14 @@ class StartSurfaceToolbarProperties { ...@@ -66,10 +66,14 @@ class StartSurfaceToolbarProperties {
public static final PropertyModel.WritableBooleanPropertyKey NEW_TAB_BUTTON_AT_START = public static final PropertyModel.WritableBooleanPropertyKey NEW_TAB_BUTTON_AT_START =
new PropertyModel.WritableBooleanPropertyKey(); new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {NEW_TAB_CLICK_HANDLER, public static final PropertyModel.WritableFloatPropertyKey TRANSLATION_Y =
IS_VISIBLE, LOGO_IS_VISIBLE, IS_INCOGNITO, INCOGNITO_STATE_PROVIDER, new PropertyModel.WritableFloatPropertyKey();
ACCESSIBILITY_ENABLED, MENU_IS_VISIBLE, NEW_TAB_BUTTON_IS_VISIBLE, BUTTONS_CLICKABLE,
IDENTITY_DISC_AT_START, INCOGNITO_SWITCHER_VISIBLE, NEW_TAB_BUTTON_AT_START, public static final PropertyKey[] ALL_KEYS =
IDENTITY_DISC_IS_VISIBLE, IDENTITY_DISC_CLICK_HANDLER, IDENTITY_DISC_IMAGE, new PropertyKey[] {NEW_TAB_CLICK_HANDLER, IS_VISIBLE, LOGO_IS_VISIBLE, IS_INCOGNITO,
IDENTITY_DISC_DESCRIPTION, IN_START_SURFACE_MODE, NEW_TAB_BUTTON_HIGHLIGHT}; INCOGNITO_STATE_PROVIDER, ACCESSIBILITY_ENABLED, MENU_IS_VISIBLE,
NEW_TAB_BUTTON_IS_VISIBLE, BUTTONS_CLICKABLE, IDENTITY_DISC_AT_START,
INCOGNITO_SWITCHER_VISIBLE, NEW_TAB_BUTTON_AT_START, IDENTITY_DISC_IS_VISIBLE,
IDENTITY_DISC_CLICK_HANDLER, IDENTITY_DISC_IMAGE, IDENTITY_DISC_DESCRIPTION,
IN_START_SURFACE_MODE, NEW_TAB_BUTTON_HIGHLIGHT, TRANSLATION_Y};
} }
...@@ -22,6 +22,7 @@ import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarPropert ...@@ -22,6 +22,7 @@ import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarPropert
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_HIGHLIGHT; import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_HIGHLIGHT;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_IS_VISIBLE; import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_BUTTON_IS_VISIBLE;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER; import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.NEW_TAB_CLICK_HANDLER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.TRANSLATION_Y;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -66,6 +67,8 @@ class StartSurfaceToolbarViewBinder { ...@@ -66,6 +67,8 @@ class StartSurfaceToolbarViewBinder {
view.setNewTabButtonHighlight(model.get(NEW_TAB_BUTTON_HIGHLIGHT)); view.setNewTabButtonHighlight(model.get(NEW_TAB_BUTTON_HIGHLIGHT));
} else if (propertyKey == NEW_TAB_BUTTON_IS_VISIBLE) { } else if (propertyKey == NEW_TAB_BUTTON_IS_VISIBLE) {
view.setNewTabButtonVisibility(model.get(NEW_TAB_BUTTON_IS_VISIBLE)); view.setNewTabButtonVisibility(model.get(NEW_TAB_BUTTON_IS_VISIBLE));
} else if (propertyKey == TRANSLATION_Y) {
view.setTranslationY(model.get(TRANSLATION_Y));
} }
} }
} }
...@@ -86,10 +86,4 @@ public interface Toolbar { ...@@ -86,10 +86,4 @@ public interface Toolbar {
* @return The primary color to use for the background drawable. * @return The primary color to use for the background drawable.
*/ */
int getPrimaryColor(); int getPrimaryColor();
/**
* Update the Tab switcher toolbar state.
* @param requestToShow Whether or not request showing the Tab switcher toolbar.
*/
void updateTabSwitcherToolbarState(boolean requestToShow);
} }
...@@ -114,6 +114,21 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con ...@@ -114,6 +114,21 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
} }
} }
/**
* TODO(crbug.com/1136111): Try to remove this method. ToolbarContainer's visibility should not
* be set outside this class. Please do not use this method without discussing with the owners.
*
* Sets the visibility of the toolbar_container view.
*/
@Deprecated
void setToolbarContainerVisibility(int visibility) {
mToolbarContainer.setVisibility(visibility);
// Trigger a capture when toolbar container view is set visible.
if (mToolbarContainer.isReadyForCapture()) {
invalidateBitmap();
}
}
@Override @Override
public boolean gatherTransparentRegion(Region region) { public boolean gatherTransparentRegion(Region region) {
// Reset the translation on the control container before attempting to compute the // Reset the translation on the control container before attempting to compute the
...@@ -165,7 +180,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con ...@@ -165,7 +180,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
@Override @Override
protected boolean isReadyForCapture() { protected boolean isReadyForCapture() {
return mReadyForBitmapCapture; return mReadyForBitmapCapture && getVisibility() == VISIBLE;
} }
} }
...@@ -251,7 +266,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con ...@@ -251,7 +266,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
if (mSwipeHandler == null) return false; if (mSwipeHandler == null) return false;
// Don't react on touch events if the toolbar container is not fully visible. // Don't react on touch events if the toolbar container is not fully visible.
if (!isFullyVisible()) return true; if (!isToolbarContainerFullyVisible()) return true;
// If we have ACTION_DOWN in this context, that means either no child consumed the event or // If we have ACTION_DOWN in this context, that means either no child consumed the event or
// this class is the top UI at the event position. Then, we don't need to feed the event to // this class is the top UI at the event position. Then, we don't need to feed the event to
...@@ -267,7 +282,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con ...@@ -267,7 +282,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent event) { public boolean onInterceptTouchEvent(MotionEvent event) {
if (!isFullyVisible()) return true; if (!isToolbarContainerFullyVisible()) return true;
if (mSwipeHandler == null || isOnTabStrip(event)) return false; if (mSwipeHandler == null || isOnTabStrip(event)) return false;
return mSwipeRecognizer.onTouchEvent(event); return mSwipeRecognizer.onTouchEvent(event);
...@@ -278,10 +293,11 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con ...@@ -278,10 +293,11 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
} }
/** /**
* @return Whether or not the control container is fully visible on screen. * @return Whether or not the toolbar container is fully visible on screen.
*/ */
private boolean isFullyVisible() { private boolean isToolbarContainerFullyVisible() {
return Float.compare(0f, getTranslationY()) == 0; return Float.compare(0f, getTranslationY()) == 0
&& mToolbarContainer.getVisibility() == VISIBLE;
} }
private class SwipeRecognizerImpl extends SwipeRecognizer { private class SwipeRecognizerImpl extends SwipeRecognizer {
......
...@@ -42,8 +42,8 @@ import org.chromium.chrome.browser.toolbar.menu_button.MenuButton; ...@@ -42,8 +42,8 @@ import org.chromium.chrome.browser.toolbar.menu_button.MenuButton;
import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator; import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator;
import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper; import org.chromium.chrome.browser.ui.appmenu.AppMenuButtonHelper;
import org.chromium.chrome.browser.user_education.UserEducationHelper; import org.chromium.chrome.browser.user_education.UserEducationHelper;
import org.chromium.chrome.features.start_surface.StartSurface;
import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration; import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration;
import org.chromium.chrome.features.start_surface.StartSurfaceState;
import org.chromium.components.browser_ui.widget.ClipDrawableProgressBar; import org.chromium.components.browser_ui.widget.ClipDrawableProgressBar;
import java.util.List; import java.util.List;
...@@ -91,6 +91,7 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -91,6 +91,7 @@ public class TopToolbarCoordinator implements Toolbar {
private TopToolbarOverlayCoordinator mOverlayCoordinator; private TopToolbarOverlayCoordinator mOverlayCoordinator;
private Callback<ClipDrawableProgressBar.DrawingInfo> mProgressDrawInfoCallback; private Callback<ClipDrawableProgressBar.DrawingInfo> mProgressDrawInfoCallback;
private ToolbarControlContainer mControlContainer;
/** /**
* Creates a new {@link TopToolbarCoordinator}. * Creates a new {@link TopToolbarCoordinator}.
...@@ -125,8 +126,9 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -125,8 +126,9 @@ public class TopToolbarCoordinator implements Toolbar {
ObservableSupplier<TabModelSelector> tabModelSelectorSupplier, ObservableSupplier<TabModelSelector> tabModelSelectorSupplier,
ObservableSupplier<Boolean> homeButtonVisibilitySupplier, ObservableSupplier<Boolean> homeButtonVisibilitySupplier,
ObservableSupplier<Boolean> identityDiscStateSupplier, ObservableSupplier<Boolean> identityDiscStateSupplier,
Callback<Runnable> invalidatorCallback, Supplier<ButtonData> identityDiscButtonSupplier, Callback<Runnable> invalidatorCallback,
OneshotSupplier<StartSurface> startSurfaceSupplier) { Supplier<ButtonData> identityDiscButtonSupplier) {
mControlContainer = controlContainer;
mToolbarLayout = toolbarLayout; mToolbarLayout = toolbarLayout;
mMenuButtonCoordinator = browsingModeMenuButtonCoordinator; mMenuButtonCoordinator = browsingModeMenuButtonCoordinator;
mOptionalButtonController = new OptionalBrowsingModeButtonController(buttonDataProviders, mOptionalButtonController = new OptionalBrowsingModeButtonController(buttonDataProviders,
...@@ -147,8 +149,7 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -147,8 +149,7 @@ public class TopToolbarCoordinator implements Toolbar {
controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub), controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub),
userEducationHelper, overviewModeBehaviorSupplier, userEducationHelper, overviewModeBehaviorSupplier,
identityDiscStateSupplier, overviewThemeColorProvider, identityDiscStateSupplier, overviewThemeColorProvider,
overviewModeMenuButtonCoordinator, identityDiscButtonSupplier, overviewModeMenuButtonCoordinator, identityDiscButtonSupplier);
startSurfaceSupplier);
} else { } else {
mTabSwitcherModeCoordinatorPhone = new TabSwitcherModeTTCoordinatorPhone( mTabSwitcherModeCoordinatorPhone = new TabSwitcherModeTTCoordinatorPhone(
controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub), controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub),
...@@ -287,6 +288,9 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -287,6 +288,9 @@ public class TopToolbarCoordinator implements Toolbar {
if (mTabModelSelectorSupplier != null) { if (mTabModelSelectorSupplier != null) {
mTabModelSelectorSupplier = null; mTabModelSelectorSupplier = null;
} }
if (mControlContainer != null) {
mControlContainer = null;
}
} }
@Override @Override
...@@ -313,18 +317,6 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -313,18 +317,6 @@ public class TopToolbarCoordinator implements Toolbar {
return mToolbarLayout.getToolbarDataProvider().getPrimaryColor(); return mToolbarLayout.getToolbarDataProvider().getPrimaryColor();
} }
@Override
public void updateTabSwitcherToolbarState(boolean requestToShow) {
// TODO(https://crbug.com/1041123): Investigate whether isInOverviewAndShowingOmnibox check
// is needed.
if (mStartSurfaceToolbarCoordinator == null
|| mToolbarLayout.getToolbarDataProvider() == null
|| !mToolbarLayout.getToolbarDataProvider().isInOverviewAndShowingOmnibox()) {
return;
}
mStartSurfaceToolbarCoordinator.setStartSurfaceToolbarVisibility(requestToShow);
}
@Override @Override
public void getPositionRelativeToContainer(View containerView, int[] position) { public void getPositionRelativeToContainer(View containerView, int[] position) {
mToolbarLayout.getPositionRelativeToContainer(containerView, position); mToolbarLayout.getPositionRelativeToContainer(containerView, position);
...@@ -634,6 +626,41 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -634,6 +626,41 @@ public class TopToolbarCoordinator implements Toolbar {
return mToolbarLayout.getLocationBar(); return mToolbarLayout.getLocationBar();
} }
/**
* Update the start surface toolbar state.
* @param newState New Start Surface State.
* @param requestToShow Whether or not request showing the start surface toolbar.
*/
public void updateStartSurfaceToolbarState(
@StartSurfaceState int newState, boolean requestToShow) {
if (mStartSurfaceToolbarCoordinator == null
|| mToolbarLayout.getToolbarDataProvider() == null) {
return;
}
mStartSurfaceToolbarCoordinator.onStartSurfaceStateChanged(newState, requestToShow);
updateToolbarContainerVisibility();
}
/**
* Triggered when the offset of start surface header view is changed.
* @param verticalOffset The start surface header view's offset.
*/
public void onStartSurfaceHeaderOffsetChanged(int verticalOffset) {
if (mStartSurfaceToolbarCoordinator != null) {
mStartSurfaceToolbarCoordinator.onStartSurfaceHeaderOffsetChanged(verticalOffset);
updateToolbarContainerVisibility();
}
}
private void updateToolbarContainerVisibility() {
if (mStartSurfaceToolbarCoordinator != null) {
boolean shouldHideToolbarContainer =
mStartSurfaceToolbarCoordinator.shouldHideToolbarContainer(getHeight());
mControlContainer.setToolbarContainerVisibility(
shouldHideToolbarContainer ? View.INVISIBLE : View.VISIBLE);
}
}
@Override @Override
public int getHeight() { public int getHeight() {
return mToolbarLayout.getHeight(); return mToolbarLayout.getHeight();
......
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