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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 ProfileMenuButton::~ProfileMenuButton() {} | 29 ProfileMenuButton::~ProfileMenuButton() {} |
30 | 30 |
31 void ProfileMenuButton::UpdateText(Profile* profile) { | 31 void ProfileMenuButton::UpdateText(Profile* profile) { |
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 if (!text.empty()) | 38 gtk_widget_set_visible(widget_.get(), !text.empty()); |
39 gtk_widget_show(widget_.get()); | |
40 else | |
41 gtk_widget_hide(widget_.get()); | |
42 } | 39 } |
43 | 40 |
44 gboolean ProfileMenuButton::OnButtonPressed(GtkWidget* widget, | 41 gboolean ProfileMenuButton::OnButtonPressed(GtkWidget* widget, |
45 GdkEventButton* event) { | 42 GdkEventButton* event) { |
46 if (event->button != 1) | 43 if (event->button != 1) |
47 return FALSE; | 44 return FALSE; |
48 | 45 |
49 menu_->PopupForWidget(widget_.get(), event->button, event->time); | 46 menu_->PopupForWidget(widget_.get(), event->button, event->time); |
50 return TRUE; | 47 return TRUE; |
51 } | 48 } |
OLD | NEW |