Commit 26abb730 authored by Lijin Shen's avatar Lijin Shen Committed by Commit Bot

Fix URL bar background flash on swiping tabs and entering/exiting tab switcher

The background of URL bar is not displayed on swiping tabs or entering/existing
tab switcher. This CL is trying to correct location bar background color by
detecting whether it is an NTP and location bar is on top of the NTP or not.

Bug: 874101
Change-Id: I6749d0829839cf753a99e1663e6c0565bd9bf279
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1887655
Commit-Queue: Lijin Shen <lazzzis@google.com>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712207}
parent 5c8985fc
......@@ -35,7 +35,6 @@ import org.chromium.chrome.browser.compositor.scene_layer.ToolbarSceneLayer;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManagementDelegate;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.native_page.NativePageFactory;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.tab.SadTab;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.Tab.TabHidingType;
......@@ -650,15 +649,11 @@ public class LayoutManager implements LayoutUpdateHost, LayoutProvider,
boolean canUseLiveTexture = tab.getWebContents() != null && !SadTab.isShowing(tab)
&& !isNativePage && !tab.isHidden();
boolean isNtp = tab.getNativePage() instanceof NewTabPage;
boolean isLocationBarShownInNtp =
isNtp && ((NewTabPage) tab.getNativePage()).isLocationBarShownInNTP();
boolean needsUpdate = layoutTab.initFromHost(TabThemeColorHelper.getBackgroundColor(tab),
shouldStall(tab), canUseLiveTexture,
ToolbarColors.getToolbarSceneLayerBackground(tab),
ToolbarColors.getTextBoxColorForToolbarBackground(mContext.getResources(),
isLocationBarShownInNtp, themeColor, tab.isIncognito()),
ToolbarColors.getTextBoxColorForToolbarBackground(
mContext.getResources(), tab, themeColor),
ToolbarColors.getTextBoxAlphaForToolbarBackground(tab));
if (needsUpdate) requestUpdate();
......
......@@ -19,8 +19,6 @@ import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter;
import org.chromium.chrome.browser.compositor.overlays.SceneOverlay;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.ControlContainer;
import org.chromium.chrome.browser.toolbar.ToolbarColors;
import org.chromium.chrome.browser.ui.widget.ClipDrawableProgressBar.DrawingInfo;
......@@ -105,24 +103,11 @@ public class ToolbarSceneLayer extends SceneOverlayLayer implements SceneOverlay
boolean showShadow = fullscreenManager.drawControlsAsTexture()
|| forceHideAndroidBrowserControls;
boolean isLocationBarShownInNtp = false;
boolean isIncognito = false;
Tab currentTab = fullscreenManager.getTab();
if (currentTab != null) {
boolean isNtp =
currentTab != null ? currentTab.getNativePage() instanceof NewTabPage : false;
if (isNtp) {
isLocationBarShownInNtp =
((NewTabPage) currentTab.getNativePage()).isLocationBarShownInNTP();
}
isIncognito = currentTab.isIncognito();
}
int textBoxColor =
ToolbarColors.getTextBoxColorForToolbarBackground(mContext.getResources(),
isLocationBarShownInNtp, browserControlsBackgroundColor, isIncognito);
int textBoxResourceId = R.drawable.modern_location_bar;
fullscreenManager.getTab(), browserControlsBackgroundColor);
int textBoxResourceId = R.drawable.modern_location_bar;
ToolbarSceneLayerJni.get().updateToolbarLayer(mNativePtr, ToolbarSceneLayer.this,
resourceManager, R.id.control_container, browserControlsBackgroundColor,
textBoxResourceId, browserControlsUrlBarAlpha, textBoxColor,
......
......@@ -549,6 +549,13 @@ public class NewTabPage implements NativePage, InvalidationAwareThumbnailProvide
return mNewTabPageManager.isLocationBarShownInNTP();
}
/**
* @return Whether the location bar has been scrolled to top in the NTP.
*/
public boolean isLocationBarScrolledToTopInNtp() {
return mNewTabPageLayout.getToolbarTransitionPercentage() == 1;
}
/**
* Sets the listener for search box scroll changes.
* @param listener The listener to be notified on changes.
......
......@@ -380,7 +380,7 @@ public class NewTabPageLayout extends LinearLayout implements TileGroup.Observer
*
* @return the transition percentage
*/
private float getToolbarTransitionPercentage() {
float getToolbarTransitionPercentage() {
// During startup the view may not be fully initialized.
if (!mScrollDelegate.isScrollViewInitialized()) return 0f;
......
......@@ -624,6 +624,7 @@ public class Tab {
* no current page or the current page is displayed using something besides
* {@link NativePage}.
*/
@Nullable
public NativePage getNativePage() {
return mNativePage;
}
......
......@@ -12,6 +12,7 @@ import android.support.v7.content.res.AppCompatResources;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
......@@ -28,17 +29,37 @@ public class ToolbarColors {
private static final float LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA = 0.2f;
/**
* Determine the text box color based on the current toolbar background color.
* Determine the text box background color given the current tab.
* @param res {@link Resources} used to retrieve colors.
* @param isLocationBarShownInNtp Whether the location bar is currently shown in an NTP. Note
* that this should be false if the returned text box color is
* not used in an NTP.
* @param tab The current {@link Tab}
* @param color The color of the toolbar background.
* @param isIncognito Whether or not the color is used for incognito mode.
* @return The base color for the textbox given a toolbar background color.
*/
public static int getTextBoxColorForToolbarBackground(
Resources res, boolean isLocationBarShownInNtp, int color, boolean isIncognito) {
Resources res, @Nullable Tab tab, int color) {
boolean isIncognito = tab != null && tab.isIncognito();
if (tab != null && tab.getNativePage() instanceof NewTabPage) {
NewTabPage page = (NewTabPage) tab.getNativePage();
if (page.isLocationBarShownInNTP()) {
return page.isLocationBarScrolledToTopInNtp()
? ApiCompatibilityUtils.getColor(res, R.color.toolbar_text_box_background)
: ChromeColors.getPrimaryBackgroundColor(res, false);
}
}
return ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(
res, color, isIncognito);
}
/**
* Determine the text box background color given a toolbar background color
* @param res {@link Resources} used to retrieve colors.
* @param color The color of the toolbar background.
* @param isIncognito Whether or not the color is used for incognito mode.
* @return The base color for the textbox given a toolbar background color.
*/
public static int getTextBoxColorForToolbarBackgroundInNonNativePage(
Resources res, int color, boolean isIncognito) {
// Text box color on default toolbar background in incognito mode is a pre-defined
// color. We calculate the equivalent opaque color from the pre-defined translucent color.
if (isIncognito) {
......@@ -49,10 +70,6 @@ public class ToolbarColors {
return ColorUtils.getColorWithOverlay(color, overlayColorOpaque, overlayColorAlpha);
}
// NTP should have no visible text box in the toolbar, so just return the NTP
// background color.
if (isLocationBarShownInNtp) return ChromeColors.getPrimaryBackgroundColor(res, false);
// Text box color on default toolbar background in standard mode is a pre-defined
// color instead of a calculated color.
if (isUsingDefaultToolbarColor(res, false, color)) {
......
......@@ -137,7 +137,7 @@ class BottomToolbarNewTabButton extends ChromeImageButton
if (mThemeColorProvider == null || mIncognitoStateProvider == null) return;
mBackground.setColorFilter(
ToolbarColors.getTextBoxColorForToolbarBackground(mResources, false,
ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(mResources,
mThemeColorProvider.getThemeColor(),
mThemeColorProvider.useLight()
&& mIncognitoStateProvider.isIncognitoSelected()),
......
......@@ -123,8 +123,8 @@ class SearchAccelerator extends ChromeImageButton
private void updateBackground() {
if (mThemeColorProvider == null || mIncognitoStateProvider == null) return;
mBackground.setColorFilter(ToolbarColors.getTextBoxColorForToolbarBackground(mResources,
false, mThemeColorProvider.getThemeColor(),
mBackground.setColorFilter(ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(
mResources, mThemeColorProvider.getThemeColor(),
mIncognitoStateProvider.isIncognitoSelected()),
PorterDuff.Mode.SRC_IN);
}
......
......@@ -433,8 +433,8 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
* @return The location bar color.
*/
private int getLocationBarColorForToolbarColor(int toolbarColor) {
return ToolbarColors.getTextBoxColorForToolbarBackground(
getResources(), false, toolbarColor, isIncognito());
return ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(
getResources(), toolbarColor, isIncognito());
}
private void inflateTabSwitchingResources() {
......
......@@ -387,8 +387,8 @@ public class ToolbarTablet extends ToolbarLayout
@Override
public void onThemeColorChanged(int color, boolean shouldAnimate) {
setBackgroundColor(color);
final int textBoxColor = ToolbarColors.getTextBoxColorForToolbarBackground(
getResources(), false, color, isIncognito());
final int textBoxColor = ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(
getResources(), color, isIncognito());
mLocationBar.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN);
mLocationBar.updateVisualsForState();
......
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