OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/gtk/avatar_menu_button_gtk.h" | 5 #include "chrome/browser/ui/gtk/avatar_menu_button_gtk.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "chrome/browser/profiles/profile_metrics.h" | 8 #include "chrome/browser/profiles/profile_metrics.h" |
| 9 #include "chrome/browser/profiles/profile_info_util.h" |
9 #include "chrome/browser/ui/gtk/avatar_menu_bubble_gtk.h" | 10 #include "chrome/browser/ui/gtk/avatar_menu_bubble_gtk.h" |
10 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" | 11 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
11 #include "ui/gfx/gtk_util.h" | 12 #include "ui/gfx/gtk_util.h" |
12 | 13 |
13 AvatarMenuButtonGtk::AvatarMenuButtonGtk(Browser* browser) | 14 AvatarMenuButtonGtk::AvatarMenuButtonGtk(Browser* browser) |
14 : image_(NULL), | 15 : image_(NULL), |
15 browser_(browser), | 16 browser_(browser), |
16 arrow_location_(BubbleGtk::ARROW_LOCATION_TOP_LEFT) { | 17 arrow_location_(BubbleGtk::ARROW_LOCATION_TOP_LEFT), |
| 18 is_gaia_picture_(false), |
| 19 old_height_(0) { |
17 GtkWidget* event_box = gtk_event_box_new(); | 20 GtkWidget* event_box = gtk_event_box_new(); |
18 image_ = gtk_image_new(); | 21 image_ = gtk_image_new(); |
19 gtk_container_add(GTK_CONTAINER(event_box), image_); | 22 gtk_container_add(GTK_CONTAINER(event_box), image_); |
20 | 23 |
21 g_signal_connect(event_box, "button-press-event", | 24 g_signal_connect(event_box, "button-press-event", |
22 G_CALLBACK(OnButtonPressedThunk), this); | 25 G_CALLBACK(OnButtonPressedThunk), this); |
| 26 g_signal_connect(event_box, "size-allocate", |
| 27 G_CALLBACK(OnSizeAllocateThunk), this); |
23 | 28 |
24 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE); | 29 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE); |
25 | 30 |
26 widget_.Own(event_box); | 31 widget_.Own(event_box); |
27 } | 32 } |
28 | 33 |
29 AvatarMenuButtonGtk::~AvatarMenuButtonGtk() { | 34 AvatarMenuButtonGtk::~AvatarMenuButtonGtk() { |
30 } | 35 } |
31 | 36 |
32 void AvatarMenuButtonGtk::SetIcon(const SkBitmap& icon) { | 37 void AvatarMenuButtonGtk::SetIcon(const gfx::Image& image, |
33 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); | 38 bool is_gaia_picture) { |
34 gtk_image_set_from_pixbuf(GTK_IMAGE(image_), icon_pixbuf); | 39 icon_.reset(new gfx::Image(image)); |
35 g_object_unref(icon_pixbuf); | 40 is_gaia_picture_ = is_gaia_picture; |
36 | 41 UpdateButtonIcon(); |
37 gtk_misc_set_alignment(GTK_MISC(image_), 0.0, 1.0); | |
38 gtk_widget_set_size_request(image_, -1, 0); | |
39 } | 42 } |
40 | 43 |
41 gboolean AvatarMenuButtonGtk::OnButtonPressed(GtkWidget* widget, | 44 gboolean AvatarMenuButtonGtk::OnButtonPressed(GtkWidget* widget, |
42 GdkEventButton* event) { | 45 GdkEventButton* event) { |
43 if (event->button != 1) | 46 if (event->button != 1) |
44 return FALSE; | 47 return FALSE; |
45 | 48 |
46 ShowAvatarBubble(); | 49 ShowAvatarBubble(); |
47 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | 50 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
48 return TRUE; | 51 return TRUE; |
49 } | 52 } |
50 | 53 |
| 54 void AvatarMenuButtonGtk::OnSizeAllocate(GtkWidget* widget, |
| 55 GtkAllocation* allocation) { |
| 56 if (allocation->height != old_height_) |
| 57 UpdateButtonIcon(); |
| 58 } |
| 59 |
51 void AvatarMenuButtonGtk::ShowAvatarBubble() { | 60 void AvatarMenuButtonGtk::ShowAvatarBubble() { |
52 new AvatarMenuBubbleGtk(browser_, widget_.get(), arrow_location_, NULL); | 61 new AvatarMenuBubbleGtk(browser_, widget_.get(), arrow_location_, NULL); |
53 } | 62 } |
| 63 |
| 64 void AvatarMenuButtonGtk::UpdateButtonIcon() { |
| 65 if (!icon_.get()) |
| 66 return; |
| 67 |
| 68 old_height_ = widget()->allocation.height; |
| 69 gfx::Image icon = profiles::GetAvatarIconForTitleBar(*icon_, is_gaia_picture_, |
| 70 profiles::kAvatarIconWidth, old_height_); |
| 71 gtk_image_set_from_pixbuf(GTK_IMAGE(image_), icon.ToGdkPixbuf()); |
| 72 gtk_misc_set_alignment(GTK_MISC(image_), 0.0, 1.0); |
| 73 gtk_widget_set_size_request(image_, -1, 0); |
| 74 } |
OLD | NEW |