Commit bac9e16f authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Explicitly set scrim in location bar

Since the scrim is now created programmatically, it takes a bit of
extra time after chrome starts to be able to get access to it. In
the case of the location bar, its design allows users to focus it
prior to the rest of chrome being loaded. Because of this, it is
possible to get the omnibox focused without the scrim, locking up
the page under it. This change explicitly sets the scrim when it
becomes available in ChromeActivity and then calls the scrim update
method in case it is needed.

Bug: 850848
Change-Id: Ia0a25a0c6e8f9c2d64c914ebca5bbcf9e14601ad
Reviewed-on: https://chromium-review.googlesource.com/1101963
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568579}
parent d1d82748
......@@ -1423,6 +1423,10 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
findViewById(R.id.keyboard_accessory_stub),
findViewById(R.id.keyboard_accessory_sheet_stub));
if (mToolbarManager != null && mToolbarManager.getToolbar() != null) {
mToolbarManager.getToolbar().setScrim(mFadingBackgroundView);
}
if (supportsContextualSuggestionsBottomSheet()
&& FeatureUtilities.isContextualSuggestionsBottomSheetEnabled(isTablet())) {
getLayoutInflater().inflate(R.layout.bottom_sheet, coordinator);
......
......@@ -17,6 +17,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.Toolbar;
import org.chromium.chrome.browser.toolbar.ToolbarActionModeCallback;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.chrome.browser.widget.FadingBackgroundView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.ui.base.WindowAndroid;
......@@ -193,4 +194,9 @@ public interface LocationBar extends UrlBarDelegate {
* to it, used to avoid text overlapping the buttons and vice versa.
*/
int getUrlContainerMarginEnd();
/**
* @param scrim The scrim for this location bar to use.
*/
void setScrim(FadingBackgroundView scrim);
}
......@@ -2016,6 +2016,16 @@ public class LocationBarLayout
}
}
@Override
public void setScrim(FadingBackgroundView scrim) {
mFadingView = scrim;
// In some cases, users can start chrome and immediately start tapping the omnibox. In that
// case, the omnibox will focus, but there is no scrim. This checks if the scrim needs to
// be visible and updates it accordingly.
updateFadingBackgroundView(isUrlBarFocused(), true);
}
/**
* Update the fading background view that shows when the omnibox is focused. If Chrome Home is
* enabled, this method is a no-op.
......@@ -2024,15 +2034,10 @@ public class LocationBarLayout
* scrim.
*/
protected void updateFadingBackgroundView(boolean visible, boolean ignoreNtpChecks) {
if (mFadingView == null) {
// Some uses of the location bar do not have a tab backing them (like SearchActivity).
if (getCurrentTab() == null || getCurrentTab().getActivity() == null) return;
mFadingView = getCurrentTab().getActivity().getFadingBackgroundView();
}
if (mFadingView == null) return;
NewTabPage ntp = mToolbarDataProvider.getNewTabPageForCurrentTab();
boolean locationBarShownInNTP = ntp != null && ntp.isLocationBarShownInNTP();
if (mFadingView != null) {
if (visible && (!locationBarShownInNTP || ignoreNtpChecks)) {
// If the location bar is shown in the NTP, the toolbar will eventually trigger a
// fade in.
......@@ -2041,7 +2046,6 @@ public class LocationBarLayout
mFadingView.hideFadingOverlay(!locationBarShownInNTP);
}
}
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
......
......@@ -54,6 +54,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.widget.FadingBackgroundView;
import org.chromium.chrome.browser.widget.TintedDrawable;
import org.chromium.chrome.browser.widget.TintedImageButton;
import org.chromium.components.url_formatter.UrlFormatter;
......@@ -820,4 +821,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
public int getUrlContainerMarginEnd() {
return 0;
}
@Override
public void setScrim(FadingBackgroundView scrim) {}
}
......@@ -8,6 +8,7 @@ import android.graphics.Rect;
import android.view.View;
import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
import org.chromium.chrome.browser.widget.FadingBackgroundView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
/**
......@@ -111,4 +112,9 @@ public interface Toolbar {
* @return height of the tab strip in px.
*/
int getTabStripHeight();
/**
* @param scrim The scrim for this location bar to use.
*/
void setScrim(FadingBackgroundView scrim);
}
......@@ -40,6 +40,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.FadingBackgroundView;
import org.chromium.chrome.browser.widget.PulseDrawable;
import org.chromium.chrome.browser.widget.TintedImageButton;
import org.chromium.chrome.browser.widget.ToolbarProgressBar;
......@@ -978,4 +979,9 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
ntpButton.setImageResource(iconResId);
}
@Override
public void setScrim(FadingBackgroundView scrim) {
getLocationBar().setScrim(scrim);
}
}
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