diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 00:53:32 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 00:53:32 +0000 |
commit | 546882bd3fae21df702efcaaec50ec168ec6bf86 (patch) | |
tree | 5f5c77beabb57eb7bb3d91c9c423b81998017336 | |
parent | 9bba0e83dd8d8f2b2196a7985cc6fa704fae0cc3 (diff) | |
download | chromium_src-546882bd3fae21df702efcaaec50ec168ec6bf86.zip chromium_src-546882bd3fae21df702efcaaec50ec168ec6bf86.tar.gz chromium_src-546882bd3fae21df702efcaaec50ec168ec6bf86.tar.bz2 |
Add GetImageSkiaNamed to resource_bundle and theme_provider.
This makes converting use of SkBitmap into ImageSkia easier
Bug=124566
Test=Manual
Review URL: https://chromiumcodereview.appspot.com/10388064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136470 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/themes/theme_service.cc | 22 | ||||
-rw-r--r-- | chrome/browser/themes/theme_service.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm | 4 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view_unittest.mm | 2 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/download/background_theme.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/download/background_theme.mm | 6 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/gtk_theme_service.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/gtk_theme_service.h | 1 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.cc | 5 | ||||
-rw-r--r-- | ui/base/resource/resource_bundle.h | 9 | ||||
-rw-r--r-- | ui/base/theme_provider.h | 10 | ||||
-rw-r--r-- | ui/views/widget/default_theme_provider.cc | 5 | ||||
-rw-r--r-- | ui/views/widget/default_theme_provider.h | 1 |
13 files changed, 62 insertions, 11 deletions
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc index e5628e4..f9be837 100644 --- a/chrome/browser/themes/theme_service.cc +++ b/chrome/browser/themes/theme_service.cc @@ -22,6 +22,7 @@ #include "grit/theme_resources_standard.h" #include "grit/ui_resources.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image_skia.h" #if defined(OS_WIN) && !defined(USE_AURA) #include "ui/views/widget/native_widget_win.h" @@ -244,17 +245,20 @@ const gfx::Image* ThemeService::GetImageNamed(int id) const { } SkBitmap* ThemeService::GetBitmapNamed(int id) const { - DCHECK(CalledOnValidThread()); - - SkBitmap* bitmap = NULL; - - if (theme_pack_.get()) - bitmap = theme_pack_->GetBitmapNamed(id); + const gfx::Image* image = GetImageNamed(id); + if (!image) + return NULL; - if (!bitmap) - bitmap = rb_.GetBitmapNamed(id); + return const_cast<SkBitmap*>(image->ToSkBitmap()); +} - return bitmap; +gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const { + const gfx::Image* image = GetImageNamed(id); + if (!image) + return NULL; + // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns + // its images const. GetImageSkiaNamed() also should but has many callsites. + return const_cast<gfx::ImageSkia*>(image->ToImageSkia()); } SkColor ThemeService::GetColor(int id) const { diff --git a/chrome/browser/themes/theme_service.h b/chrome/browser/themes/theme_service.h index f49bead..c5cc1ba 100644 --- a/chrome/browser/themes/theme_service.h +++ b/chrome/browser/themes/theme_service.h @@ -156,6 +156,7 @@ class ThemeService : public base::NonThreadSafe, // Overridden from ui::ThemeProvider: virtual SkBitmap* GetBitmapNamed(int id) const OVERRIDE; + virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE; virtual SkColor GetColor(int id) const OVERRIDE; virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE; diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm index a1a0985..1193f89 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm @@ -33,6 +33,7 @@ #import "third_party/ocmock/OCMock/OCMock.h" #include "ui/base/test/cocoa_test_event_utils.h" #include "ui/base/theme_provider.h" +#include "ui/gfx/image/image_skia.h" // Unit tests don't need time-consuming asynchronous animations. @interface BookmarkBarControllerTestable : BookmarkBarController { @@ -189,7 +190,8 @@ class FakeTheme : public ui::ThemeProvider { FakeTheme(NSColor* color) : color_(color) {} scoped_nsobject<NSColor> color_; - virtual SkBitmap* GetBitmapNamed(int id) const { return nil; } + virtual SkBitmap* GetBitmapNamed(int id) const { return NULL; } + virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const { return NULL; } virtual SkColor GetColor(int id) const { return SkColor(); } virtual bool GetDisplayProperty(int id, int* result) const { return false; } virtual bool ShouldUseNativeFrame() const { return false; } diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view_unittest.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view_unittest.mm index 6b4654f..7ed17ba 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view_unittest.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view_unittest.mm @@ -16,6 +16,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/base/theme_provider.h" +#include "ui/gfx/image/image_skia.h" using ::testing::_; using ::testing::DoAll; @@ -29,6 +30,7 @@ class MockThemeProvider : public ui::ThemeProvider { // Cross platform methods MOCK_METHOD1(Init, void(Profile*)); MOCK_CONST_METHOD1(GetBitmapNamed, SkBitmap*(int)); + MOCK_CONST_METHOD1(GetImageSkiaNamed, gfx::ImageSkia*(int)); MOCK_CONST_METHOD1(GetColor, SkColor(int)); MOCK_CONST_METHOD2(GetDisplayProperty, bool(int, int*)); MOCK_CONST_METHOD0(ShouldUseNativeFrame, bool()); diff --git a/chrome/browser/ui/cocoa/download/background_theme.h b/chrome/browser/ui/cocoa/download/background_theme.h index e9d4bd7..df4afaa 100644 --- a/chrome/browser/ui/cocoa/download/background_theme.h +++ b/chrome/browser/ui/cocoa/download/background_theme.h @@ -18,6 +18,7 @@ class BackgroundTheme : public ui::ThemeProvider { // Overridden from ui::ThemeProvider: virtual SkBitmap* GetBitmapNamed(int id) const OVERRIDE; + virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE; virtual SkColor GetColor(int id) const OVERRIDE; virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE; diff --git a/chrome/browser/ui/cocoa/download/background_theme.mm b/chrome/browser/ui/cocoa/download/background_theme.mm index af4dc7c..4f2d689 100644 --- a/chrome/browser/ui/cocoa/download/background_theme.mm +++ b/chrome/browser/ui/cocoa/download/background_theme.mm @@ -28,7 +28,11 @@ BackgroundTheme::BackgroundTheme(ui::ThemeProvider* provider) : BackgroundTheme::~BackgroundTheme() {} SkBitmap* BackgroundTheme::GetBitmapNamed(int id) const { - return nil; + return NULL; +} + +gfx::ImageSkia* BackgroundTheme::GetImageSkiaNamed(int id) const { + return NULL; } SkColor BackgroundTheme::GetColor(int id) const { diff --git a/chrome/browser/ui/gtk/gtk_theme_service.cc b/chrome/browser/ui/gtk/gtk_theme_service.cc index 84975ba..cd6b0ab 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service.cc +++ b/chrome/browser/ui/gtk/gtk_theme_service.cc @@ -301,6 +301,12 @@ SkBitmap* GtkThemeService::GetBitmapNamed(int id) const { return const_cast<SkBitmap*>(GetImageNamed(id)->ToSkBitmap()); } +gfx::ImageSkia* GtkThemeService::GetImageSkiaNamed(int id) const { + // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns + // its images const. GetImageSkiaNamed() also should but has many callsites. + return const_cast<gfx::ImageSkia*>(GetImageNamed(id)->ToImageSkia()); +} + const gfx::Image* GtkThemeService::GetImageNamed(int id) const { // Try to get our cached version: ImageCache::const_iterator it = gtk_images_.find(id); diff --git a/chrome/browser/ui/gtk/gtk_theme_service.h b/chrome/browser/ui/gtk/gtk_theme_service.h index d5b288a9..0228c56 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service.h +++ b/chrome/browser/ui/gtk/gtk_theme_service.h @@ -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 gfx::ImageSkia* GetImageSkiaNamed(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; diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc index d6a69bd..f84e8db 100644 --- a/ui/base/resource/resource_bundle.cc +++ b/ui/base/resource/resource_bundle.cc @@ -212,6 +212,11 @@ SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { return const_cast<SkBitmap*>(bitmap); } +gfx::ImageSkia* ResourceBundle::GetImageSkiaNamed(int resource_id) { + const gfx::ImageSkia* image = GetImageNamed(resource_id).ToImageSkia(); + return const_cast<gfx::ImageSkia*>(image); +} + gfx::Image& ResourceBundle::GetImageNamed(int resource_id) { // Check to see if the image is already in the cache. { diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h index 41d2634..df25f31 100644 --- a/ui/base/resource/resource_bundle.h +++ b/ui/base/resource/resource_bundle.h @@ -154,6 +154,15 @@ class UI_EXPORT ResourceBundle { // !! THIS IS DEPRECATED. PLEASE USE THE METHOD BELOW. !! SkBitmap* GetBitmapNamed(int resource_id); + // Gets image with the specified resource_id from the current module data. + // Returns a pointer to a shared instance of gfx::ImageSkia. This shared + // instance is owned by the resource bundle and should not be freed. + // TODO(pkotwicz): Make method return const gfx::ImageSkia* + // + // NOTE: It is preferrable to use GetImageNamed such that code is more + // portable. + gfx::ImageSkia* GetImageSkiaNamed(int resource_id); + // Gets an image resource from the current module data. This will load the // image in Skia format by default. The ResourceBundle owns this. gfx::Image& GetImageNamed(int resource_id); diff --git a/ui/base/theme_provider.h b/ui/base/theme_provider.h index 82037d70..4aec13d 100644 --- a/ui/base/theme_provider.h +++ b/ui/base/theme_provider.h @@ -31,6 +31,10 @@ namespace base { class RefCountedMemory; } +namespace gfx { +class ImageSkia; +} + namespace ui { //////////////////////////////////////////////////////////////////////////////// @@ -48,8 +52,14 @@ class UI_EXPORT ThemeProvider { // Get the bitmap specified by |id|. An implementation of ThemeProvider should // have its own source of ids (e.g. an enum, or external resource bundle). + // TODO(pkotwicz): Get rid of GetBitmapNamed once all code uses + // GetImageSkiaNamed. virtual SkBitmap* GetBitmapNamed(int id) const = 0; + // Get the image specified by |id|. An implementation of ThemeProvider should + // have its own source of ids (e.g. an enum, or external resource bundle). + virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const = 0; + // Get the color specified by |id|. virtual SkColor GetColor(int id) const = 0; diff --git a/ui/views/widget/default_theme_provider.cc b/ui/views/widget/default_theme_provider.cc index df33ee6..469410b 100644 --- a/ui/views/widget/default_theme_provider.cc +++ b/ui/views/widget/default_theme_provider.cc @@ -5,6 +5,7 @@ #include "ui/views/widget/default_theme_provider.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image_skia.h" #if defined(OS_WIN) && !defined(USE_AURA) #include "ui/views/widget/native_widget_win.h" @@ -20,6 +21,10 @@ SkBitmap* DefaultThemeProvider::GetBitmapNamed(int id) const { return ResourceBundle::GetSharedInstance().GetBitmapNamed(id); } +gfx::ImageSkia* DefaultThemeProvider::GetImageSkiaNamed(int id) const { + return ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); +} + SkColor DefaultThemeProvider::GetColor(int id) const { // Return debugging-blue. return 0xff0000ff; diff --git a/ui/views/widget/default_theme_provider.h b/ui/views/widget/default_theme_provider.h index c1df943..ca135b2 100644 --- a/ui/views/widget/default_theme_provider.h +++ b/ui/views/widget/default_theme_provider.h @@ -27,6 +27,7 @@ class VIEWS_EXPORT DefaultThemeProvider : public ui::ThemeProvider { // Overridden from ui::ThemeProvider: virtual SkBitmap* GetBitmapNamed(int id) const OVERRIDE; + virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const OVERRIDE; virtual SkColor GetColor(int id) const OVERRIDE; virtual bool GetDisplayProperty(int id, int* result) const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE; |