summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 17:39:34 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 17:39:34 +0000
commit4f14f81100d3f7bb283c3cb23f35f4d514e12443 (patch)
treebe3c1078a4806cb49881d9f75c9445781f60be01
parent2a025b18b5c8971caa8845da9a724a2092e37eae (diff)
downloadchromium_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
-rw-r--r--chrome/browser/gtk/custom_button.cc39
-rw-r--r--chrome/browser/gtk/custom_button.h10
-rw-r--r--chrome/browser/gtk/tabs/tab_renderer_gtk.cc16
-rw-r--r--chrome/browser/gtk/tabs/tab_renderer_gtk.h3
4 files changed, 62 insertions, 6 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,
diff --git a/chrome/browser/gtk/custom_button.h b/chrome/browser/gtk/custom_button.h
index ca248e8..72085fa 100644
--- a/chrome/browser/gtk/custom_button.h
+++ b/chrome/browser/gtk/custom_button.h
@@ -14,6 +14,7 @@
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/owned_widget_gtk.h"
+#include "third_party/skia/include/core/SkBitmap.h"
class GtkThemeProvider;
@@ -42,6 +43,9 @@ class CustomDrawButtonBase : public NotificationObserver {
void set_paint_override(int state) { paint_override_ = state; }
int paint_override() const { return paint_override_; }
+ // Set the background details.
+ void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask);
+
// Provide NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
@@ -52,6 +56,9 @@ class CustomDrawButtonBase : public NotificationObserver {
// INSENSITIVE is the last available state;
GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1];
+ // The background image.
+ GdkPixbuf* background_image_;
+
// If non-negative, the state to paint the button.
int paint_override_;
@@ -113,6 +120,9 @@ class CustomDrawButton : public NotificationObserver {
// Resume normal drawing of the widget's state.
void UnsetPaintOverride();
+ // Set the background details.
+ void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask);
+
// Provide NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
index 5aacce4..02cb4f9 100644
--- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
@@ -217,7 +217,8 @@ TabRendererGtk::TabRendererGtk(ThemeProvider* theme_provider)
showing_close_button_(false),
fav_icon_hiding_offset_(0),
should_display_crashed_favicon_(false),
- loading_animation_(theme_provider) {
+ loading_animation_(theme_provider),
+ close_button_color_(NULL) {
InitResources();
data_.pinned = false;
@@ -497,6 +498,19 @@ void TabRendererGtk::Layout() {
close_button_bounds_.SetRect(local_bounds.width() + kCloseButtonHorzFuzz,
close_button_top, close_button_width_,
close_button_height_);
+
+ // If the close button color has changed, generate a new one.
+ if (theme_provider_) {
+ SkColor tab_text_color =
+ theme_provider_->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT);
+ if (!close_button_color_ || tab_text_color != close_button_color_) {
+ close_button_color_ = tab_text_color;
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ close_button_->SetBackground(close_button_color_,
+ rb.GetBitmapNamed(IDR_TAB_CLOSE),
+ rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
+ }
+ }
} else {
close_button_bounds_.SetRect(0, 0, 0, 0);
}
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h
index c34a439..aec1464 100644
--- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h
+++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h
@@ -335,6 +335,9 @@ class TabRendererGtk : public AnimationDelegate {
// The close button.
scoped_ptr<CustomDrawButton> close_button_;
+ // The current color of the close button.
+ SkColor close_button_color_;
+
DISALLOW_COPY_AND_ASSIGN(TabRendererGtk);
};