diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 18:49:07 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 18:49:07 +0000 |
commit | 9366cf747481b8fb04f5e76beae807d31d4c6aff (patch) | |
tree | 91d2de15704752993dca73abd204087349f439dc /chrome/browser | |
parent | 549935ac8361186f358f80b3b15ec31b1329a85a (diff) | |
download | chromium_src-9366cf747481b8fb04f5e76beae807d31d4c6aff.zip chromium_src-9366cf747481b8fb04f5e76beae807d31d4c6aff.tar.gz chromium_src-9366cf747481b8fb04f5e76beae807d31d4c6aff.tar.bz2 |
Allow getting the theme tint as a value so that it can be applied independent of the theme provider. Since the Mac needs it to tint its vector resources it's added to the Mac.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/151153
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 69 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 17 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider_mac.mm | 39 |
4 files changed, 96 insertions, 31 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 4fb94912..c3e2bb4 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -137,7 +137,7 @@ BrowserThemeProvider::BrowserThemeProvider() } BrowserThemeProvider::~BrowserThemeProvider() { - FreeImages(); + ClearCaches(); } void BrowserThemeProvider::Init(Profile* profile) { @@ -266,7 +266,7 @@ bool BrowserThemeProvider::HasCustomImage(int id) { void BrowserThemeProvider::SetTheme(Extension* extension) { // Clear our image cache. - FreeImages(); + ClearCaches(); DCHECK(extension); DCHECK(extension->IsTheme()); @@ -289,7 +289,7 @@ void BrowserThemeProvider::SetTheme(Extension* extension) { void BrowserThemeProvider::UseDefaultTheme() { // Clear our image cache. - FreeImages(); + ClearCaches(); images_.clear(); colors_.clear(); @@ -361,35 +361,54 @@ SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { } } -skia::HSL BrowserThemeProvider::GetTint(int id) { - DCHECK(CalledOnValidThread()); +const std::string BrowserThemeProvider::GetTintKey(int id) { switch (id) { case TINT_FRAME: - return (tints_.find(kTintFrame) != tints_.end()) ? - tints_[kTintFrame] : kDefaultTintFrame; + return kTintFrame; case TINT_FRAME_INACTIVE: - return (tints_.find(kTintFrameInactive) != tints_.end()) ? - tints_[kTintFrameInactive] : kDefaultTintFrameInactive; + return kTintFrameInactive; case TINT_FRAME_INCOGNITO: - return (tints_.count(kTintFrameIncognito)) ? - tints_[kTintFrameIncognito] : kDefaultTintFrameIncognito; + return kTintFrameIncognito; case TINT_FRAME_INCOGNITO_INACTIVE: - return (tints_.count(kTintFrameIncognitoInactive)) ? - tints_[kTintFrameIncognitoInactive] : - kDefaultTintFrameIncognitoInactive; + return kTintFrameIncognitoInactive; case TINT_BUTTONS: - return (tints_.find(kTintButtons) != tints_.end()) ? - tints_[kTintButtons] : - kDefaultTintButtons; + return kTintButtons; case TINT_BACKGROUND_TAB: - return (tints_.find(kTintBackgroundTab) != tints_.end()) ? - tints_[kTintBackgroundTab] : - kDefaultTintBackgroundTab; + return kTintBackgroundTab; default: NOTREACHED() << "Unknown tint requested"; + return ""; } - skia::HSL result = {-1, -1, -1}; - return result; +} + +skia::HSL BrowserThemeProvider::GetDefaultTint(int id) { + switch (id) { + case TINT_FRAME: + return kDefaultTintFrame; + case TINT_FRAME_INACTIVE: + return kDefaultTintFrameInactive; + case TINT_FRAME_INCOGNITO: + return kDefaultTintFrameIncognito; + case TINT_FRAME_INCOGNITO_INACTIVE: + return kDefaultTintFrameIncognitoInactive; + case TINT_BUTTONS: + return kDefaultTintButtons; + case TINT_BACKGROUND_TAB: + return kDefaultTintBackgroundTab; + default: + skia::HSL result = {-1, -1, -1}; + return result; + } +} + +skia::HSL BrowserThemeProvider::GetTint(int id) { + DCHECK(CalledOnValidThread()); + + TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); + if (tint_iter != tints_.end()) + return tint_iter->second; + else + return GetDefaultTint(id); } SkBitmap BrowserThemeProvider::TintBitmap(const SkBitmap& bitmap, int hsl_id) { @@ -730,8 +749,8 @@ SkColor BrowserThemeProvider::FindColor(const char* id, return (colors_.find(id) != colors_.end()) ? colors_[id] : default_color; } -void BrowserThemeProvider::FreeImages() { - FreePlatformImages(); +void BrowserThemeProvider::ClearCaches() { + FreePlatformCaches(); for (ImageCache::iterator i = image_cache_.begin(); i != image_cache_.end(); i++) { delete i->second; @@ -740,7 +759,7 @@ void BrowserThemeProvider::FreeImages() { } #if defined(OS_WIN) -void BrowserThemeProvider::FreePlatformImages() { +void BrowserThemeProvider::FreePlatformCaches() { // Windows has no platform image cache to clear. } #endif diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 7e5c144..b43a69c 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -74,6 +74,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, virtual GdkPixbuf* GetPixbufNamed(int id); #elif defined(OS_MACOSX) virtual NSImage* GetNSImageNamed(int id); + virtual NSColor* GetNSColorTint(int id); #endif // Set the current theme to the theme defined in |extension|. @@ -104,6 +105,12 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // otherwise modified, or an application default. SkBitmap* LoadThemeBitmap(int id); + // Returns the string key for the given tint |id| TINT_* enum value. + const std::string GetTintKey(int id); + + // Returns the default tint for the given tint |id| TINT_* enum value. + skia::HSL GetDefaultTint(int id); + // Get the specified tint - |id| is one of the TINT_* enum values. skia::HSL GetTint(int id); @@ -158,11 +165,11 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, SkColor FindColor(const char* id, SkColor default_color); // Frees generated images and clears the image cache. - void FreeImages(); + void ClearCaches(); - // Clears the platform-specific image cache. Do not call directly; it's called - // from FreeImages(). - void FreePlatformImages(); + // Clears the platform-specific caches. Do not call directly; it's called + // from ClearCaches(). + void FreePlatformCaches(); // Cached images. We cache all retrieved and generated bitmaps and keep // track of the pointers. We own these and will delete them when we're done @@ -175,6 +182,8 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, #elif defined(OS_MACOSX) typedef std::map<int, NSImage*> NSImageMap; NSImageMap nsimage_cache_; + typedef std::map<int, NSColor*> NSColorMap; + NSColorMap nscolor_cache_; #endif ResourceBundle& rb_; diff --git a/chrome/browser/browser_theme_provider_gtk.cc b/chrome/browser/browser_theme_provider_gtk.cc index 370e773..9605344 100644 --- a/chrome/browser/browser_theme_provider_gtk.cc +++ b/chrome/browser/browser_theme_provider_gtk.cc @@ -41,7 +41,7 @@ GdkPixbuf* BrowserThemeProvider::GetPixbufNamed(int id) { return empty_bitmap; } -void BrowserThemeProvider::FreePlatformImages() { +void BrowserThemeProvider::FreePlatformCaches() { DCHECK(CalledOnValidThread()); // Free GdkPixbufs. diff --git a/chrome/browser/browser_theme_provider_mac.mm b/chrome/browser/browser_theme_provider_mac.mm index 4c52fe1..300cf70 100644 --- a/chrome/browser/browser_theme_provider_mac.mm +++ b/chrome/browser/browser_theme_provider_mac.mm @@ -52,7 +52,37 @@ NSImage* BrowserThemeProvider::GetNSImageNamed(int id) { return empty_image; } -void BrowserThemeProvider::FreePlatformImages() { +NSColor* BrowserThemeProvider::GetNSColorTint(int id) { + DCHECK(CalledOnValidThread()); + + // Check to see if we already have the color in the cache. + NSColorMap::const_iterator found = nscolor_cache_.find(id); + if (found != nscolor_cache_.end()) + return found->second; + + TintMap::iterator tint_iter = tints_.find(GetTintKey(id)); + if (tint_iter != tints_.end()) { + skia::HSL tint = tint_iter->second; + + // The tint is HSL, not HSB, but we're cheating for now. TODO(avi,alcor): + // determine how much this matters and fix it if necessary. + // http://crbug.com/15760 + NSColor* tint_color = [NSColor colorWithCalibratedHue:tint.h + saturation:tint.s + brightness:tint.l + alpha:1.0]; + + // We loaded successfully. Cache the color. + if (tint_color) { + nscolor_cache_[id] = [tint_color retain]; + return tint_color; + } + } + + return nil; +} + +void BrowserThemeProvider::FreePlatformCaches() { DCHECK(CalledOnValidThread()); // Free images. @@ -61,4 +91,11 @@ void BrowserThemeProvider::FreePlatformImages() { [i->second release]; } nsimage_cache_.clear(); + + // Free colors. + for (NSColorMap::iterator i = nscolor_cache_.begin(); + i != nscolor_cache_.end(); i++) { + [i->second release]; + } + nscolor_cache_.clear(); } |