Skip to content

Commit

Permalink
GTK: Fix gtk-theme mode: implement GtkThemeService::GetImageNamed().
Browse files Browse the repository at this point in the history
GtkThemeService injects themed images into SkBitmaps for theming. When I
started moving to the gfx::Image returning GetImageNamed() interface, I didn't
implement it at the GtkThemeService level.

BUG=106597,106060
TEST=No blue tabs in gtk-theme mode.


Review URL: http://codereview.chromium.org/8771052

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113536 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
erg@chromium.org committed Dec 8, 2011
1 parent 20f656f commit e7c8114
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 3 additions & 4 deletions chrome/browser/themes/theme_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ class ThemeService : public base::NonThreadSafe,

// Returns a cross platform image for an id.
//
// TODO(erg): Make this a virtual, exposed through ui::ThemeProvider and the
// main way to get theme properties out of the theme provider since it's
// cross platform.
const gfx::Image* GetImageNamed(int id) const;
// TODO(erg): Make this part of the ui::ThemeProvider and the main way to get
// theme properties out of the theme provider since it's cross platform.
virtual const gfx::Image* GetImageNamed(int id) const;

// ui::ThemeProvider implementation.
virtual void Init(Profile* profile) OVERRIDE;
Expand Down
16 changes: 11 additions & 5 deletions chrome/browser/ui/gtk/gtk_theme_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,25 @@ void GtkThemeService::Init(Profile* profile) {
}

SkBitmap* GtkThemeService::GetBitmapNamed(int id) const {
// TODO(erg): Remove this const cast. The gfx::Image interface returns its
// images const. GetBitmapNamed() also should but doesn't and has a million
// callsites.
return const_cast<SkBitmap*>(GetImageNamed(id)->ToSkBitmap());
}

const gfx::Image* GtkThemeService::GetImageNamed(int id) const {
// Try to get our cached version:
ImageCache::const_iterator it = gtk_images_.find(id);
if (it != gtk_images_.end())
return it->second;

if (use_gtk_ && IsOverridableImage(id)) {
// We haven't built this image yet:
SkBitmap* bitmap = GenerateGtkThemeBitmap(id);
gtk_images_[id] = bitmap;
return bitmap;
gfx::Image* image = new gfx::Image(GenerateGtkThemeBitmap(id));
gtk_images_[id] = image;
return image;
}

return ThemeService::GetBitmapNamed(id);
return ThemeService::GetImageNamed(id);
}

SkColor GtkThemeService::GetColor(int id) const {
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ui/gtk/gtk_theme_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class GtkThemeService : public ThemeService {
// ThemeService's implementation.
virtual void Init(Profile* profile) OVERRIDE;
virtual SkBitmap* GetBitmapNamed(int id) const OVERRIDE;
virtual const gfx::Image* GetImageNamed(int id) const OVERRIDE;
virtual SkColor GetColor(int id) const OVERRIDE;
virtual bool HasCustomImage(int id) const OVERRIDE;
virtual void SetTheme(const Extension* extension) OVERRIDE;
Expand Down Expand Up @@ -170,7 +171,7 @@ class GtkThemeService : public ThemeService {
private:
typedef std::map<int, SkColor> ColorMap;
typedef std::map<int, color_utils::HSL> TintMap;
typedef std::map<int, SkBitmap*> ImageCache;
typedef std::map<int, gfx::Image*> ImageCache;
typedef std::map<int, gfx::CairoCachedSurface*> CairoCachedSurfaceMap;
typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap;

Expand Down

0 comments on commit e7c8114

Please sign in to comment.