Skip to content

Commit

Permalink
Move HasCustomColor from Mac-only to all platforms
Browse files Browse the repository at this point in the history
This CL is in preparation for making other changes related to how theme
colors will be handled. By moving HasCustomColor(), the code can now
make more intelligent decisions on how colors are selected or created
for maximum contrast and readability. Ultimately, a poorly designed theme
can still lead to an unreadable UI.

Bug: none
Change-Id: Id2d6e212a5b83f40eb49c527804bb42eebb24c6e
Reviewed-on: https://chromium-review.googlesource.com/1129637
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573720}
  • Loading branch information
Allen Bauer authored and Commit Bot committed Jul 10, 2018
1 parent 216b18a commit cd4b788
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
9 changes: 9 additions & 0 deletions chrome/browser/themes/theme_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ bool ThemeService::BrowserThemeProvider::HasCustomImage(int id) const {
return theme_service_.HasCustomImage(id);
}

bool ThemeService::BrowserThemeProvider::HasCustomColor(int id) const {
return theme_service_.HasCustomColor(id);
}

base::RefCountedMemory* ThemeService::BrowserThemeProvider::GetRawData(
int id,
ui::ScaleFactor scale_factor) const {
Expand Down Expand Up @@ -767,6 +771,11 @@ 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(
int id,
ui::ScaleFactor scale_factor) const {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/themes/theme_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ class ThemeService : public content::NotificationObserver, public KeyedService {
int GetDisplayProperty(int id) const override;
bool ShouldUseNativeFrame() const override;
bool HasCustomImage(int id) const override;
bool HasCustomColor(int id) const override;
base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
const override;
#if defined(OS_MACOSX)
bool UsingSystemTheme() const override;
bool InIncognitoMode() const override;
bool HasCustomColor(int id) const override;
NSImage* GetNSImageNamed(int id) const override;
NSColor* GetNSImageColorNamed(int id) const override;
NSColor* GetNSColor(int id) const override;
Expand Down Expand Up @@ -249,12 +249,12 @@ class ThemeService : public content::NotificationObserver, public KeyedService {
gfx::ImageSkia* GetImageSkiaNamed(int id, bool incognito) const;
SkColor GetColor(int id, bool incognito) const;
int GetDisplayProperty(int id) const;
bool HasCustomColor(int id) const;
base::RefCountedMemory* GetRawData(int id,
ui::ScaleFactor scale_factor) const;
#if defined(OS_MACOSX)
NSImage* GetNSImageNamed(int id, bool incognito) const;
NSColor* GetNSImageColorNamed(int id, bool incognito) const;
bool HasCustomColor(int id) const;
NSColor* GetNSColor(int id, bool incognito) const;
NSColor* GetNSColorTint(int id) const;
NSGradient* GetNSGradient(int id) const;
Expand Down
9 changes: 0 additions & 9 deletions chrome/browser/themes/theme_service_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ void HSLToHSB(const color_utils::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) {
return image_color;
}

bool ThemeService::HasCustomColor(int id) const {
SkColor color;
return theme_supplier_ && theme_supplier_->GetColor(id, &color);
}

NSColor* ThemeService::GetNSColor(int id, bool incognito) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

Expand Down Expand Up @@ -360,10 +355,6 @@ void HSLToHSB(const color_utils::HSL& hsl, CGFloat* h, CGFloat* s, CGFloat* b) {
return theme_service_.UsingSystemTheme();
}

bool ThemeService::BrowserThemeProvider::HasCustomColor(int id) const {
return theme_service_.HasCustomColor(id);
}

NSImage* ThemeService::BrowserThemeProvider::GetNSImageNamed(int id) const {
return theme_service_.GetNSImageNamed(id, incognito_);
}
Expand Down
4 changes: 4 additions & 0 deletions ui/base/default_theme_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ bool DefaultThemeProvider::HasCustomImage(int id) const {
return false;
}

bool DefaultThemeProvider::HasCustomColor(int id) const {
return false;
}

base::RefCountedMemory* DefaultThemeProvider::GetRawData(
int id,
ui::ScaleFactor scale_factor) const {
Expand Down
2 changes: 1 addition & 1 deletion ui/base/default_theme_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class UI_BASE_EXPORT DefaultThemeProvider : public ThemeProvider {
int GetDisplayProperty(int id) const override;
bool ShouldUseNativeFrame() const override;
bool HasCustomImage(int id) const override;
bool HasCustomColor(int id) const override;
base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
const override;

#if defined(OS_MACOSX)
bool UsingSystemTheme() const override;
bool InIncognitoMode() const override;
bool HasCustomColor(int id) const override;
NSImage* GetNSImageNamed(int id) const override;
NSColor* GetNSImageColorNamed(int id) const override;
NSColor* GetNSColor(int id) const override;
Expand Down
4 changes: 0 additions & 4 deletions ui/base/default_theme_provider_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
return false;
}

bool DefaultThemeProvider::HasCustomColor(int id) const {
return false;
}

NSImage* DefaultThemeProvider::GetNSImageNamed(int id) const {
return ResourceBundle::GetSharedInstance().
GetNativeImageNamed(id).ToNSImage();
Expand Down
6 changes: 3 additions & 3 deletions ui/base/theme_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class UI_BASE_EXPORT ThemeProvider {
// doesn't provide a certain image, but custom themes might (badges, etc).
virtual bool HasCustomImage(int id) const = 0;

// Returns true if the theme has defined a custom color for color |id|.
virtual bool HasCustomColor(int id) const = 0;

// Reads the image data from the theme file into the specified vector. Only
// valid for un-themed resources and the themed IDR_THEME_NTP_* in most
// implementations of ThemeProvider. Returns NULL on error.
Expand All @@ -91,9 +94,6 @@ class UI_BASE_EXPORT ThemeProvider {
// Gets the NSImage with the specified |id|.
virtual NSImage* GetNSImageNamed(int id) const = 0;

// Returns true if the theme has defined a custom color for color |id|.
virtual bool HasCustomColor(int id) const = 0;

// Gets the NSImage that GetNSImageNamed (above) would return, but returns it
// as a pattern color.
virtual NSColor* GetNSImageColorNamed(int id) const = 0;
Expand Down

0 comments on commit cd4b788

Please sign in to comment.