| 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/profile_menu_button.h" | 5 #include "chrome/browser/ui/gtk/profile_menu_button.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" | 10 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
| 11 #include "chrome/browser/ui/profile_menu_model.h" | 11 #include "chrome/browser/ui/profile_menu_model.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "ui/base/text/text_elider.h" | 13 #include "ui/base/text/text_elider.h" |
| 14 | 14 |
| 15 // Maximum width for name string in pixels. | 15 // Maximum width for name string in pixels. |
| 16 const int kMaxTextWidth = 200; | 16 const int kMaxTextWidth = 200; |
| 17 | 17 |
| 18 ProfileMenuButton::ProfileMenuButton() { | 18 ProfileMenuButton::ProfileMenuButton(Profile* profile) : profile_(profile) { |
| 19 profile_menu_model_.reset(new ProfileMenuModel); | 19 profile_menu_model_.reset(new ProfileMenuModel(profile_)); |
| 20 menu_.reset(new MenuGtk(NULL, profile_menu_model_.get())); | 20 menu_.reset(new MenuGtk(NULL, profile_menu_model_.get())); |
| 21 | 21 |
| 22 widget_.Own(gtk_button_new()); | 22 widget_.Own(gtk_button_new()); |
| 23 | 23 |
| 24 g_signal_connect(widget_.get(), "button-press-event", | 24 g_signal_connect(widget_.get(), "button-press-event", |
| 25 G_CALLBACK(OnButtonPressedThunk), this); | 25 G_CALLBACK(OnButtonPressedThunk), this); |
| 26 gtk_widget_set_no_show_all(GTK_WIDGET(widget_.get()), TRUE); | 26 gtk_widget_set_no_show_all(GTK_WIDGET(widget_.get()), TRUE); |
| 27 } | 27 } |
| 28 | 28 |
| 29 ProfileMenuButton::~ProfileMenuButton() {} | 29 ProfileMenuButton::~ProfileMenuButton() {} |
| 30 | 30 |
| 31 void ProfileMenuButton::UpdateText(Profile* profile) { | 31 void ProfileMenuButton::UpdateText() { |
| 32 string16 text = UTF8ToUTF16( | 32 string16 text = UTF8ToUTF16( |
| 33 profile->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); | 33 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); |
| 34 string16 elided_text = ui::ElideText(text, gfx::Font(), kMaxTextWidth, false); | 34 string16 elided_text = ui::ElideText(text, gfx::Font(), kMaxTextWidth, false); |
| 35 gtk_button_set_label( | 35 gtk_button_set_label( |
| 36 GTK_BUTTON(widget_.get()), UTF16ToUTF8(elided_text).c_str()); | 36 GTK_BUTTON(widget_.get()), UTF16ToUTF8(elided_text).c_str()); |
| 37 | 37 |
| 38 gtk_widget_set_visible(widget_.get(), !text.empty()); | 38 gtk_widget_set_visible(widget_.get(), !text.empty()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 gboolean ProfileMenuButton::OnButtonPressed(GtkWidget* widget, | 41 gboolean ProfileMenuButton::OnButtonPressed(GtkWidget* widget, |
| 42 GdkEventButton* event) { | 42 GdkEventButton* event) { |
| 43 if (event->button != 1) | 43 if (event->button != 1) |
| 44 return FALSE; | 44 return FALSE; |
| 45 | 45 |
| 46 menu_->PopupForWidget(widget_.get(), event->button, event->time); | 46 menu_->PopupForWidget(widget_.get(), event->button, event->time); |
| 47 return TRUE; | 47 return TRUE; |
| 48 } | 48 } |
| OLD | NEW |