Skip to content

Commit

Permalink
This CL removes ResourceBundle::GetBitmapNamed() and ThemeProvider::G…
Browse files Browse the repository at this point in the history
…etBitmapNamed()

BUG=153180
Test=Compiles

R=sail,erg
TBR=sky

Review URL: https://chromiumcodereview.appspot.com/11015007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160789 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pkotwicz@chromium.org committed Oct 9, 2012
1 parent 9bc732a commit 5b3bdb5
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 138 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/extensions/extension_icon_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void ExtensionIconManager::OnImageLoaded(const gfx::Image& image,
void ExtensionIconManager::EnsureDefaultIcon() {
if (default_icon_.empty()) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
SkBitmap* src = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
default_icon_ = ApplyTransforms(*src);
SkBitmap src = rb.GetImageNamed(IDR_EXTENSIONS_SECTION).AsBitmap();
default_icon_ = ApplyTransforms(src);
}
}

Expand Down
11 changes: 0 additions & 11 deletions chrome/browser/themes/browser_theme_pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -594,17 +594,6 @@ bool BrowserThemePack::GetDisplayProperty(int id, int* result) const {
return false;
}

SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const {
const gfx::Image* image = GetImageNamed(idr_id);
if (!image)
return NULL;

// TODO(sail): This cast should be removed. Currently we use this const_cast
// to avoid changing the BrowserThemePack::GetBitmapNamed API. Once we
// switch to using gfx::Image everywhere this can be removed.
return const_cast<SkBitmap*>(image->ToSkBitmap());
}

