1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_GTK_AVATAR_MENU_ITEM_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_AVATAR_MENU_ITEM_GTK_H_ 7 8 #include <gtk/gtk.h> 9 10 #include "chrome/browser/profiles/avatar_menu_model.h" 11 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_registrar.h" 13 #include "ui/base/gtk/gtk_signal.h" 14 #include "ui/base/gtk/owned_widget_gtk.h" 15 16 class GtkThemeService; 17 18 // This widget contains the profile icon, user name, and synchronization status 19 // to be displayed in the AvatarMenuBubble. Clicking the profile will open a new 20 // browser window, and when the user hovers over an active profile item, a link 21 // is displayed that will allow editing the profile. 22 class AvatarMenuItemGtk : public content::NotificationObserver { 23 public: 24 // Delegates opening or editing a profile. 25 class Delegate { 26 public: 27 // Open a new browser window using the profile at |profile_index|. 28 virtual void OpenProfile(size_t profile_index) = 0; 29 30 // Edit the profile given by |profile_index|. 31 virtual void EditProfile(size_t profile_index) = 0; 32 }; 33 34 AvatarMenuItemGtk(Delegate* delegate, 35 const AvatarMenuModel::Item& item, 36 size_t item_index, 37 GtkThemeService* theme_service); 38 virtual ~AvatarMenuItemGtk(); 39 40 // Returns the root widget for this menu item. 41 GtkWidget* widget() { return widget_.get(); } 42 43 // content::NotificationObserver implementation. 44 virtual void Observe(int type, 45 const content::NotificationSource& source, 46 const content::NotificationDetails& details) OVERRIDE; 47 48 private: 49 50 void ShowStatusLabel(); 51 void ShowEditLink(); 52 53 CHROMEGTK_CALLBACK_1(AvatarMenuItemGtk, gboolean, OnProfileClick, 54 GdkEventButton*); 55 CHROMEGTK_CALLBACK_1(AvatarMenuItemGtk, gboolean, OnProfileEnter, 56 GdkEventCrossing*); 57 CHROMEGTK_CALLBACK_1(AvatarMenuItemGtk, gboolean, OnProfileLeave, 58 GdkEventCrossing*); 59 CHROMEGTK_CALLBACK_1(AvatarMenuItemGtk, gboolean, OnProfileFocusIn, 60 GdkEventFocus*); 61 CHROMEGTK_CALLBACK_1(AvatarMenuItemGtk, gboolean, OnProfileFocusOut, 62 GdkEventFocus*); 63 CHROMEGTK_CALLBACK_1(AvatarMenuItemGtk, gboolean, OnProfileKeyPress, 64 GdkEventKey*); 65 CHROMEGTK_CALLBACK_1(AvatarMenuItemGtk, gboolean, OnEventBoxExpose, 66 GdkEventExpose*); 67 CHROMEGTK_CALLBACK_0(AvatarMenuItemGtk, void, OnEditProfileLinkClicked); 68 69 // Create all widgets in this menu item, using |theme_service|. 70 void Init(GtkThemeService* theme_service); 71 72 // A weak pointer to the item's delegate. 73 Delegate* delegate_; 74 75 // Profile information to display for this item, e.g. user name, sync status. 76 AvatarMenuModel::Item item_; 77 78 // The index of this profile. The delegate uses this value to distinguish 79 // which profile should be switched to. 80 size_t item_index_; 81 82 // The root widget for this menu item. 83 ui::OwnedWidgetGtk widget_; 84 85 // Provides colors. 86 GtkThemeService* theme_service_; 87 88 // A weak pointer to a label that displays the sync status. It is not shown 89 // when the user is hovering over the item if the profile is the active 90 // profile. 91 GtkWidget* status_label_; 92 93 // A weak pointer to a link button to edit the given profile. It is shown only 94 // when the user is hovering over the active profile. 95 GtkWidget* link_alignment_; 96 97 // A weak pointer to a GtkChromeLinkButton so we can keep the use_gtk_theme 98 // property up to date. 99 GtkWidget* edit_profile_link_; 100 101 // The highlighted color. Depending on the theme, this is either |widget|'s 102 // bg[GTK_STATE_SELECTED] or a static highlight. 103 GdkColor highlighted_color_; 104 105 // The unhighlighted color. Depending on the theme, this is either NULL or a 106 // pointer to static data. 107 const GdkColor* unhighlighted_color_; 108 109 content::NotificationRegistrar registrar_; 110 111 DISALLOW_COPY_AND_ASSIGN(AvatarMenuItemGtk); 112 }; 113 114 #endif // CHROME_BROWSER_UI_GTK_AVATAR_MENU_ITEM_GTK_H_ 115