Commit 8c35e22c authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Add background tab colors and inactive images to the theme system.

These will eventually be used for three purposes:
(1) To allow generating different background tab images from a common tint for
    the inactive and incognito cases, thus allowing background tabs that blend
    into the frame for custom themes.
(2) To allow autogenerating the background tab colors from the background tab
    images, thus letting us autocalculate better tab text/separator/etc. colors.
(3) To allow theme authors to customize/override this behavior more precisely.

Reasons (1) and (2) dictated the design here; reason (3) is basically a free
bonus.  I thought about not making these resources overrideable by theme
authors, but there was some technical reason that turned out to not be easily
feasible, and there seems little reason to prevent it.

This also allows us to read THEME_TAB_BACKGROUND_INCOGNITO on Mac (Views).

This shouldn't result in a visual change on its own.

Bug: 862664
Change-Id: Icc57f78fd526d68b83c692fbac669a7371bb38ff
Reviewed-on: https://chromium-review.googlesource.com/1147869
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578790}
parent 2f47cacf
...@@ -435,11 +435,14 @@ ...@@ -435,11 +435,14 @@
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INACTIVE" file="mac/theme_default_inactive_background.png" /> <structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INACTIVE" file="mac/theme_default_inactive_background.png" />
<if expr="mac_views_browser"> <if expr="mac_views_browser">
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INCOGNITO" file="mac/theme_default_inactive.png" /> <structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INCOGNITO" file="mac/theme_default_inactive.png" />
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE" file="mac/theme_default_inactive_background.png" />
</if> </if>
</if> </if>
<if expr="not is_macosx"> <if expr="not is_macosx">
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND" file="notused.png" /> <structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND" file="notused.png" />
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INACTIVE" file="notused.png" />
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INCOGNITO" file="notused.png" /> <structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INCOGNITO" file="notused.png" />
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE" file="notused.png" />
</if> </if>
<structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_V" file="notused.png" /> <structure type="chrome_scaled_image" name="IDR_THEME_TAB_BACKGROUND_V" file="notused.png" />
<if expr="is_macosx"> <if expr="is_macosx">
......
...@@ -82,6 +82,8 @@ const int PRS_THEME_FRAME_OVERLAY_INACTIVE = 11; ...@@ -82,6 +82,8 @@ const int PRS_THEME_FRAME_OVERLAY_INACTIVE = 11;
const int PRS_THEME_BUTTON_BACKGROUND = 12; const int PRS_THEME_BUTTON_BACKGROUND = 12;
const int PRS_THEME_NTP_ATTRIBUTION = 13; const int PRS_THEME_NTP_ATTRIBUTION = 13;
const int PRS_THEME_WINDOW_CONTROL_BACKGROUND = 14; const int PRS_THEME_WINDOW_CONTROL_BACKGROUND = 14;
const int PRS_THEME_TAB_BACKGROUND_INACTIVE = 15;
const int PRS_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE = 16;
struct PersistingImagesTable { struct PersistingImagesTable {
// A non-changing integer ID meant to be saved in theme packs. This ID must // A non-changing integer ID meant to be saved in theme packs. This ID must
...@@ -110,10 +112,13 @@ const PersistingImagesTable kPersistingImages[] = { ...@@ -110,10 +112,13 @@ const PersistingImagesTable kPersistingImages[] = {
{PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR, "theme_toolbar"}, {PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR, "theme_toolbar"},
{PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND, {PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND,
"theme_tab_background"}, "theme_tab_background"},
#if !defined(OS_MACOSX) {PRS_THEME_TAB_BACKGROUND_INACTIVE, IDR_THEME_TAB_BACKGROUND_INACTIVE,
"theme_tab_background_inactive"},
{PRS_THEME_TAB_BACKGROUND_INCOGNITO, IDR_THEME_TAB_BACKGROUND_INCOGNITO, {PRS_THEME_TAB_BACKGROUND_INCOGNITO, IDR_THEME_TAB_BACKGROUND_INCOGNITO,
"theme_tab_background_incognito"}, "theme_tab_background_incognito"},
#endif {PRS_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE,
IDR_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE,
"theme_tab_background_incognito_inactive"},
{PRS_THEME_TAB_BACKGROUND_V, IDR_THEME_TAB_BACKGROUND_V, {PRS_THEME_TAB_BACKGROUND_V, IDR_THEME_TAB_BACKGROUND_V,
"theme_tab_background_v"}, "theme_tab_background_v"},
{PRS_THEME_NTP_BACKGROUND, IDR_THEME_NTP_BACKGROUND, {PRS_THEME_NTP_BACKGROUND, IDR_THEME_NTP_BACKGROUND,
...@@ -225,6 +230,11 @@ const StringToIntTable kColorTable[] = { ...@@ -225,6 +230,11 @@ const StringToIntTable kColorTable[] = {
{ "frame_incognito", ThemeProperties::COLOR_FRAME_INCOGNITO }, { "frame_incognito", ThemeProperties::COLOR_FRAME_INCOGNITO },
{ "frame_incognito_inactive", { "frame_incognito_inactive",
ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE }, ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE },
{ "background_tab", ThemeProperties::COLOR_BACKGROUND_TAB },
{ "background_tab_inactive", ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE },
{ "background_tab_incognito", ThemeProperties::COLOR_BACKGROUND_TAB },
{ "background_tab_incognito_inactive",
ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE },
{ "toolbar", ThemeProperties::COLOR_TOOLBAR }, { "toolbar", ThemeProperties::COLOR_TOOLBAR },
{ "tab_text", ThemeProperties::COLOR_TAB_TEXT }, { "tab_text", ThemeProperties::COLOR_TAB_TEXT },
{ "tab_background_text", ThemeProperties::COLOR_BACKGROUND_TAB_TEXT }, { "tab_background_text", ThemeProperties::COLOR_BACKGROUND_TAB_TEXT },
...@@ -1244,26 +1254,52 @@ void BrowserThemePack::CreateFrameImages(ImageCache* images) const { ...@@ -1244,26 +1254,52 @@ void BrowserThemePack::CreateFrameImages(ImageCache* images) const {
} }
void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const { void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const {
static constexpr int kTabBackgroundMap[][3] = { static constexpr struct TabValues {
{PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME, ThemeProperties::COLOR_FRAME}, // The background image to create/update.
{PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO, int tab_id;
ThemeProperties::COLOR_FRAME_INCOGNITO},
// For inactive images, the corresponding active image. If the active
// images are customized and the inactive ones are not, the inactive ones
// will be based on the active ones.
base::Optional<int> fallback_tab_id;
// The frame image to use as the base of this tab background image.
int frame_id;
// The frame color to use as the base of this tab background image.
int frame_color_id;
} kTabBackgroundMap[] = {
{PRS_THEME_TAB_BACKGROUND, base::nullopt, PRS_THEME_FRAME,
ThemeProperties::COLOR_FRAME},
{PRS_THEME_TAB_BACKGROUND_INACTIVE, PRS_THEME_TAB_BACKGROUND,
PRS_THEME_FRAME_INACTIVE, ThemeProperties::COLOR_FRAME_INACTIVE},
{PRS_THEME_TAB_BACKGROUND_INCOGNITO, base::nullopt,
PRS_THEME_FRAME_INCOGNITO, ThemeProperties::COLOR_FRAME_INCOGNITO},
{PRS_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE,
PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO_INACTIVE,
ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE},
}; };
ImageCache temp_output; ImageCache temp_output;
for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) {
int prs_id = kTabBackgroundMap[i][0]; const int tab_id = kTabBackgroundMap[i].tab_id;
ImageCache::const_iterator tab_it = images->find(tab_id);
// Inactive images should be based on the active ones if the active ones
// were customized.
if (tab_it == images->end() && kTabBackgroundMap[i].fallback_tab_id)
tab_it = images->find(*kTabBackgroundMap[i].fallback_tab_id);
// Generate background tab images when provided with custom frame or // Generate background tab images when provided with custom frame or
// background tab images; in the former case the theme author may want the // background tab images; in the former case the theme author may want the
// background tabs to appear to tint the frame, and in the latter case the // background tabs to appear to tint the frame, and in the latter case the
// provided background tab image may have transparent regions, which must be // provided background tab image may have transparent regions, which must be
// made opaque by overlaying atop the original frame. // made opaque by overlaying atop the original frame.
ImageCache::const_iterator frame_it = images->find(kTabBackgroundMap[i][1]); const ImageCache::const_iterator frame_it =
ImageCache::const_iterator tab_it = images->find(prs_id); images->find(kTabBackgroundMap[i].frame_id);
if (frame_it != images->end() || tab_it != images->end()) { if (frame_it != images->end() || tab_it != images->end()) {
SkColor background_color; SkColor frame_color;
GetColor(kTabBackgroundMap[i][2], &background_color); GetColor(kTabBackgroundMap[i].frame_color_id, &frame_color);
gfx::ImageSkia image_to_tint; gfx::ImageSkia image_to_tint;
if (frame_it != images->end()) if (frame_it != images->end())
...@@ -1285,12 +1321,12 @@ void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const { ...@@ -1285,12 +1321,12 @@ void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const {
constexpr int kRestoredTabVerticalOffset = 8; constexpr int kRestoredTabVerticalOffset = 8;
auto source = std::make_unique<TabBackgroundImageSource>( auto source = std::make_unique<TabBackgroundImageSource>(
background_color, image_to_tint, overlay, frame_color, image_to_tint, overlay,
GetTintInternal(ThemeProperties::TINT_BACKGROUND_TAB), GetTintInternal(ThemeProperties::TINT_BACKGROUND_TAB),
kRestoredTabVerticalOffset); kRestoredTabVerticalOffset);
gfx::Size dest_size = image_to_tint.size(); gfx::Size dest_size = image_to_tint.size();
dest_size.SetToMax(gfx::Size(0, kTallestTabHeight)); dest_size.SetToMax(gfx::Size(0, kTallestTabHeight));
temp_output[prs_id] = temp_output[tab_id] =
gfx::Image(gfx::ImageSkia(std::move(source), dest_size)); gfx::Image(gfx::ImageSkia(std::move(source), dest_size));
} }
} }
......
...@@ -285,13 +285,20 @@ void BrowserThemePackTest::VerifyStarGazing(BrowserThemePack* pack) { ...@@ -285,13 +285,20 @@ void BrowserThemePackTest::VerifyStarGazing(BrowserThemePack* pack) {
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_OVERLAY_INACTIVE)); EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_OVERLAY_INACTIVE));
EXPECT_TRUE(pack->GetImageNamed(IDR_THEME_FRAME_OVERLAY_INACTIVE).IsEmpty()); EXPECT_TRUE(pack->GetImageNamed(IDR_THEME_FRAME_OVERLAY_INACTIVE).IsEmpty());
#if !defined(OS_MACOSX) // The incognito and inactive tab background images are missing, but will
// The tab background image is missing, but will still be generated in // still be generated in CreateTabBackgroundImages based on the frame
// CreateTabBackgroundImages based on IDR_THEME_FRAME. // images.
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INCOGNITO)); EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INACTIVE));
EXPECT_FALSE( EXPECT_FALSE(
pack->GetImageNamed(IDR_THEME_TAB_BACKGROUND_INCOGNITO).IsEmpty()); pack->GetImageNamed(IDR_THEME_TAB_BACKGROUND_INACTIVE).IsEmpty());
#endif EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INCOGNITO));
EXPECT_FALSE(
pack->GetImageNamed(IDR_THEME_TAB_BACKGROUND_INCOGNITO).IsEmpty());
EXPECT_FALSE(
pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE));
EXPECT_FALSE(
pack->GetImageNamed(IDR_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE)
.IsEmpty());
// Make sure we don't have phantom data. // Make sure we don't have phantom data.
EXPECT_FALSE(pack->GetColor(TP::COLOR_CONTROL_BACKGROUND, &color)); EXPECT_FALSE(pack->GetColor(TP::COLOR_CONTROL_BACKGROUND, &color));
...@@ -412,6 +419,10 @@ SkColor BrowserThemePackTest::GetDefaultColor(int id) { ...@@ -412,6 +419,10 @@ SkColor BrowserThemePackTest::GetDefaultColor(int id) {
return TP::GetDefaultColor(TP::COLOR_FRAME, true); return TP::GetDefaultColor(TP::COLOR_FRAME, true);
case TP::COLOR_FRAME_INCOGNITO_INACTIVE: case TP::COLOR_FRAME_INCOGNITO_INACTIVE:
return TP::GetDefaultColor(TP::COLOR_FRAME_INACTIVE, true); return TP::GetDefaultColor(TP::COLOR_FRAME_INACTIVE, true);
case TP::COLOR_BACKGROUND_TAB_INCOGNITO:
return TP::GetDefaultColor(TP::COLOR_BACKGROUND_TAB, true);
case TP::COLOR_BACKGROUND_TAB_INCOGNITO_INACTIVE:
return TP::GetDefaultColor(TP::COLOR_BACKGROUND_TAB_INACTIVE, true);
default: default:
return TP::GetDefaultColor(id, false); return TP::GetDefaultColor(id, false);
} }
......
...@@ -34,6 +34,10 @@ const SkColor kDefaultColorFrameIncognito = ...@@ -34,6 +34,10 @@ const SkColor kDefaultColorFrameIncognito =
SkColorSetARGB(0xE6, 0x14, 0x16, 0x18); SkColorSetARGB(0xE6, 0x14, 0x16, 0x18);
const SkColor kDefaultColorFrameIncognitoInactive = const SkColor kDefaultColorFrameIncognitoInactive =
SkColorSetRGB(0x1E, 0x1E, 0x1E); SkColorSetRGB(0x1E, 0x1E, 0x1E);
const SkColor kDefaultColorTabBackgroundInactive =
SkColorSetRGB(0xEC, 0xEC, 0xEC);
const SkColor kDefaultColorTabBackgroundInactiveIncognito =
SkColorSetRGB(0x28, 0x28, 0x28);
#else #else
const SkColor kDefaultColorFrameIncognito = SkColorSetRGB(0x28, 0x2B, 0x2D); const SkColor kDefaultColorFrameIncognito = SkColorSetRGB(0x28, 0x2B, 0x2D);
const SkColor kDefaultColorFrameIncognitoInactive = const SkColor kDefaultColorFrameIncognitoInactive =
...@@ -110,10 +114,6 @@ const SkColor kDefaultColorFrameVibrancyOverlayIncognito = ...@@ -110,10 +114,6 @@ const SkColor kDefaultColorFrameVibrancyOverlayIncognito =
const SkColor kDefaultColorToolbarInactive = SkColorSetRGB(0xF6, 0xF6, 0xF6); const SkColor kDefaultColorToolbarInactive = SkColorSetRGB(0xF6, 0xF6, 0xF6);
const SkColor kDefaultColorToolbarInactiveIncognito = const SkColor kDefaultColorToolbarInactiveIncognito =
SkColorSetRGB(0x2D, 0x2D, 0x2D); SkColorSetRGB(0x2D, 0x2D, 0x2D);
const SkColor kDefaultColorTabBackgroundInactive =
SkColorSetRGB(0xEC, 0xEC, 0xEC);
const SkColor kDefaultColorTabBackgroundInactiveIncognito =
SkColorSetRGB(0x28, 0x28, 0x28);
const SkColor kDefaultColorToolbarButtonStroke = const SkColor kDefaultColorToolbarButtonStroke =
SkColorSetARGB(0x4B, 0x51, 0x51, 0x51); SkColorSetARGB(0x4B, 0x51, 0x51, 0x51);
const SkColor kDefaultColorToolbarButtonStrokeInactive = const SkColor kDefaultColorToolbarButtonStrokeInactive =
...@@ -155,6 +155,7 @@ base::Optional<SkColor> MaybeGetDefaultColorForNewerMaterialUi(int id, ...@@ -155,6 +155,7 @@ base::Optional<SkColor> MaybeGetDefaultColorForNewerMaterialUi(int id,
case ThemeProperties::COLOR_BACKGROUND_TAB: case ThemeProperties::COLOR_BACKGROUND_TAB:
return incognito ? gfx::kGoogleGrey900 : SkColorSetRGB(0xDE, 0xE1, 0xE6); return incognito ? gfx::kGoogleGrey900 : SkColorSetRGB(0xDE, 0xE1, 0xE6);
case ThemeProperties::COLOR_FRAME_INACTIVE: case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE:
return incognito ? gfx::kGoogleGrey800 : SkColorSetRGB(0xE7, 0xEA, 0xED); return incognito ? gfx::kGoogleGrey800 : SkColorSetRGB(0xE7, 0xEA, 0xED);
case ThemeProperties::COLOR_TOOLBAR: case ThemeProperties::COLOR_TOOLBAR:
return incognito ? SkColorSetRGB(0x32, 0x36, 0x39) : SK_ColorWHITE; return incognito ? SkColorSetRGB(0x32, 0x36, 0x39) : SK_ColorWHITE;
...@@ -376,6 +377,8 @@ SkColor ThemeProperties::GetDefaultColor(int id, bool incognito) { ...@@ -376,6 +377,8 @@ SkColor ThemeProperties::GetDefaultColor(int id, bool incognito) {
case COLOR_FRAME_INCOGNITO: case COLOR_FRAME_INCOGNITO:
case COLOR_FRAME_INCOGNITO_INACTIVE: case COLOR_FRAME_INCOGNITO_INACTIVE:
case COLOR_BACKGROUND_TAB_INCOGNITO:
case COLOR_BACKGROUND_TAB_INCOGNITO_INACTIVE:
NOTREACHED() << "These values should be queried via their respective " NOTREACHED() << "These values should be queried via their respective "
"non-incognito equivalents and an appropriate " "non-incognito equivalents and an appropriate "
"|incognito| value."; "|incognito| value.";
......
...@@ -30,9 +30,14 @@ class ThemeProperties { ...@@ -30,9 +30,14 @@ class ThemeProperties {
COLOR_FRAME_INACTIVE, COLOR_FRAME_INACTIVE,
// Instead of using the INCOGNITO variants directly, most code should // Instead of using the INCOGNITO variants directly, most code should
// use the original color ID in an incognito-aware context (such as // use the original color ID in an incognito-aware context (such as
// GetDefaultColor). // GetDefaultColor). This comment applies to other properties tagged
// INCOGNITO below as well.
COLOR_FRAME_INCOGNITO, COLOR_FRAME_INCOGNITO,
COLOR_FRAME_INCOGNITO_INACTIVE, COLOR_FRAME_INCOGNITO_INACTIVE,
COLOR_BACKGROUND_TAB,
COLOR_BACKGROUND_TAB_INACTIVE,
COLOR_BACKGROUND_TAB_INCOGNITO,
COLOR_BACKGROUND_TAB_INCOGNITO_INACTIVE,
COLOR_TOOLBAR, COLOR_TOOLBAR,
COLOR_TAB_TEXT, COLOR_TAB_TEXT,
COLOR_BACKGROUND_TAB_TEXT, COLOR_BACKGROUND_TAB_TEXT,
...@@ -103,9 +108,6 @@ class ThemeProperties { ...@@ -103,9 +108,6 @@ class ThemeProperties {
// shelf. // shelf.
COLOR_TOOLBAR_VERTICAL_SEPARATOR, COLOR_TOOLBAR_VERTICAL_SEPARATOR,
// The color of a background tab, as well as the new tab button.
COLOR_BACKGROUND_TAB,
// The color of the "instructions text" in an empty bookmarks bar. // The color of the "instructions text" in an empty bookmarks bar.
COLOR_BOOKMARK_BAR_INSTRUCTIONS_TEXT, COLOR_BOOKMARK_BAR_INSTRUCTIONS_TEXT,
...@@ -144,7 +146,6 @@ class ThemeProperties { ...@@ -144,7 +146,6 @@ class ThemeProperties {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
COLOR_FRAME_VIBRANCY_OVERLAY, COLOR_FRAME_VIBRANCY_OVERLAY,
COLOR_TOOLBAR_INACTIVE, COLOR_TOOLBAR_INACTIVE,
COLOR_BACKGROUND_TAB_INACTIVE,
COLOR_TOOLBAR_BEZEL, COLOR_TOOLBAR_BEZEL,
COLOR_TOOLBAR_STROKE, COLOR_TOOLBAR_STROKE,
COLOR_TOOLBAR_STROKE_INACTIVE, COLOR_TOOLBAR_STROKE_INACTIVE,
......
...@@ -115,6 +115,10 @@ int GetIncognitoId(int id) { ...@@ -115,6 +115,10 @@ int GetIncognitoId(int id) {
return ThemeProperties::COLOR_FRAME_INCOGNITO; return ThemeProperties::COLOR_FRAME_INCOGNITO;
case ThemeProperties::COLOR_FRAME_INACTIVE: case ThemeProperties::COLOR_FRAME_INACTIVE:
return ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE; return ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE;
case ThemeProperties::COLOR_BACKGROUND_TAB:
return ThemeProperties::COLOR_BACKGROUND_TAB_INCOGNITO;
case ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE:
return ThemeProperties::COLOR_BACKGROUND_TAB_INCOGNITO_INACTIVE;
default: default:
return id; return id;
} }
...@@ -482,7 +486,8 @@ SkColor ThemeService::GetDefaultColor(int id, bool incognito) const { ...@@ -482,7 +486,8 @@ SkColor ThemeService::GetDefaultColor(int id, bool incognito) const {
GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito), GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito),
0x4D); 0x4D);
} }
case ThemeProperties::COLOR_BACKGROUND_TAB: { case ThemeProperties::COLOR_BACKGROUND_TAB:
case ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE: {
// Touchable hardcodes the background tab color. This can break custom // Touchable hardcodes the background tab color. This can break custom
// themes, but touchable is replaced by touchable refresh, which doesn't // themes, but touchable is replaced by touchable refresh, which doesn't
// use the default background tab color at all, so this issue won't be // use the default background tab color at all, so this issue won't be
......
...@@ -126,12 +126,19 @@ SkColor BrowserNonClientFrameView::GetTabSeparatorColor() const { ...@@ -126,12 +126,19 @@ SkColor BrowserNonClientFrameView::GetTabSeparatorColor() const {
} }
SkColor BrowserNonClientFrameView::GetTabBackgroundColor(TabState state) const { SkColor BrowserNonClientFrameView::GetTabBackgroundColor(TabState state) const {
if (state == TAB_INACTIVE && MD::IsRefreshUi()) if (state == TAB_ACTIVE)
return GetFrameColor(); return GetThemeOrDefaultColor(ThemeProperties::COLOR_TOOLBAR);
const auto color_id = state == TAB_ACTIVE
? ThemeProperties::COLOR_TOOLBAR const int color_id = ShouldPaintAsActive()
: ThemeProperties::COLOR_BACKGROUND_TAB; ? ThemeProperties::COLOR_BACKGROUND_TAB
return GetThemeOrDefaultColor(color_id); : ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE;
const ui::ThemeProvider* tp = GetThemeProvider();
// When the background tab color has not been customized, use the actual frame
// color instead of COLOR_BACKGROUND_TAB; these will differ for single-tab
// mode and custom window frame colors.
return (MD::IsRefreshUi() && !tp->HasCustomColor(color_id))
? GetFrameColor()
: GetThemeOrDefaultColor(color_id);
} }
SkColor BrowserNonClientFrameView::GetTabForegroundColor(TabState state) const { SkColor BrowserNonClientFrameView::GetTabForegroundColor(TabState state) const {
...@@ -152,6 +159,31 @@ SkColor BrowserNonClientFrameView::GetTabForegroundColor(TabState state) const { ...@@ -152,6 +159,31 @@ SkColor BrowserNonClientFrameView::GetTabForegroundColor(TabState state) const {
return GetThemeOrDefaultColor(color_id); return GetThemeOrDefaultColor(color_id);
} }
int BrowserNonClientFrameView::GetTabBackgroundResourceId(
bool* has_custom_image) const {
const ui::ThemeProvider* tp = GetThemeProvider();
const bool incognito = browser_view_->IsIncognito();
const bool active = ShouldPaintAsActive();
const int active_id =
incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND;
const int inactive_id =
incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO_INACTIVE
: IDR_THEME_TAB_BACKGROUND_INACTIVE;
const int id = active ? active_id : inactive_id;
// tp->HasCustomImage() will only return true if the supplied ID has been
// customized directly. We also account for the following fallback cases:
// * The inactive images are copied directly from the active ones if present
// * Tab backgrounds are generated from frame backgrounds if present, and
// * The incognito frame image is generated from the normal frame image, so
// in incognito mode we look at both.
*has_custom_image =
tp->HasCustomImage(id) || (!active && tp->HasCustomImage(active_id)) ||
tp->HasCustomImage(IDR_THEME_FRAME) ||
(incognito && tp->HasCustomImage(IDR_THEME_FRAME_INCOGNITO));
return id;
}
views::Button* BrowserNonClientFrameView::GetProfileSwitcherButton() const { views::Button* BrowserNonClientFrameView::GetProfileSwitcherButton() const {
return profile_switcher_.avatar_button(); return profile_switcher_.avatar_button();
} }
......
...@@ -96,6 +96,14 @@ class BrowserNonClientFrameView : public views::NonClientFrameView, ...@@ -96,6 +96,14 @@ class BrowserNonClientFrameView : public views::NonClientFrameView,
// |state| of the tab and the activation state of the window. // |state| of the tab and the activation state of the window.
SkColor GetTabForegroundColor(TabState state) const; SkColor GetTabForegroundColor(TabState state) const;
// For non-transparent windows, returns the resource ID to use behind
// background tabs. |has_custom_image| will be set to true if this has been
// customized by the theme in some way. Note that because of fallback during
// image generation, |has_custom_image| may be true even when the returned
// background resource ID has not been directly overridden (i.e.
// ThemeProvider::HasCustomImage() returns false).
int GetTabBackgroundResourceId(bool* has_custom_image) const;
// Updates the throbber. // Updates the throbber.
virtual void UpdateThrobber(bool running) = 0; virtual void UpdateThrobber(bool running) = 0;
......
...@@ -398,6 +398,11 @@ SkColor BrowserTabStripController::GetTabForegroundColor(TabState state) const { ...@@ -398,6 +398,11 @@ SkColor BrowserTabStripController::GetTabForegroundColor(TabState state) const {
return GetFrameView()->GetTabForegroundColor(state); return GetFrameView()->GetTabForegroundColor(state);
} }
int BrowserTabStripController::GetTabBackgroundResourceId(
bool* has_custom_image) const {
return GetFrameView()->GetTabBackgroundResourceId(has_custom_image);
}
base::string16 BrowserTabStripController::GetAccessibleTabName( base::string16 BrowserTabStripController::GetAccessibleTabName(
const Tab* tab) const { const Tab* tab) const {
return browser_view_->GetAccessibleTabLabel( return browser_view_->GetAccessibleTabLabel(
......
...@@ -79,6 +79,7 @@ class BrowserTabStripController : public TabStripController, ...@@ -79,6 +79,7 @@ class BrowserTabStripController : public TabStripController,
SkColor GetTabSeparatorColor() const override; SkColor GetTabSeparatorColor() const override;
SkColor GetTabBackgroundColor(TabState active) const override; SkColor GetTabBackgroundColor(TabState active) const override;
SkColor GetTabForegroundColor(TabState state) const override; SkColor GetTabForegroundColor(TabState state) const override;
int GetTabBackgroundResourceId(bool* has_custom_image) const override;
base::string16 GetAccessibleTabName(const Tab* tab) const override; base::string16 GetAccessibleTabName(const Tab* tab) const override;
Profile* GetProfile() const override; Profile* GetProfile() const override;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/ui/views/tabs/tab_renderer_data.h" #include "chrome/browser/ui/views/tabs/tab_renderer_data.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/grit/theme_resources.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
FakeBaseTabStripController::FakeBaseTabStripController() {} FakeBaseTabStripController::FakeBaseTabStripController() {}
...@@ -163,6 +164,12 @@ SkColor FakeBaseTabStripController::GetTabForegroundColor( ...@@ -163,6 +164,12 @@ SkColor FakeBaseTabStripController::GetTabForegroundColor(
return gfx::kPlaceholderColor; return gfx::kPlaceholderColor;
} }
int FakeBaseTabStripController::GetTabBackgroundResourceId(
bool* has_custom_image) const {
*has_custom_image = false;
return IDR_THEME_TAB_BACKGROUND;
}
base::string16 FakeBaseTabStripController::GetAccessibleTabName( base::string16 FakeBaseTabStripController::GetAccessibleTabName(
const Tab* tab) const { const Tab* tab) const {
return base::string16(); return base::string16();
......
...@@ -55,6 +55,7 @@ class FakeBaseTabStripController : public TabStripController { ...@@ -55,6 +55,7 @@ class FakeBaseTabStripController : public TabStripController {
SkColor GetTabSeparatorColor() const override; SkColor GetTabSeparatorColor() const override;
SkColor GetTabBackgroundColor(TabState state) const override; SkColor GetTabBackgroundColor(TabState state) const override;
SkColor GetTabForegroundColor(TabState state) const override; SkColor GetTabForegroundColor(TabState state) const override;
int GetTabBackgroundResourceId(bool* has_custom_image) const override;
base::string16 GetAccessibleTabName(const Tab* tab) const override; base::string16 GetAccessibleTabName(const Tab* tab) const override;
Profile* GetProfile() const override; Profile* GetProfile() const override;
......
...@@ -155,7 +155,7 @@ class TabController { ...@@ -155,7 +155,7 @@ class TabController {
// Returns the resource ID for the image to use as the tab background. // Returns the resource ID for the image to use as the tab background.
// |custom_image| is an outparam set to true if either the tab or the frame // |custom_image| is an outparam set to true if either the tab or the frame
// background images have been customized; see implementation comments. // background images have been customized; see implementation comments.
virtual int GetBackgroundResourceId(bool* custom_image) const = 0; virtual int GetBackgroundResourceId(bool* has_custom_image) const = 0;
// If the given tab is animating to its target destination, this returns the // If the given tab is animating to its target destination, this returns the
// target bounds. If the tab isn't moving this will return the current bounds // target bounds. If the tab isn't moving this will return the current bounds
......
...@@ -1172,28 +1172,13 @@ base::string16 TabStrip::GetAccessibleTabName(const Tab* tab) const { ...@@ -1172,28 +1172,13 @@ base::string16 TabStrip::GetAccessibleTabName(const Tab* tab) const {
return base::string16(); return base::string16();
} }
int TabStrip::GetBackgroundResourceId(bool* custom_image) const { int TabStrip::GetBackgroundResourceId(bool* has_custom_image) const {
const ui::ThemeProvider* tp = GetThemeProvider(); if (!TitlebarBackgroundIsTransparent())
return controller_->GetTabBackgroundResourceId(has_custom_image);
if (TitlebarBackgroundIsTransparent()) {
const int kBackgroundIdGlass = IDR_THEME_TAB_BACKGROUND_V; constexpr int kBackgroundIdGlass = IDR_THEME_TAB_BACKGROUND_V;
*custom_image = tp->HasCustomImage(kBackgroundIdGlass); *has_custom_image = GetThemeProvider()->HasCustomImage(kBackgroundIdGlass);
return kBackgroundIdGlass; return kBackgroundIdGlass;
}
// If a custom theme does not provide a replacement tab background, but does
// provide a replacement frame image, HasCustomImage() on the tab background
// ID will return false, but the theme provider will make a custom image from
// the frame image. Furthermore, since the theme provider will create the
// incognito frame image from the normal frame image, in incognito mode we
// need to look for a custom incognito _or_ regular frame image.
const bool incognito = IsIncognito();
const int id =
incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND;
*custom_image = tp->HasCustomImage(id) ||
tp->HasCustomImage(IDR_THEME_FRAME) ||
(incognito && tp->HasCustomImage(IDR_THEME_FRAME_INCOGNITO));
return id;
} }
gfx::Rect TabStrip::GetTabAnimationTargetBounds(const Tab* tab) { gfx::Rect TabStrip::GetTabAnimationTargetBounds(const Tab* tab) {
......
...@@ -262,7 +262,7 @@ class TabStrip : public views::View, ...@@ -262,7 +262,7 @@ class TabStrip : public views::View,
SkColor GetTabBackgroundColor(TabState state) const override; SkColor GetTabBackgroundColor(TabState state) const override;
SkColor GetTabForegroundColor(TabState state) const override; SkColor GetTabForegroundColor(TabState state) const override;
base::string16 GetAccessibleTabName(const Tab* tab) const override; base::string16 GetAccessibleTabName(const Tab* tab) const override;
int GetBackgroundResourceId(bool* custom_image) const override; int GetBackgroundResourceId(bool* has_custom_image) const override;
gfx::Rect GetTabAnimationTargetBounds(const Tab* tab) override; gfx::Rect GetTabAnimationTargetBounds(const Tab* tab) override;
// MouseWatcherListener: // MouseWatcherListener:
......
...@@ -131,6 +131,14 @@ class TabStripController { ...@@ -131,6 +131,14 @@ class TabStripController {
// of the tab and the activation state of the window. // of the tab and the activation state of the window.
virtual SkColor GetTabForegroundColor(TabState state) const = 0; virtual SkColor GetTabForegroundColor(TabState state) const = 0;
// For non-transparent windows, returns the resource ID to use behind
// background tabs. |has_custom_image| will be set to true if this has been
// customized by the theme in some way. Note that because of fallback during
// image generation, |has_custom_image| may be true even when the returned
// background resource ID has not been directly overridden (i.e.
// ThemeProvider::HasCustomImage() returns false).
virtual int GetTabBackgroundResourceId(bool* has_custom_image) const = 0;
// Returns the accessible tab name. // Returns the accessible tab name.
virtual base::string16 GetAccessibleTabName(const Tab* tab) const = 0; virtual base::string16 GetAccessibleTabName(const Tab* tab) const = 0;
......
...@@ -91,8 +91,8 @@ class FakeTabController : public TabController { ...@@ -91,8 +91,8 @@ class FakeTabController : public TabController {
SkColor GetTabForegroundColor(TabState state) const override { SkColor GetTabForegroundColor(TabState state) const override {
return gfx::kPlaceholderColor; return gfx::kPlaceholderColor;
} }
int GetBackgroundResourceId(bool* custom_image) const override { int GetBackgroundResourceId(bool* has_custom_image) const override {
*custom_image = false; *has_custom_image = false;
return IDR_THEME_TAB_BACKGROUND; return IDR_THEME_TAB_BACKGROUND;
} }
gfx::Rect GetTabAnimationTargetBounds(const Tab* tab) override { gfx::Rect GetTabAnimationTargetBounds(const Tab* tab) override {
......
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