Index: chrome/browser/ui/gtk/avatar_menu_button_gtk.cc |
diff --git a/chrome/browser/ui/gtk/avatar_menu_button_gtk.cc b/chrome/browser/ui/gtk/avatar_menu_button_gtk.cc |
index c96a2ced64cc083e02f219c254003b7f8827fb1f..6c9f4386a5320474474a7209825eb6e98603e900 100644 |
--- a/chrome/browser/ui/gtk/avatar_menu_button_gtk.cc |
+++ b/chrome/browser/ui/gtk/avatar_menu_button_gtk.cc |
@@ -6,6 +6,7 @@ |
#include "base/i18n/rtl.h" |
#include "chrome/browser/profiles/profile_metrics.h" |
+#include "chrome/browser/profiles/profile_info_util.h" |
#include "chrome/browser/ui/gtk/avatar_menu_bubble_gtk.h" |
#include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
#include "ui/gfx/gtk_util.h" |
@@ -13,13 +14,17 @@ |
AvatarMenuButtonGtk::AvatarMenuButtonGtk(Browser* browser) |
: image_(NULL), |
browser_(browser), |
- arrow_location_(BubbleGtk::ARROW_LOCATION_TOP_LEFT) { |
+ arrow_location_(BubbleGtk::ARROW_LOCATION_TOP_LEFT), |
+ is_gaia_picture_(false), |
+ old_height_(0) { |
GtkWidget* event_box = gtk_event_box_new(); |
image_ = gtk_image_new(); |
gtk_container_add(GTK_CONTAINER(event_box), image_); |
g_signal_connect(event_box, "button-press-event", |
G_CALLBACK(OnButtonPressedThunk), this); |
+ g_signal_connect(event_box, "size-allocate", |
+ G_CALLBACK(OnSizeAllocateThunk), this); |
gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE); |
@@ -29,13 +34,11 @@ AvatarMenuButtonGtk::AvatarMenuButtonGtk(Browser* browser) |
AvatarMenuButtonGtk::~AvatarMenuButtonGtk() { |
} |
-void AvatarMenuButtonGtk::SetIcon(const SkBitmap& icon) { |
- GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); |
- gtk_image_set_from_pixbuf(GTK_IMAGE(image_), icon_pixbuf); |
- g_object_unref(icon_pixbuf); |
- |
- gtk_misc_set_alignment(GTK_MISC(image_), 0.0, 1.0); |
- gtk_widget_set_size_request(image_, -1, 0); |
+void AvatarMenuButtonGtk::SetIcon(const gfx::Image& image, |
+ bool is_gaia_picture) { |
+ icon_.reset(new gfx::Image(image)); |
+ is_gaia_picture_ = is_gaia_picture; |
+ UpdateButtonIcon(); |
} |
gboolean AvatarMenuButtonGtk::OnButtonPressed(GtkWidget* widget, |
@@ -48,6 +51,24 @@ gboolean AvatarMenuButtonGtk::OnButtonPressed(GtkWidget* widget, |
return TRUE; |
} |
+void AvatarMenuButtonGtk::OnSizeAllocate(GtkWidget* widget, |
+ GtkAllocation* allocation) { |
+ if (allocation->height != old_height_) |
+ UpdateButtonIcon(); |
+} |
+ |
void AvatarMenuButtonGtk::ShowAvatarBubble() { |
new AvatarMenuBubbleGtk(browser_, widget_.get(), arrow_location_, NULL); |
} |
+ |
+void AvatarMenuButtonGtk::UpdateButtonIcon() { |
+ if (!icon_.get()) |
+ return; |
+ |
+ old_height_ = widget()->allocation.height; |
+ gfx::Image icon = profiles::GetAvatarIconForTitleBar(*icon_, is_gaia_picture_, |
+ profiles::kAvatarIconWidth, old_height_); |
+ gtk_image_set_from_pixbuf(GTK_IMAGE(image_), icon.ToGdkPixbuf()); |
+ gtk_misc_set_alignment(GTK_MISC(image_), 0.0, 1.0); |
+ gtk_widget_set_size_request(image_, -1, 0); |
+} |