const gfx::Image* BrowserThemePack::GetImageNamed(int idr_id) const {
int prs_id = GetPersistentIDByIDR(idr_id);
if (prs_id == -1)
Expand Down
6 changes: 0 additions & 6 deletions chrome/browser/themes/browser_theme_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ class BrowserThemePack : public base::RefCountedThreadSafe<
bool GetColor(int id, SkColor* color) const;
bool GetDisplayProperty(int id, int* result) const;

// Returns a bitmap if we have a custom image for |id|, otherwise NULL. Note
// that this is separate from HasCustomImage() which returns whether a custom
// image |id| was included in the unprocessed theme and is used as a proxy
// for making layout decisions in the interface.
SkBitmap* GetBitmapNamed(int id) const;

// Returns an image if we have a custom image for |id|, otherwise NULL.
const gfx::Image* GetImageNamed(int id) const;

Expand Down
8 changes: 0 additions & 8 deletions chrome/browser/themes/theme_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,6 @@ gfx::Image ThemeService::GetImageNamed(int id) const {
return image ? *image : gfx::Image();
}

SkBitmap* ThemeService::GetBitmapNamed(int id) const {
gfx::Image image = GetImageNamed(id);
if (image.IsEmpty())
return NULL;

return const_cast<SkBitmap*>(image.ToSkBitmap());
}

gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id) const {
gfx::Image image = GetImageNamed(id);
if (image.IsEmpty())
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/themes/theme_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class ThemeService : public base::NonThreadSafe,
virtual gfx::Image GetImageNamed(int id) const;

// 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;
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/themes/theme_service_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/image/image.h"

GdkPixbuf* ThemeService::GetRTLEnabledPixbufNamed(int id) const {
return GetPixbufImpl(id, true);
Expand All @@ -26,8 +27,8 @@ GdkPixbuf* ThemeService::GetPixbufImpl(int id, bool rtl_enabled) const {
if (pixbufs_iter != gdk_pixbufs_.end())
return pixbufs_iter->second;

SkBitmap* bitmap = GetBitmapNamed(id);
GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(*bitmap);
SkBitmap bitmap = GetImageNamed(id).AsBitmap();
GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap);

// We loaded successfully. Cache the pixbuf.
if (pixbuf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ - (void)setDragDataNode:(const BookmarkNode*)node {
FakeTheme(NSColor* color) : color_(color) {}
scoped_nsobject<NSColor> color_;

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; }
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/ui/cocoa/download/background_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class BackgroundTheme : public ui::ThemeProvider {
virtual ~BackgroundTheme();

// 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;
Expand Down
4 changes: 0 additions & 4 deletions chrome/browser/ui/cocoa/download/background_theme.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

BackgroundTheme::~BackgroundTheme() {}

SkBitmap* BackgroundTheme::GetBitmapNamed(int id) const {
return NULL;
}

gfx::ImageSkia* BackgroundTheme::GetImageSkiaNamed(int id) const {
return NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ virtual void OnImageLoaded(const gfx::Image& image,
ResourceBundle& rb = ResourceBundle::GetSharedInstance();

// Fall back on the default extension icon on failure.
const SkBitmap* icon;
const gfx::ImageSkia* icon;
if (image.IsEmpty())
icon = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
icon = rb.GetImageSkiaNamed(IDR_EXTENSIONS_SECTION);
else
icon = image.ToSkBitmap();
icon = image.ToImageSkia();

SkBitmap* drop_image = rb.GetBitmapNamed(IDR_APP_DROPARROW);
gfx::ImageSkia* drop_image = rb.GetImageSkiaNamed(IDR_APP_DROPARROW);

const int image_size = extension_misc::EXTENSION_ICON_BITTY;
scoped_ptr<gfx::Canvas> canvas(
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/gtk/browser_titlebar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ void BrowserTitlebar::GetButtonResources(const std::string& button_name,
void BrowserTitlebar::UpdateButtonBackground(CustomDrawButton* button) {
SkColor color = theme_service_->GetColor(
ThemeService::COLOR_BUTTON_BACKGROUND);
SkBitmap* background =
theme_service_->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND);
SkBitmap background = theme_service_->GetImageNamed(
IDR_THEME_WINDOW_CONTROL_BACKGROUND).AsBitmap();

// TODO(erg): For now, we just use a completely black mask and we can get
// away with this in the short term because our buttons are rectangles. We
Expand All @@ -564,7 +564,7 @@ void BrowserTitlebar::UpdateButtonBackground(CustomDrawButton* button) {
mask.allocPixels();
mask.eraseColor(SK_ColorBLACK);

button->SetBackground(color, background, &mask);
button->SetBackground(color, background, mask);
}

void BrowserTitlebar::UpdateCustomFrame(bool use_custom_frame) {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/gtk/browser_toolbar_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ gboolean BrowserToolbarGtk::OnWrenchMenuButtonExpose(GtkWidget* sender,
gtk_widget_get_allocation(sender, &allocation);

// Draw the chrome app menu icon onto the canvas.
const SkBitmap* badge = theme_service_->GetBitmapNamed(resource_id);
const gfx::ImageSkia* badge = theme_service_->GetImageSkiaNamed(resource_id);
gfx::CanvasSkiaPaint canvas(expose, false);
int x_offset = base::i18n::IsRTL() ? 0 : allocation.width - badge->width();
int y_offset = 0;
Expand Down
10 changes: 6 additions & 4 deletions chrome/browser/ui/gtk/custom_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget,
}

void CustomDrawButtonBase::SetBackground(SkColor color,
SkBitmap* image, SkBitmap* mask) {
if (!image || !mask) {
const SkBitmap& image,
const SkBitmap& mask) {
if (image.isNull() || mask.isNull()) {
if (background_image_->valid()) {
background_image_->UsePixbuf(NULL);
}
} else {
SkBitmap img =
SkBitmapOperations::CreateButtonBackground(color, *image, *mask);
SkBitmapOperations::CreateButtonBackground(color, image, mask);

GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(img);
background_image_->UsePixbuf(pixbuf);
Expand Down Expand Up @@ -336,7 +337,8 @@ void CustomDrawButton::UnsetPaintOverride() {
}

void CustomDrawButton::SetBackground(SkColor color,
SkBitmap* image, SkBitmap* mask) {
const SkBitmap& image,
const SkBitmap& mask) {
button_base_.SetBackground(color, image, mask);
}

Expand Down
8 changes: 6 additions & 2 deletions chrome/browser/ui/gtk/custom_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class CustomDrawButtonBase : public content::NotificationObserver {
int paint_override() const { return paint_override_; }

// Set the background details.
void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask);
void SetBackground(SkColor color,
const SkBitmap& image,
const SkBitmap& mask);

// Provide content::NotificationObserver implementation.
virtual void Observe(int type,
Expand Down Expand Up @@ -186,7 +188,9 @@ class CustomDrawButton : public content::NotificationObserver {
void UnsetPaintOverride();

// Set the background details.
void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask);
void SetBackground(SkColor color,
const SkBitmap& image,
const SkBitmap& mask);

// content::NotificationObserver implementation.
virtual void Observe(int type,
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/ui/gtk/download/download_shelf_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "grit/ui_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/gtk/gtk_screen_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
Expand Down Expand Up @@ -267,8 +268,8 @@ void DownloadShelfGtk::Observe(int type,
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
close_button_->SetBackground(
theme_service_->GetColor(ThemeService::COLOR_TAB_TEXT),
rb.GetBitmapNamed(IDR_CLOSE_BAR),
rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK));
rb.GetImageNamed(IDR_CLOSE_BAR).AsBitmap(),
rb.GetImageNamed(IDR_CLOSE_BAR_MASK).AsBitmap());
}
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/gtk/find_bar_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ void FindBarGtk::Observe(int type,
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
close_button_->SetBackground(
theme_service_->GetColor(ThemeService::COLOR_TAB_TEXT),
rb.GetBitmapNamed(IDR_CLOSE_BAR),
rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK));
rb.GetImageNamed(IDR_CLOSE_BAR).AsBitmap(),
rb.GetImageNamed(IDR_CLOSE_BAR_MASK).AsBitmap());
}

UpdateMatchLabelAppearance(match_label_failure_);
Expand Down
15 changes: 4 additions & 11 deletions chrome/browser/ui/gtk/gtk_theme_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void BuildIconFromIDRWithColor(int id,
GtkIconSet* icon_set) {
SkColor color = gfx::GdkColorToSkColor(style->fg[state]);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SkBitmap original = *rb.GetBitmapNamed(id);
SkBitmap original = rb.GetImageNamed(id).AsBitmap();

SkBitmap fill_color;
fill_color.setConfig(SkBitmap::kARGB_8888_Config,
Expand Down Expand Up @@ -296,13 +296,6 @@ void GtkThemeService::Init(Profile* profile) {
ThemeService::Init(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());
}

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.
Expand Down Expand Up @@ -1050,9 +1043,9 @@ SkBitmap GtkThemeService::GenerateFrameImage(
}

SkBitmap GtkThemeService::GenerateTabImage(int base_id) const {
SkBitmap* base_image = GetBitmapNamed(base_id);
SkBitmap base_image = GetImageNamed(base_id).AsBitmap();
SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap(
*base_image, GetTint(ThemeService::TINT_BACKGROUND_TAB));
base_image, GetTint(ThemeService::TINT_BACKGROUND_TAB));
return SkBitmapOperations::CreateTiledBitmap(
bg_tint, 0, 0, bg_tint.width(), bg_tint.height());
}
Expand All @@ -1062,7 +1055,7 @@ SkBitmap GtkThemeService::GenerateTintedIcon(
const color_utils::HSL& tint) const {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return SkBitmapOperations::CreateHSLShiftedBitmap(
*rb.GetBitmapNamed(base_id), tint);
rb.GetImageNamed(base_id).AsBitmap(), tint);
}

void GtkThemeService::GetNormalButtonTintHSL(
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/ui/gtk/gtk_theme_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class GtkThemeService : public ThemeService {
// Sets that we aren't using the system theme, then calls
// 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 gfx::Image GetImageNamed(int id) const OVERRIDE;
virtual SkColor GetColor(int id) const OVERRIDE;
Expand Down Expand Up @@ -295,7 +294,7 @@ class GtkThemeService : public ThemeService {
GtkIconSet* fullscreen_icon_set_;

// Image cache of lazily created images, created when requested by
// GetBitmapNamed().
// GetImageNamed().
mutable ImageCache gtk_images_;

PrefChangeRegistrar registrar_;
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/ui/gtk/notifications/balloon_view_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ void BalloonViewImpl::Show(Balloon* balloon) {
IDR_TAB_CLOSE_P,
IDR_TAB_CLOSE_H,
IDR_TAB_CLOSE));
close_button_->SetBackground(SK_ColorBLACK,
rb.GetBitmapNamed(IDR_TAB_CLOSE),
rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
close_button_->SetBackground(
SK_ColorBLACK,
rb.GetImageNamed(IDR_TAB_CLOSE).AsBitmap(),
rb.GetImageNamed(IDR_TAB_CLOSE_MASK).AsBitmap());
gtk_widget_set_tooltip_text(close_button_->widget(), dismiss_text.c_str());
g_signal_connect(close_button_->widget(), "clicked",
G_CALLBACK(OnCloseButtonThunk), this);
Expand Down
38 changes: 19 additions & 19 deletions chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ TabRendererGtk::LoadingAnimation::Data::Data(
GtkThemeService* theme_service) {
// The loading animation image is a strip of states. Each state must be
// square, so the height must divide the width evenly.
SkBitmap* loading_animation_frames =
theme_service->GetBitmapNamed(IDR_THROBBER);
DCHECK(loading_animation_frames);
DCHECK_EQ(loading_animation_frames->width() %
loading_animation_frames->height(), 0);
SkBitmap loading_animation_frames =
theme_service->GetImageNamed(IDR_THROBBER).AsBitmap();
DCHECK(!loading_animation_frames.isNull());
DCHECK_EQ(loading_animation_frames.width() %
loading_animation_frames.height(), 0);
loading_animation_frame_count =
loading_animation_frames->width() /
loading_animation_frames->height();

SkBitmap* waiting_animation_frames =
theme_service->GetBitmapNamed(IDR_THROBBER_WAITING);
DCHECK(waiting_animation_frames);
DCHECK_EQ(waiting_animation_frames->width() %
waiting_animation_frames->height(), 0);
loading_animation_frames.width() /
loading_animation_frames.height();

SkBitmap waiting_animation_frames =
theme_service->GetImageNamed(IDR_THROBBER_WAITING).AsBitmap();
DCHECK(!waiting_animation_frames.isNull());
DCHECK_EQ(waiting_animation_frames.width() %
waiting_animation_frames.height(), 0);
waiting_animation_frame_count =
waiting_animation_frames->width() /
waiting_animation_frames->height();
waiting_animation_frames.width() /
waiting_animation_frames.height();

waiting_to_loading_frame_count_ratio =
waiting_animation_frame_count /
Expand Down Expand Up @@ -394,8 +394,8 @@ void TabRendererGtk::UpdateData(WebContents* contents,
// will eventually be chromium-themable and this code will go away.
data_.is_default_favicon =
(data_.favicon.pixelRef() ==
ui::ResourceBundle::GetSharedInstance().GetBitmapNamed(
IDR_DEFAULT_FAVICON)->pixelRef());
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_DEFAULT_FAVICON).AsBitmap().pixelRef());
}

// Loading state also involves whether we show the favicon, since that's where
Expand Down Expand Up @@ -759,8 +759,8 @@ void TabRendererGtk::Layout() {
close_button_color_ = tab_text_color;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
close_button_->SetBackground(close_button_color_,
rb.GetBitmapNamed(IDR_TAB_CLOSE),
rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
rb.GetImageNamed(IDR_TAB_CLOSE).AsBitmap(),
rb.GetImageNamed(IDR_TAB_CLOSE_MASK).AsBitmap());
}
}
} else {
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2269,8 +2269,9 @@ CustomDrawButton* TabStripGtk::MakeNewTabButton() {
void TabStripGtk::SetNewTabButtonBackground() {
SkColor color = theme_service_->GetColor(
ThemeService::COLOR_BUTTON_BACKGROUND);
SkBitmap* background = theme_service_->GetBitmapNamed(
IDR_THEME_WINDOW_CONTROL_BACKGROUND);
SkBitmap* mask = theme_service_->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK);
SkBitmap background = theme_service_->GetImageNamed(
IDR_THEME_WINDOW_CONTROL_BACKGROUND).AsBitmap();
SkBitmap mask = theme_service_->GetImageNamed(
IDR_NEWTAB_BUTTON_MASK).AsBitmap();
newtab_button_->SetBackground(color, background, mask);
}
4 changes: 2 additions & 2 deletions chrome/browser/ui/gtk/task_manager_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ std::string TaskManagerGtk::GetModelText(int row, int col_id) {
GdkPixbuf* TaskManagerGtk::GetModelIcon(int row) {
SkBitmap icon = *model_->GetResourceIcon(row).bitmap();
if (icon.pixelRef() ==
ui::ResourceBundle::GetSharedInstance().GetBitmapNamed(
IDR_DEFAULT_FAVICON)->pixelRef()) {
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_DEFAULT_FAVICON).AsBitmap().pixelRef()) {
return static_cast<GdkPixbuf*>(g_object_ref(
GtkThemeService::GetDefaultFavicon(true).ToGdkPixbuf()));
}
Expand Down
Loading

0 comments on commit 5b3bdb5

Please sign in to comment.