Commit 002c66ed authored by chuanl's avatar chuanl Committed by Commit Bot

Enable hiding top bar by setting its height to zero.

Bug: 882404
Change-Id: Iaa93ed3b96a70ba78fff6bc711eb0404b52f179f
Reviewed-on: https://chromium-review.googlesource.com/c/1412397Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: John Lin <chuanl@google.com>
Cr-Commit-Position: refs/heads/master@{#625355}
parent 89c17cb8
......@@ -40,7 +40,12 @@ public class CustomTabTopBarDelegate {
getTopBarView().addView(mTopBarContentView);
}
if (mTopBarContentView != null) {
mTopBarContentView.setVisibility(isVisible ? View.VISIBLE : View.GONE);
if (mTopBarHeight != null && mTopBarHeight == 0) {
// Hide the top bar when its height is specifically set to 0.
mTopBarContentView.setVisibility(View.GONE);
} else {
mTopBarContentView.setVisibility(isVisible ? View.VISIBLE : View.GONE);
}
}
}
......
......@@ -413,15 +413,22 @@ public class DynamicModuleCoordinator implements NativeInitObserver, Destroyable
public void setTopBarHeight(int height) {
mTopBarDelegate.get().setTopBarHeight(height);
maybeCustomizeCctHeader(mIntentDataProvider.getUrlToLoad());
maybeCustomizeCctHeader(getContentUrl());
}
private String getContentUrl() {
Tab tab = mTabController.getTab();
if (tab != null && tab.getWebContents() != null && !tab.getWebContents().isDestroyed()
&& tab.getWebContents().getLastCommittedUrl() != null) {
return tab.getWebContents().getLastCommittedUrl();
}
return mIntentDataProvider.getUrlToLoad();
}
private int getTopBarHeight() {
Integer topBarHeight = mTopBarDelegate.get().getTopBarHeight();
// Custom top bar height must not be too small compared to the default top control container
// height, nor shall it be larger than the height of the web content.
// Custom top bar height must not be larger than the height of the web content.
if (topBarHeight != null && topBarHeight >= 0
&& topBarHeight > mDefaultTopControlContainerHeight / 2
&& mActivity.getWindow() != null
&& topBarHeight < mActivity.getWindow().getDecorView().getHeight() / 2) {
return topBarHeight;
......@@ -441,6 +448,19 @@ public class DynamicModuleCoordinator implements NativeInitObserver, Destroyable
mIntentDataProvider.getSession());
}
private View getProgressBarAnchorView(boolean isModuleManagedUrl) {
View anchorView = null;
if (isModuleManagedUrl) {
View topBarContentView = mTopBarDelegate.get().getTopBarContentView();
if (topBarContentView != null && topBarContentView.getVisibility() == View.VISIBLE) {
anchorView = topBarContentView;
}
} else {
anchorView = mActivity.getToolbarManager().getToolbarView();
}
return anchorView;
}
private void maybeCustomizeCctHeader(String url) {
if (!isModuleLoaded() && !isModuleLoading()) return;
......@@ -453,9 +473,8 @@ public class DynamicModuleCoordinator implements NativeInitObserver, Destroyable
isModuleManagedUrl ? View.GONE : mDefaultToolbarShadowVisibility);
mFullscreenManager.get().setTopControlsHeight(
isModuleManagedUrl ? getTopBarHeight() : mDefaultTopControlContainerHeight);
mActivity.getToolbarManager().setProgressBarAnchorView(isModuleManagedUrl
? mTopBarDelegate.get().getTopBarContentView()
: mActivity.getToolbarManager().getToolbarView());
mActivity.getToolbarManager().setProgressBarAnchorView(
getProgressBarAnchorView(isModuleManagedUrl));
}
}
......
......@@ -422,7 +422,8 @@ public class ChromeFullscreenManager
if (mControlsPosition == ControlsPosition.NONE) return;
if (getTopControlsHeight() == 0) {
mControlOffsetRatio = 0;
// Treat the case of 0 height as controls being totally offscreen.
mControlOffsetRatio = 1.0f;
} else {
mControlOffsetRatio =
Math.abs((float) mRendererTopControlOffset / getTopControlsHeight());
......
......@@ -463,6 +463,27 @@ public class CustomTabsDynamicModuleUITest {
});
}
@Test
@SmallTest
@Features.EnableFeatures({
ChromeFeatureList.CCT_MODULE, ChromeFeatureList.CCT_MODULE_CUSTOM_HEADER,
ChromeFeatureList.CCT_MODULE_USE_INTENT_EXTRAS})
public void testSetTopBarHeight_zeroHeightHidesTopBar() throws Exception {
Intent intent = new IntentBuilder(mModuleManagedPage)
.setModuleManagedUrlRegex(getModuleManagedRegex())
.build();
mActivityRule.startCustomTabActivityWithIntent(intent);
waitForModuleLoading();
runOnUiThreadBlocking(() -> {
CustomTabActivity cctActivity = getActivity();
View anyView = new View(cctActivity);
getModuleCoordinator().setTopBarContentView(anyView);
getModuleCoordinator().setTopBarHeight(0);
assertEquals(View.GONE, anyView.getVisibility());
});
}
@Test
@SmallTest
@Features.EnableFeatures(ChromeFeatureList.CCT_MODULE_USE_INTENT_EXTRAS)
......
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