Commit a91ffca6 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Make HasCustomColor() match GetColor().

The latter has various transformations around when it queries the underlying
the provider and with what constants.  Use this behavior in HasCustomColor()
too.  This ensures callers get consistent behavior in these cases.

Along the way this changes a multi-arm conditional to a helper function.
That isn't necessary for this patch, but it will make it easy to land
subsequent ones that add more such constants.

Bug: 862664
Change-Id: I83295902f7c38767c3a051a40e5f195f8e78e4ef
Reviewed-on: https://chromium-review.googlesource.com/1147601
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577703}
parent 6f2dc3ac
...@@ -107,6 +107,19 @@ void WritePackToDiskCallback(BrowserThemePack* pack, ...@@ -107,6 +107,19 @@ void WritePackToDiskCallback(BrowserThemePack* pack,
false); false);
} }
// For legacy reasons, the theme supplier requires the incognito variants of
// color IDs. This converts from normal to incognito IDs where they exist.
int GetIncognitoId(int id) {
switch (id) {
case ThemeProperties::COLOR_FRAME:
return ThemeProperties::COLOR_FRAME_INCOGNITO;
case ThemeProperties::COLOR_FRAME_INACTIVE:
return ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE;
default:
return id;
}
}
// Heuristic to determine if color is grayscale. This is used to decide whether // Heuristic to determine if color is grayscale. This is used to decide whether
// to use the colorful or white logo, if a theme fails to specify which. // to use the colorful or white logo, if a theme fails to specify which.
bool IsColorGrayscale(SkColor color) { bool IsColorGrayscale(SkColor color) {
...@@ -156,7 +169,9 @@ bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const { ...@@ -156,7 +169,9 @@ bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const {
} }
bool ThemeService::BrowserThemeProvider::HasCustomColor(int id) const { bool ThemeService::BrowserThemeProvider::HasCustomColor(int id) const {
return theme_service_.HasCustomColor(id); bool has_custom_color = false;
theme_service_.GetColor(id, incognito_, &has_custom_color);
return has_custom_color;
} }
base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData( base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData(
...@@ -721,9 +736,14 @@ gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const { ...@@ -721,9 +736,14 @@ gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const {
return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); return const_cast<gfx::ImageSkia*>(image.ToImageSkia());
} }
SkColor ThemeService::GetColor(int id, bool incognito) const { SkColor ThemeService::GetColor(int id,
bool incognito,
bool* has_custom_color) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (has_custom_color)
*has_custom_color = false;
// The incognito NTP always uses the default background color, unless there is // The incognito NTP always uses the default background color, unless there is
// a custom NTP background image. See also https://crbug.com/21798#c114. // a custom NTP background image. See also https://crbug.com/21798#c114.
if (id == ThemeProperties::COLOR_NTP_BACKGROUND && incognito && if (id == ThemeProperties::COLOR_NTP_BACKGROUND && incognito &&
...@@ -731,19 +751,13 @@ SkColor ThemeService::GetColor(int id, bool incognito) const { ...@@ -731,19 +751,13 @@ SkColor ThemeService::GetColor(int id, bool incognito) const {
return ThemeProperties::GetDefaultColor(id, incognito); return ThemeProperties::GetDefaultColor(id, incognito);
} }
// For legacy reasons, |theme_supplier_| requires the incognito variants
// of color IDs.
int theme_supplier_id = id;
if (incognito) {
if (id == ThemeProperties::COLOR_FRAME)
theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO;
else if (id == ThemeProperties::COLOR_FRAME_INACTIVE)
theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE;
}
SkColor color; SkColor color;
if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color)) const int theme_supplier_id = incognito ? GetIncognitoId(id) : id;
if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color)) {
if (has_custom_color)
*has_custom_color = true;
return color; return color;
}
return GetDefaultColor(id, incognito); return GetDefaultColor(id, incognito);
} }
...@@ -775,11 +789,6 @@ int ThemeService::GetDisplayProperty(int id) const { ...@@ -775,11 +789,6 @@ int ThemeService::GetDisplayProperty(int id) const {
} }
} }
bool ThemeService::HasCustomColor(int id) const {
SkColor color;
return theme_supplier_ && theme_supplier_->GetColor(id, &color);
}
base::RefCountedMemory* ThemeService::GetRawData( base::RefCountedMemory* ThemeService::GetRawData(
int id, int id,
ui::ScaleFactor scale_factor) const { ui::ScaleFactor scale_factor) const {
......
...@@ -247,9 +247,10 @@ class ThemeService : public content::NotificationObserver, public KeyedService { ...@@ -247,9 +247,10 @@ class ThemeService : public content::NotificationObserver, public KeyedService {
// These methods provide the implementation for ui::ThemeProvider (exposed // These methods provide the implementation for ui::ThemeProvider (exposed
// via BrowserThemeProvider). // via BrowserThemeProvider).
gfx::ImageSkia* GetImageSkiaNamed(int id, bool incognito) const; gfx::ImageSkia* GetImageSkiaNamed(int id, bool incognito) const;
SkColor GetColor(int id, bool incognito) const; SkColor GetColor(int id,
bool incognito,
bool* has_custom_color = nullptr) const;
int GetDisplayProperty(int id) const; int GetDisplayProperty(int id) const;
bool HasCustomColor(int id) const;
base::RefCountedMemory* GetRawData(int id, base::RefCountedMemory* GetRawData(int id,
ui::ScaleFactor scale_factor) const; ui::ScaleFactor scale_factor) const;
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
......
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