diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 17:39:34 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 17:39:34 +0000 |
commit | 4f14f81100d3f7bb283c3cb23f35f4d514e12443 (patch) | |
tree | be3c1078a4806cb49881d9f75c9445781f60be01 /chrome/browser/gtk/custom_button.cc | |
parent | 2a025b18b5c8971caa8845da9a724a2092e37eae (diff) | |
download | chromium_src-4f14f81100d3f7bb283c3cb23f35f4d514e12443.zip chromium_src-4f14f81100d3f7bb283c3cb23f35f4d514e12443.tar.gz chromium_src-4f14f81100d3f7bb283c3cb23f35f4d514e12443.tar.bz2 |
gtk: Theme the tab close button.
BUG=none
TEST=Open a browser window. The close button should be visible. Apply a theme with a colored close button. The close button color should match the theme.
Review URL: http://codereview.chromium.org/159338
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21542 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/custom_button.cc')
-rw-r--r-- | chrome/browser/gtk/custom_button.cc | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc index fab4907..b9e836e 100644 --- a/chrome/browser/gtk/custom_button.cc +++ b/chrome/browser/gtk/custom_button.cc @@ -11,12 +11,15 @@ #include "base/gfx/gtk_util.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" +#include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" #include "grit/theme_resources.h" +#include "skia/ext/image_operations.h" CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeProvider* theme_provider, int normal_id, int active_id, int highlight_id, int depressed_id) - : paint_override_(-1), + : background_image_(NULL), + paint_override_(-1), normal_id_(normal_id), active_id_(active_id), highlight_id_(highlight_id), @@ -46,6 +49,10 @@ CustomDrawButtonBase::CustomDrawButtonBase(GtkThemeProvider* theme_provider, } CustomDrawButtonBase::~CustomDrawButtonBase() { + if (background_image_) { + g_object_unref(background_image_); + background_image_ = NULL; + } } gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) { @@ -64,10 +71,13 @@ gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) { // The widget might be larger than the pixbuf. Paint the pixbuf flush with the // start of the widget (left for LTR, right for RTL). - int pixbuf_width = gdk_pixbuf_get_width(pixbuf); - int widget_width = widget->allocation.width; - int x = (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? - widget_width - pixbuf_width : 0; + gfx::Rect bounds = gfx::Rect(0, 0, gdk_pixbuf_get_width(pixbuf), 0); + int x = gtk_util::MirroredLeftPointForRect(widget, bounds); + + if (background_image_) { + gdk_cairo_set_source_pixbuf(cairo_context, background_image_, x, 0); + cairo_paint(cairo_context); + } gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, x, 0); cairo_paint(cairo_context); @@ -76,6 +86,20 @@ gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) { return TRUE; } +void CustomDrawButtonBase::SetBackground(SkColor color, + SkBitmap* image, SkBitmap* mask) { + if (!image || !mask) { + if (background_image_) { + g_object_unref(background_image_); + background_image_ = NULL; + } + } else { + SkBitmap img = skia::ImageOperations::CreateButtonBackground(color, + *image, *mask); + background_image_ = gfx::GdkPixbufFromSkBitmap(&img); + } +} + void CustomDrawButtonBase::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK(theme_provider_); @@ -147,6 +171,11 @@ void CustomDrawButton::UnsetPaintOverride() { gtk_widget_queue_draw(widget_.get()); } +void CustomDrawButton::SetBackground(SkColor color, + SkBitmap* image, SkBitmap* mask) { + button_base_.SetBackground(color, image, mask); +} + // static gboolean CustomDrawButton::OnCustomExpose(GtkWidget* widget, GdkEventExpose* e, |