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_item_gtk.h" | 5 #include "chrome/browser/ui/gtk/avatar_menu_item_gtk.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" |
7 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 10 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
9 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 11 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
10 #include "chrome/browser/ui/gtk/gtk_util.h" | 12 #include "chrome/browser/ui/gtk/gtk_util.h" |
11 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
12 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
13 #include "grit/theme_resources_standard.h" | 15 #include "grit/theme_resources_standard.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "ui/base/gtk/gtk_hig_constants.h" | 17 #include "ui/base/gtk/gtk_hig_constants.h" |
16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
33 } // namespace | 35 } // namespace |
34 | 36 |
35 AvatarMenuItemGtk::AvatarMenuItemGtk(Delegate* delegate, | 37 AvatarMenuItemGtk::AvatarMenuItemGtk(Delegate* delegate, |
36 const AvatarMenuModel::Item& item, | 38 const AvatarMenuModel::Item& item, |
37 size_t item_index, | 39 size_t item_index, |
38 GtkThemeService* theme_service) | 40 GtkThemeService* theme_service) |
39 : delegate_(delegate), | 41 : delegate_(delegate), |
40 item_(item), | 42 item_(item), |
41 item_index_(item_index), | 43 item_index_(item_index), |
42 status_label_(NULL), | 44 status_label_(NULL), |
43 link_alignment_(NULL) { | 45 link_alignment_(NULL), |
| 46 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
44 Init(theme_service); | 47 Init(theme_service); |
45 } | 48 } |
46 | 49 |
47 AvatarMenuItemGtk::~AvatarMenuItemGtk() { | 50 AvatarMenuItemGtk::~AvatarMenuItemGtk() { |
| 51 widget_.Destroy(); |
| 52 } |
| 53 |
| 54 void AvatarMenuItemGtk::OpenProfile() { |
| 55 delegate_->OpenProfile(item_index_); |
48 } | 56 } |
49 | 57 |
50 gboolean AvatarMenuItemGtk::OnProfileClick(GtkWidget* widget, | 58 gboolean AvatarMenuItemGtk::OnProfileClick(GtkWidget* widget, |
51 GdkEventButton* event) { | 59 GdkEventButton* event) { |
52 delegate_->OpenProfile(item_index_); | 60 // delegate_->EditProfile() will close the avatar bubble which in turn |
| 61 // try to destroy this AvatarMenuItemGtk. |
| 62 // This is not OK to do this from the signal handler, so we'll |
| 63 // defer it. |
| 64 MessageLoop::current()->PostTask( |
| 65 FROM_HERE, |
| 66 base::Bind(&AvatarMenuItemGtk::OpenProfile, |
| 67 weak_factory_.GetWeakPtr())); |
53 return FALSE; | 68 return FALSE; |
54 } | 69 } |
55 | 70 |
56 gboolean AvatarMenuItemGtk::OnProfileEnter(GtkWidget* widget, | 71 gboolean AvatarMenuItemGtk::OnProfileEnter(GtkWidget* widget, |
57 GdkEventCrossing* event) { | 72 GdkEventCrossing* event) { |
58 if (event->detail == GDK_NOTIFY_INFERIOR) | 73 if (event->detail == GDK_NOTIFY_INFERIOR) |
59 return FALSE; | 74 return FALSE; |
60 | 75 |
61 GtkStyle* style = gtk_rc_get_style(widget); | 76 GtkStyle* style = gtk_rc_get_style(widget); |
62 GdkColor highlight_color = style->bg[GTK_STATE_SELECTED]; | 77 GdkColor highlight_color = style->bg[GTK_STATE_SELECTED]; |
(...skipping 13 matching lines...) Expand all Loading... |
76 | 91 |
77 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, NULL); | 92 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, NULL); |
78 if (item_.active) { | 93 if (item_.active) { |
79 gtk_widget_show(status_label_); | 94 gtk_widget_show(status_label_); |
80 gtk_widget_hide(link_alignment_); | 95 gtk_widget_hide(link_alignment_); |
81 } | 96 } |
82 | 97 |
83 return FALSE; | 98 return FALSE; |
84 } | 99 } |
85 | 100 |
| 101 void AvatarMenuItemGtk::EditProfile() { |
| 102 delegate_->EditProfile(item_index_); |
| 103 } |
| 104 |
86 void AvatarMenuItemGtk::OnEditProfileLinkClicked(GtkWidget* link) { | 105 void AvatarMenuItemGtk::OnEditProfileLinkClicked(GtkWidget* link) { |
87 delegate_->EditProfile(item_index_); | 106 // delegate_->EditProfile() will close the avatar bubble which in turn |
| 107 // try to destroy this AvatarMenuItemGtk. |
| 108 // This is not OK to do this from the signal handler, so we'll |
| 109 // defer it. |
| 110 MessageLoop::current()->PostTask( |
| 111 FROM_HERE, |
| 112 base::Bind(&AvatarMenuItemGtk::EditProfile, |
| 113 weak_factory_.GetWeakPtr())); |
88 } | 114 } |
89 | 115 |
90 void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) { | 116 void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) { |
91 widget_.Own(gtk_event_box_new()); | 117 widget_.Own(gtk_event_box_new()); |
92 | 118 |
93 g_signal_connect(widget_.get(), "button-press-event", | 119 g_signal_connect(widget_.get(), "button-press-event", |
94 G_CALLBACK(OnProfileClickThunk), this); | 120 G_CALLBACK(OnProfileClickThunk), this); |
95 g_signal_connect(widget_.get(), "enter-notify-event", | 121 g_signal_connect(widget_.get(), "enter-notify-event", |
96 G_CALLBACK(OnProfileEnterThunk), this); | 122 G_CALLBACK(OnProfileEnterThunk), this); |
97 g_signal_connect(widget_.get(), "leave-notify-event", | 123 g_signal_connect(widget_.get(), "leave-notify-event", |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 201 |
176 GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | 202 GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); |
177 gtk_size_group_add_widget(size_group, status_label_); | 203 gtk_size_group_add_widget(size_group, status_label_); |
178 gtk_size_group_add_widget(size_group, link_alignment_); | 204 gtk_size_group_add_widget(size_group, link_alignment_); |
179 g_object_unref(size_group); | 205 g_object_unref(size_group); |
180 } | 206 } |
181 | 207 |
182 gtk_box_pack_start(GTK_BOX(item_hbox), item_vbox, TRUE, TRUE, 0); | 208 gtk_box_pack_start(GTK_BOX(item_hbox), item_vbox, TRUE, TRUE, 0); |
183 gtk_container_add(GTK_CONTAINER(widget_.get()), item_hbox); | 209 gtk_container_add(GTK_CONTAINER(widget_.get()), item_hbox); |
184 } | 210 } |
OLD | NEW |