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;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.supplier.OneshotSupplierImpl;
......@@ -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
public void addStateChangeObserver(StateObserver observer) {
mStartSurfaceMediator.addStateChangeObserver(observer);
......
......@@ -6,6 +6,8 @@ package org.chromium.chrome.features.start_surface;
import android.os.SystemClock;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
......@@ -36,6 +38,20 @@ public interface StartSurface {
@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.
*/
......
......@@ -21,7 +21,7 @@
android:layout_height="@dimen/toolbar_height_no_shadow"
android:background="@android:color/transparent"
android:orientation="vertical"
app:layout_scrollFlags="scroll">
app:layout_scrollFlags="scroll|enterAlways|snap">
</LinearLayout>
<LinearLayout
android:id="@+id/scroll_component_container"
......
......@@ -10,6 +10,8 @@ import android.view.ViewGroup;
import androidx.annotation.Nullable;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.ntp.FakeboxDelegate;
......@@ -75,4 +77,17 @@ public interface TasksSurface {
* require native initialization should be constructed here.
*/
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;
import androidx.annotation.Nullable;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.app.ChromeActivity;
......@@ -163,4 +165,16 @@ public class TasksSurfaceCoordinator implements TasksSurface {
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 {
void setTrendyTermsVisibility(boolean isVisible) {
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;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.ActionBar;
import com.google.android.material.appbar.AppBarLayout;
import org.chromium.base.Callback;
import org.chromium.base.CallbackController;
import org.chromium.base.TraceEvent;
......@@ -214,6 +216,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
private StartSurface mStartSurface;
private StartSurface.StateObserver mStartSurfaceStateObserver;
private AppBarLayout.OnOffsetChangedListener mStartSurfaceHeaderOffsetChangeListener;
private OneshotSupplier<IntentMetadata> mIntentMetadataOneshotSupplier;
private OneshotSupplier<Boolean> mPromoShownOneshotSupplier;
......@@ -357,7 +360,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mToolbar = createTopToolbarCoordinator(controlContainer, toolbarLayout, buttonDataProviders,
browsingModeThemeColorProvider, startSurfaceMenuButtonCoordinator, invalidator,
identityDiscController, startSurfaceSupplier);
identityDiscController);
mActionModeController =
new ActionModeController(mActivity, mActionBarDelegate, toolbarActionModeCallback);
......@@ -666,9 +669,16 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mStartSurface = startSurface;
mStartSurfaceStateObserver = (newState, shouldShowToolbar) -> {
assert StartSurfaceConfiguration.isStartSurfaceEnabled();
mToolbar.updateTabSwitcherToolbarState(shouldShowToolbar);
mStartSurfaceState = newState;
mToolbar.updateStartSurfaceToolbarState(newState, shouldShowToolbar);
};
mStartSurface.addStateChangeObserver(mStartSurfaceStateObserver);
mStartSurfaceHeaderOffsetChangeListener = (appbarLayout, verticalOffset) -> {
assert StartSurfaceConfiguration.isStartSurfaceEnabled();
mToolbar.onStartSurfaceHeaderOffsetChanged(verticalOffset);
};
mStartSurface.addHeaderOffsetChangeListener(mStartSurfaceHeaderOffsetChangeListener);
}));
TraceEvent.end("ToolbarManager.ToolbarManager");
......@@ -679,26 +689,20 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
List<ButtonDataProvider> buttonDataProviders,
ThemeColorProvider browsingModeThemeColorProvider,
MenuButtonCoordinator startSurfaceMenuButtonCoordinator, Invalidator invalidator,
IdentityDiscController identityDiscController,
OneshotSupplier<StartSurface> startSurfaceSupplier) {
IdentityDiscController identityDiscController) {
TopToolbarCoordinator toolbar = new TopToolbarCoordinator(controlContainer, toolbarLayout,
mLocationBarModel, mToolbarTabController,
new UserEducationHelper(mActivity, mHandler, TrackerFactory::getTrackerForProfile),
buttonDataProviders, mOverviewModeBehaviorSupplier, browsingModeThemeColorProvider,
mAppThemeColorProvider, mMenuButtonCoordinator, startSurfaceMenuButtonCoordinator,
mMenuButtonCoordinator.getMenuButtonHelperSupplier(), mTabModelSelectorSupplier,
mHomeButtonVisibilitySupplier, mIdentityDiscStateSupplier,
(client)
-> {
mHomeButtonVisibilitySupplier, mIdentityDiscStateSupplier, (client) -> {
if (invalidator != null) {
invalidator.invalidate(client);
} else {
client.run();
}
},
()
-> identityDiscController.getForStartSurface(mStartSurfaceState),
startSurfaceSupplier);
}, () -> identityDiscController.getForStartSurface(mStartSurfaceState));
mHomepageStateListener = () -> {
mHomeButtonVisibilitySupplier.set(HomepageManager.isHomepageEnabled());
mHomepageManagedByPolicySupplier.set(HomepagePolicyManager.isHomepageManagedByPolicy());
......@@ -1026,8 +1030,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
if (mStartSurface != null) {
mStartSurface.removeStateChangeObserver(mStartSurfaceStateObserver);
mStartSurface.removeHeaderOffsetChangeListener(mStartSurfaceHeaderOffsetChangeListener);
mStartSurface = null;
mStartSurfaceStateObserver = null;
mStartSurfaceHeaderOffsetChangeListener = null;
}
mActivity.unregisterComponentCallbacks(mComponentCallbacks);
......
......@@ -28,8 +28,8 @@ import org.chromium.chrome.browser.toolbar.TabSwitcherButtonView;
import org.chromium.chrome.browser.toolbar.ThemeColorProvider;
import org.chromium.chrome.browser.toolbar.menu_button.MenuButtonCoordinator;
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.StartSurfaceState;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
......@@ -60,8 +60,7 @@ public class StartSurfaceToolbarCoordinator {
OneshotSupplier<OverviewModeBehavior> overviewModeBehaviorSupplier,
ObservableSupplier<Boolean> identityDiscStateSupplier, ThemeColorProvider provider,
MenuButtonCoordinator menuButtonCoordinator,
Supplier<ButtonData> identityDiscButtonSupplier,
OneshotSupplier<StartSurface> startSurfaceSupplier) {
Supplier<ButtonData> identityDiscButtonSupplier) {
mStub = startSurfaceToolbarStub;
overviewModeBehaviorSupplier.onAvailable(
......@@ -96,8 +95,7 @@ public class StartSurfaceToolbarCoordinator {
StartSurfaceConfiguration.START_SURFACE_HIDE_INCOGNITO_SWITCH_NO_TAB.getValue(),
StartSurfaceConfiguration.START_SURFACE_HIDE_INCOGNITO_SWITCH.getValue(),
StartSurfaceConfiguration.START_SURFACE_SHOW_STACK_TAB_SWITCHER.getValue(),
menuButtonCoordinator, identityDiscStateSupplier, identityDiscButtonSupplier,
startSurfaceSupplier);
menuButtonCoordinator, identityDiscStateSupplier, identityDiscButtonSupplier);
mThemeColorProvider = provider;
mMenuButtonCoordinator = menuButtonCoordinator;
......@@ -161,14 +159,6 @@ public class StartSurfaceToolbarCoordinator {
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.
* @param enabled whether accessibility status is enabled.
......@@ -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() {
// 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.
......
......@@ -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_IS_VISIBLE;
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;
......@@ -29,7 +30,6 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.Callback;
import org.chromium.base.CallbackController;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.compositor.layouts.EmptyOverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
......@@ -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.user_education.IPHCommandBuilder;
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.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -68,16 +67,14 @@ class StartSurfaceToolbarMediator {
private int mOverviewModeState;
private boolean mIsGoogleSearchEngine;
private StartSurface mStartSurface;
private StartSurface.StateObserver mStartSurfaceStateObserver;
private CallbackController mCallbackController = new CallbackController();
private float mNonIncognitoHomepageTranslationY;
StartSurfaceToolbarMediator(PropertyModel model, Callback<IPHCommandBuilder> showIPHCallback,
boolean hideIncognitoSwitchWhenNoTabs, boolean hideIncognitoSwitchOnHomePage,
boolean showNewTabAndIdentityDiscAtStart, MenuButtonCoordinator menuButtonCoordinator,
ObservableSupplier<Boolean> identityDiscStateSupplier,
Supplier<ButtonData> identityDiscButtonSupplier,
OneshotSupplier<StartSurface> startSurfaceSupplier) {
Supplier<ButtonData> identityDiscButtonSupplier) {
mPropertyModel = model;
mOverviewModeState = StartSurfaceState.NOT_SHOWN;
mShowIPHCallback = showIPHCallback;
......@@ -91,20 +88,6 @@ class StartSurfaceToolbarMediator {
if (!canShowHint && !mPropertyModel.get(IDENTITY_DISC_IS_VISIBLE)) return;
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() {
......@@ -132,15 +115,37 @@ class StartSurfaceToolbarMediator {
if (mOverviewModeObserver != null) {
mOverviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver);
}
if (mStartSurface != null) {
mStartSurface.removeStateChangeObserver(mStartSurfaceStateObserver);
}
if (mCallbackController != null) {
mCallbackController.destroy();
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) {
mPropertyModel.set(NEW_TAB_CLICK_HANDLER, listener);
}
......@@ -286,6 +291,19 @@ class StartSurfaceToolbarMediator {
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
@StartSurfaceState
int getOverviewModeStateForTesting() {
......
......@@ -66,10 +66,14 @@ class StartSurfaceToolbarProperties {
public static final PropertyModel.WritableBooleanPropertyKey NEW_TAB_BUTTON_AT_START =
new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {NEW_TAB_CLICK_HANDLER,
IS_VISIBLE, LOGO_IS_VISIBLE, IS_INCOGNITO, 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};
public static final PropertyModel.WritableFloatPropertyKey TRANSLATION_Y =
new PropertyModel.WritableFloatPropertyKey();
public static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {NEW_TAB_CLICK_HANDLER, IS_VISIBLE, LOGO_IS_VISIBLE, IS_INCOGNITO,
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
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_CLICK_HANDLER;
import static org.chromium.chrome.browser.toolbar.top.StartSurfaceToolbarProperties.TRANSLATION_Y;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -66,6 +67,8 @@ class StartSurfaceToolbarViewBinder {
view.setNewTabButtonHighlight(model.get(NEW_TAB_BUTTON_HIGHLIGHT));
} else if (propertyKey == 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 {
* @return The primary color to use for the background drawable.
*/
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
}
}
/**
* 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
public boolean gatherTransparentRegion(Region region) {
// Reset the translation on the control container before attempting to compute the
......@@ -165,7 +180,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
@Override
protected boolean isReadyForCapture() {
return mReadyForBitmapCapture;
return mReadyForBitmapCapture && getVisibility() == VISIBLE;
}
}
......@@ -251,7 +266,7 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
if (mSwipeHandler == null) return false;
// 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
// 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
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!isFullyVisible()) return true;
if (!isToolbarContainerFullyVisible()) return true;
if (mSwipeHandler == null || isOnTabStrip(event)) return false;
return mSwipeRecognizer.onTouchEvent(event);
......@@ -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() {
return Float.compare(0f, getTranslationY()) == 0;
private boolean isToolbarContainerFullyVisible() {
return Float.compare(0f, getTranslationY()) == 0
&& mToolbarContainer.getVisibility() == VISIBLE;
}
private class SwipeRecognizerImpl extends SwipeRecognizer {
......
......@@ -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.ui.appmenu.AppMenuButtonHelper;
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.StartSurfaceState;
import org.chromium.components.browser_ui.widget.ClipDrawableProgressBar;
import java.util.List;
......@@ -91,6 +91,7 @@ public class TopToolbarCoordinator implements Toolbar {
private TopToolbarOverlayCoordinator mOverlayCoordinator;
private Callback<ClipDrawableProgressBar.DrawingInfo> mProgressDrawInfoCallback;
private ToolbarControlContainer mControlContainer;
/**
* Creates a new {@link TopToolbarCoordinator}.
......@@ -125,8 +126,9 @@ public class TopToolbarCoordinator implements Toolbar {
ObservableSupplier<TabModelSelector> tabModelSelectorSupplier,
ObservableSupplier<Boolean> homeButtonVisibilitySupplier,
ObservableSupplier<Boolean> identityDiscStateSupplier,
Callback<Runnable> invalidatorCallback, Supplier<ButtonData> identityDiscButtonSupplier,
OneshotSupplier<StartSurface> startSurfaceSupplier) {
Callback<Runnable> invalidatorCallback,
Supplier<ButtonData> identityDiscButtonSupplier) {
mControlContainer = controlContainer;
mToolbarLayout = toolbarLayout;
mMenuButtonCoordinator = browsingModeMenuButtonCoordinator;
mOptionalButtonController = new OptionalBrowsingModeButtonController(buttonDataProviders,
......@@ -147,8 +149,7 @@ public class TopToolbarCoordinator implements Toolbar {
controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub),
userEducationHelper, overviewModeBehaviorSupplier,
identityDiscStateSupplier, overviewThemeColorProvider,
overviewModeMenuButtonCoordinator, identityDiscButtonSupplier,
startSurfaceSupplier);
overviewModeMenuButtonCoordinator, identityDiscButtonSupplier);
} else {
mTabSwitcherModeCoordinatorPhone = new TabSwitcherModeTTCoordinatorPhone(
controlContainer.getRootView().findViewById(R.id.tab_switcher_toolbar_stub),
......@@ -287,6 +288,9 @@ public class TopToolbarCoordinator implements Toolbar {
if (mTabModelSelectorSupplier != null) {
mTabModelSelectorSupplier = null;
}
if (mControlContainer != null) {
mControlContainer = null;
}
}
@Override
......@@ -313,18 +317,6 @@ public class TopToolbarCoordinator implements Toolbar {
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
public void getPositionRelativeToContainer(View containerView, int[] position) {
mToolbarLayout.getPositionRelativeToContainer(containerView, position);
......@@ -634,6 +626,41 @@ public class TopToolbarCoordinator implements Toolbar {
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
public int 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