| 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_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/avatar_menu_bubble_gtk.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/avatar_menu_model.h" | 9 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/gtk/avatar_menu_item_gtk.h" | 13 #include "chrome/browser/ui/gtk/avatar_menu_item_gtk.h" |
| 14 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 14 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
| 15 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 15 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 16 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 16 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
| 17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 17 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 18 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 18 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "content/public/browser/notification_source.h" |
| 19 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 20 #include "ui/base/gtk/gtk_hig_constants.h" | 22 #include "ui/base/gtk/gtk_hig_constants.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 // The minimum width in pixels of the bubble. | 27 // The minimum width in pixels of the bubble. |
| 26 const int kBubbleMinWidth = 175; | 28 const int kBubbleMinWidth = 175; |
| 27 | 29 |
| 28 // The number of pixels of padding on the left of the 'New Profile' link at the | 30 // The number of pixels of padding on the left of the 'New Profile' link at the |
| 29 // bottom of the bubble. | 31 // bottom of the bubble. |
| 30 const int kNewProfileLinkLeftPadding = 40; | 32 const int kNewProfileLinkLeftPadding = 40; |
| 31 | 33 |
| 32 } // namespace | 34 } // namespace |
| 33 | 35 |
| 34 AvatarMenuBubbleGtk::AvatarMenuBubbleGtk(Browser* browser, | 36 AvatarMenuBubbleGtk::AvatarMenuBubbleGtk(Browser* browser, |
| 35 GtkWidget* anchor, | 37 GtkWidget* anchor, |
| 36 BubbleGtk::ArrowLocationGtk arrow, | 38 BubbleGtk::ArrowLocationGtk arrow, |
| 37 const gfx::Rect* rect) | 39 const gfx::Rect* rect) |
| 38 : contents_(NULL), | 40 : contents_(NULL), |
| 39 theme_service_(GtkThemeService::GetFrom(browser->profile())), | 41 theme_service_(GtkThemeService::GetFrom(browser->profile())), |
| 42 new_profile_link_(NULL), |
| 40 minimum_width_(kBubbleMinWidth) { | 43 minimum_width_(kBubbleMinWidth) { |
| 41 avatar_menu_model_.reset(new AvatarMenuModel( | 44 avatar_menu_model_.reset(new AvatarMenuModel( |
| 42 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 45 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
| 43 this, browser)); | 46 this, browser)); |
| 44 | 47 |
| 45 InitContents(); | 48 InitContents(); |
| 46 | 49 |
| 47 OnAvatarMenuModelChanged(avatar_menu_model_.get()); | 50 OnAvatarMenuModelChanged(avatar_menu_model_.get()); |
| 48 | 51 |
| 49 bubble_ = BubbleGtk::Show(anchor, | 52 bubble_ = BubbleGtk::Show(anchor, |
| 50 rect, | 53 rect, |
| 51 contents_, | 54 contents_, |
| 52 arrow, | 55 arrow, |
| 53 true, // |match_system_theme| | 56 true, // |match_system_theme| |
| 54 true, // |grab_input| | 57 true, // |grab_input| |
| 55 theme_service_, | 58 theme_service_, |
| 56 this); // |delegate| | 59 this); // |delegate| |
| 57 g_signal_connect(contents_, "destroy", | 60 g_signal_connect(contents_, "destroy", |
| 58 G_CALLBACK(&OnDestroyThunk), this); | 61 G_CALLBACK(&OnDestroyThunk), this); |
| 62 |
| 63 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 64 content::Source<ThemeService>(theme_service_)); |
| 65 theme_service_->InitThemesFor(this); |
| 59 } | 66 } |
| 60 | 67 |
| 61 AvatarMenuBubbleGtk::~AvatarMenuBubbleGtk() { | 68 AvatarMenuBubbleGtk::~AvatarMenuBubbleGtk() { |
| 62 STLDeleteContainerPointers(items_.begin(), items_.end()); | 69 STLDeleteContainerPointers(items_.begin(), items_.end()); |
| 63 } | 70 } |
| 64 | 71 |
| 65 void AvatarMenuBubbleGtk::OnDestroy(GtkWidget* widget) { | 72 void AvatarMenuBubbleGtk::OnDestroy(GtkWidget* widget) { |
| 66 // We are self deleting, we have a destroy signal setup to catch when we | 73 // We are self deleting, we have a destroy signal setup to catch when we |
| 67 // destroyed (via the BubbleGtk being destroyed), and delete ourself. | 74 // destroyed (via the BubbleGtk being destroyed), and delete ourself. |
| 68 delete this; | 75 delete this; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 void AvatarMenuBubbleGtk::OpenProfile(size_t profile_index) { | 91 void AvatarMenuBubbleGtk::OpenProfile(size_t profile_index) { |
| 85 avatar_menu_model_->SwitchToProfile(profile_index); | 92 avatar_menu_model_->SwitchToProfile(profile_index); |
| 86 bubble_->Close(); | 93 bubble_->Close(); |
| 87 } | 94 } |
| 88 | 95 |
| 89 void AvatarMenuBubbleGtk::EditProfile(size_t profile_index) { | 96 void AvatarMenuBubbleGtk::EditProfile(size_t profile_index) { |
| 90 avatar_menu_model_->EditProfile(profile_index); | 97 avatar_menu_model_->EditProfile(profile_index); |
| 91 bubble_->Close(); | 98 bubble_->Close(); |
| 92 } | 99 } |
| 93 | 100 |
| 101 void AvatarMenuBubbleGtk::Observe(int type, |
| 102 const content::NotificationSource& source, |
| 103 const content::NotificationDetails& details) { |
| 104 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
| 105 gtk_chrome_link_button_set_use_gtk_theme( |
| 106 GTK_CHROME_LINK_BUTTON(new_profile_link_), |
| 107 theme_service_->UsingNativeTheme()); |
| 108 } |
| 109 |
| 94 void AvatarMenuBubbleGtk::OnSizeRequest(GtkWidget* widget, | 110 void AvatarMenuBubbleGtk::OnSizeRequest(GtkWidget* widget, |
| 95 GtkRequisition* req) { | 111 GtkRequisition* req) { |
| 96 // Always use the maximum width ever requested. | 112 // Always use the maximum width ever requested. |
| 97 if (req->width < minimum_width_) | 113 if (req->width < minimum_width_) |
| 98 req->width = minimum_width_; | 114 req->width = minimum_width_; |
| 99 else | 115 else |
| 100 minimum_width_ = req->width; | 116 minimum_width_ = req->width; |
| 101 } | 117 } |
| 102 | 118 |
| 103 void AvatarMenuBubbleGtk::OnNewProfileLinkClicked(GtkWidget* link) { | 119 void AvatarMenuBubbleGtk::OnNewProfileLinkClicked(GtkWidget* link) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 | 138 |
| 123 items_.push_back(item); | 139 items_.push_back(item); |
| 124 | 140 |
| 125 gtk_box_pack_start(GTK_BOX(items_vbox), item->widget(), TRUE, TRUE, 0); | 141 gtk_box_pack_start(GTK_BOX(items_vbox), item->widget(), TRUE, TRUE, 0); |
| 126 } | 142 } |
| 127 | 143 |
| 128 gtk_box_pack_start(GTK_BOX(contents_), items_vbox, TRUE, TRUE, 0); | 144 gtk_box_pack_start(GTK_BOX(contents_), items_vbox, TRUE, TRUE, 0); |
| 129 gtk_box_pack_start(GTK_BOX(contents_), gtk_hseparator_new(), TRUE, TRUE, 0); | 145 gtk_box_pack_start(GTK_BOX(contents_), gtk_hseparator_new(), TRUE, TRUE, 0); |
| 130 | 146 |
| 131 // The new profile link. | 147 // The new profile link. |
| 132 GtkWidget* new_profile_link = gtk_chrome_link_button_new( | 148 new_profile_link_ = gtk_chrome_link_button_new( |
| 133 l10n_util::GetStringUTF8(IDS_PROFILES_CREATE_NEW_PROFILE_LINK).c_str()); | 149 l10n_util::GetStringUTF8(IDS_PROFILES_CREATE_NEW_PROFILE_LINK).c_str()); |
| 134 g_signal_connect(new_profile_link, "clicked", | 150 g_signal_connect(new_profile_link_, "clicked", |
| 135 G_CALLBACK(OnNewProfileLinkClickedThunk), this); | 151 G_CALLBACK(OnNewProfileLinkClickedThunk), this); |
| 136 | 152 |
| 137 GtkWidget* link_align = gtk_alignment_new(0, 0, 0, 0); | 153 GtkWidget* link_align = gtk_alignment_new(0, 0, 0, 0); |
| 138 gtk_alignment_set_padding(GTK_ALIGNMENT(link_align), | 154 gtk_alignment_set_padding(GTK_ALIGNMENT(link_align), |
| 139 0, 0, kNewProfileLinkLeftPadding, 0); | 155 0, 0, kNewProfileLinkLeftPadding, 0); |
| 140 gtk_container_add(GTK_CONTAINER(link_align), new_profile_link); | 156 gtk_container_add(GTK_CONTAINER(link_align), new_profile_link_); |
| 141 | 157 |
| 142 gtk_box_pack_start(GTK_BOX(contents_), link_align, FALSE, FALSE, 0); | 158 gtk_box_pack_start(GTK_BOX(contents_), link_align, FALSE, FALSE, 0); |
| 143 } | 159 } |
| OLD | NEW |