Commit 044181e6 authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

[Home] Ensure toolbar is visible before expanding sheet

This change forces the toolbar to be shown in cases where it is hidden
and the bottom sheet is opened.

BUG=741320

Change-Id: Iad9ff71e0e71ae15c50f6db02bf194db4d97131b
Reviewed-on: https://chromium-review.googlesource.com/576198Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488268}
parent a5440da5
...@@ -59,6 +59,7 @@ import org.chromium.chrome.browser.widget.textbubble.ViewAnchoredTextBubble; ...@@ -59,6 +59,7 @@ import org.chromium.chrome.browser.widget.textbubble.ViewAnchoredTextBubble;
import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.BrowserStartupController;
import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.ContentViewCore;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.common.BrowserControlsState;
import org.chromium.ui.UiUtils; import org.chromium.ui.UiUtils;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -523,6 +524,7 @@ public class BottomSheet ...@@ -523,6 +524,7 @@ public class BottomSheet
if (!isSheetOpen() && tab != null && !tab.canGoBack() && !isInOverviewMode() if (!isSheetOpen() && tab != null && !tab.canGoBack() && !isInOverviewMode()
&& tab.getLaunchType() == TabLaunchType.FROM_CHROME_UI) { && tab.getLaunchType() == TabLaunchType.FROM_CHROME_UI) {
mBackButtonDismissesChrome = true; mBackButtonDismissesChrome = true;
setSheetState(SHEET_STATE_HALF, true); setSheetState(SHEET_STATE_HALF, true);
return true; return true;
} else if (isSheetOpen() && !mBackButtonDismissesChrome) { } else if (isSheetOpen() && !mBackButtonDismissesChrome) {
...@@ -674,7 +676,8 @@ public class BottomSheet ...@@ -674,7 +676,8 @@ public class BottomSheet
/** /**
* @return Whether or not the toolbar Android View is hidden due to being scrolled off-screen. * @return Whether or not the toolbar Android View is hidden due to being scrolled off-screen.
*/ */
private boolean isToolbarAndroidViewHidden() { @VisibleForTesting
public boolean isToolbarAndroidViewHidden() {
return mFullscreenManager == null || mFullscreenManager.getBottomControlOffset() > 0 return mFullscreenManager == null || mFullscreenManager.getBottomControlOffset() > 0
|| mControlContainer.getVisibility() != VISIBLE; || mControlContainer.getVisibility() != VISIBLE;
} }
...@@ -1030,6 +1033,12 @@ public class BottomSheet ...@@ -1030,6 +1033,12 @@ public class BottomSheet
private void onSheetOpened() { private void onSheetOpened() {
if (mIsSheetOpen) return; if (mIsSheetOpen) return;
// Make sure the toolbar is visible before expanding the sheet.
Tab tab = getActiveTab();
if (isToolbarAndroidViewHidden() && tab != null) {
tab.updateBrowserControlsState(BrowserControlsState.SHOWN, false);
}
mIsSheetOpen = true; mIsSheetOpen = true;
dismissSelectedText(); dismissSelectedText();
for (BottomSheetObserver o : mObservers) o.onSheetOpened(); for (BottomSheetObserver o : mObservers) o.onSheetOpened();
......
...@@ -168,6 +168,30 @@ public class BottomSheetBackBehaviorTest { ...@@ -168,6 +168,30 @@ public class BottomSheetBackBehaviorTest {
assertFalse("Chrome should no longer have focus.", mActivity.hasWindowFocus()); assertFalse("Chrome should no longer have focus.", mActivity.hasWindowFocus());
} }
@Test
@SmallTest
public void testBackButton_backButtonOpensSheetAndShowsToolbar()
throws ExecutionException, InterruptedException, TimeoutException {
final Tab tab = launchNewTabFromChrome("about:blank");
assertEquals("Tab should be on about:blank.", "about:blank", tab.getUrl());
assertEquals("The bottom sheet should be peeking.", BottomSheet.SHEET_STATE_PEEK,
mBottomSheet.getSheetState());
// This also waits for the controls to be hidden.
hideBrowserControls(tab);
// Back button press should open the bottom sheet since backward navigation is not
// possible and show the toolbar.
pressBackButton();
endBottomSheetAnimations();
waitForShownBrowserControls();
assertEquals("The bottom sheet should be at half height.", BottomSheet.SHEET_STATE_HALF,
mBottomSheet.getSheetState());
}
@Test @Test
@SmallTest @SmallTest
public void testBackButton_backWithNavigation() public void testBackButton_backWithNavigation()
...@@ -260,6 +284,39 @@ public class BottomSheetBackBehaviorTest { ...@@ -260,6 +284,39 @@ public class BottomSheetBackBehaviorTest {
}); });
} }
/**
* Wait for the browser controls to be hidden.
* @param tab The active tab.
*/
private void hideBrowserControls(final Tab tab) throws ExecutionException {
// Hide the browser controls.
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
tab.getActivity().getFullscreenManager().setHideBrowserControlsAndroidView(true);
}
});
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return mBottomSheet.isToolbarAndroidViewHidden();
}
});
}
/**
* Wait for the browser controls to be shown.
*/
private void waitForShownBrowserControls() throws ExecutionException {
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return !mBottomSheet.isToolbarAndroidViewHidden();
}
});
}
/** Notify the activity that the hardware back button was pressed. */ /** Notify the activity that the hardware back button was pressed. */
private void pressBackButton() { private void pressBackButton() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
......
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