Commit c7ebb01e authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Chromium LUCI CQ

Toolbar: Fix wrong location bar background color

The theme color for location bar background should come from a specified
tab, not the current theme color from TopUiThemeColorProvider. This
addresses the wrong color when multiple tabs are being presented
such as in tab switcher.

This CL makes TUTCP#calculateColor public to get the right theme color
for a given tab object.

Bug: 1157417, 1157433
Change-Id: I10c30a7fc93bf9a21b0d113847651c4138a3c02e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2589135Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837338}
parent 590d9ba3
...@@ -805,8 +805,8 @@ public class LayoutManagerImpl implements LayoutManager, LayoutUpdateHost, Layou ...@@ -805,8 +805,8 @@ public class LayoutManagerImpl implements LayoutManager, LayoutUpdateHost, Layou
TopUiThemeColorProvider topUiTheme = mTopUiThemeColorProvider.get(); TopUiThemeColorProvider topUiTheme = mTopUiThemeColorProvider.get();
layoutTab.initFromHost(topUiTheme.getBackgroundColor(tab), shouldStall(tab), layoutTab.initFromHost(topUiTheme.getBackgroundColor(tab), shouldStall(tab),
canUseLiveTexture, topUiTheme.getSceneLayerBackground(tab), canUseLiveTexture, topUiTheme.getSceneLayerBackground(tab),
ToolbarColors.getTextBoxColorForToolbarBackground( ToolbarColors.getTextBoxColorForToolbarBackground(mContext.getResources(), tab,
mContext.getResources(), tab, topUiTheme.getThemeColor()), topUiTheme.calculateColor(tab, tab.getThemeColor())),
topUiTheme.getTextBoxBackgroundAlpha(tab)); topUiTheme.getTextBoxBackgroundAlpha(tab));
mHost.requestRender(); mHost.requestRender();
......
...@@ -374,8 +374,8 @@ public class StaticLayout extends Layout { ...@@ -374,8 +374,8 @@ public class StaticLayout extends Layout {
return sToolbarTextBoxBackgroundColorForTesting; return sToolbarTextBoxBackgroundColorForTesting;
} }
return ToolbarColors.getTextBoxColorForToolbarBackground( return ToolbarColors.getTextBoxColorForToolbarBackground(mContext.getResources(), tab,
mContext.getResources(), tab, mTopUiThemeColorProvider.get().getThemeColor()); mTopUiThemeColorProvider.get().calculateColor(tab, tab.getThemeColor()));
} }
@VisibleForTesting @VisibleForTesting
......
...@@ -56,11 +56,11 @@ public class TopUiThemeColorProvider extends ThemeColorProvider { ...@@ -56,11 +56,11 @@ public class TopUiThemeColorProvider extends ThemeColorProvider {
mTabObserver = new CurrentTabObserver(tabSupplier, new EmptyTabObserver() { mTabObserver = new CurrentTabObserver(tabSupplier, new EmptyTabObserver() {
@Override @Override
public void onDidChangeThemeColor(Tab tab, int themeColor) { public void onDidChangeThemeColor(Tab tab, int themeColor) {
updateColor(tab, themeColor, false); updateColor(tab, themeColor, true);
} }
}); });
tabSupplier.addObserver((tab) -> { tabSupplier.addObserver((tab) -> {
if (tab != null) updateColor(tab, tab.getThemeColor(), true); if (tab != null) updateColor(tab, tab.getThemeColor(), false);
}); });
mActivityThemeColorSupplier = activityThemeColorSupplier; mActivityThemeColorSupplier = activityThemeColorSupplier;
mIsTabletSupplier = isTabletSupplier; mIsTabletSupplier = isTabletSupplier;
...@@ -80,7 +80,13 @@ public class TopUiThemeColorProvider extends ThemeColorProvider { ...@@ -80,7 +80,13 @@ public class TopUiThemeColorProvider extends ThemeColorProvider {
mIsDefaultColorUsed = isUsingDefaultColor(tab, themeColor); mIsDefaultColorUsed = isUsingDefaultColor(tab, themeColor);
} }
private int calculateColor(Tab tab, int themeColor) { /**
* Calculate theme color to be used for a given tab.
* @param tab Tab to get the theme color for.
* @param themeColor Initial color to calculate the theme color with.
* @return Final theme color for a given tab, with other signals taken into account.
*/
public int calculateColor(Tab tab, int themeColor) {
// This method is used not only for the current tab but also for // This method is used not only for the current tab but also for
// any given tab. Therefore it should not alter any class state. // any given tab. Therefore it should not alter any class state.
boolean isThemingAllowed = isThemingAllowed(tab); boolean isThemingAllowed = isThemingAllowed(tab);
......
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