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