Index: chrome/browser/ui/gtk/infobars/infobar_gtk.cc |
=================================================================== |
--- chrome/browser/ui/gtk/infobars/infobar_gtk.cc (revision 194480) |
+++ chrome/browser/ui/gtk/infobars/infobar_gtk.cc (working copy) |
@@ -52,53 +52,10 @@ |
InfoBarGtk::InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate) |
: InfoBar(owner, delegate), |
- theme_service_(GtkThemeService::GetFrom(Profile::FromBrowserContext( |
- owner->GetWebContents()->GetBrowserContext()))), |
+ bg_box_(NULL), |
+ hbox_(NULL), |
+ theme_service_(NULL), |
signals_(new ui::GtkSignalRegistrar) { |
- DCHECK(delegate); |
- // Create |hbox_| and pad the sides. |
- hbox_ = gtk_hbox_new(FALSE, kElementPadding); |
- |
- // Make the whole infor bar horizontally shrinkable. |
- gtk_widget_set_size_request(hbox_, 0, -1); |
- |
- GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1); |
- gtk_alignment_set_padding(GTK_ALIGNMENT(padding), |
- 0, 0, kLeftPadding, kRightPadding); |
- |
- bg_box_ = gtk_event_box_new(); |
- gtk_widget_set_app_paintable(bg_box_, TRUE); |
- g_signal_connect(bg_box_, "expose-event", |
- G_CALLBACK(OnBackgroundExposeThunk), this); |
- gtk_container_add(GTK_CONTAINER(padding), hbox_); |
- gtk_container_add(GTK_CONTAINER(bg_box_), padding); |
- |
- // Add the icon on the left, if any. |
- gfx::Image* icon = delegate->GetIcon(); |
- if (icon) { |
- GtkWidget* image = gtk_image_new_from_pixbuf(icon->ToGdkPixbuf()); |
- |
- gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5); |
- |
- gtk_box_pack_start(GTK_BOX(hbox_), image, FALSE, FALSE, 0); |
- } |
- |
- close_button_.reset(CustomDrawButton::CloseButtonBar(theme_service_)); |
- gtk_util::CenterWidgetInHBox(hbox_, close_button_->widget(), true, 0); |
- signals_->Connect(close_button_->widget(), "clicked", |
- G_CALLBACK(OnCloseButtonThunk), this); |
- |
- widget_.Own(gtk_expanded_container_new()); |
- gtk_container_add(GTK_CONTAINER(widget_.get()), bg_box_); |
- gtk_widget_set_size_request(widget_.get(), -1, 0); |
- |
- g_signal_connect(widget_.get(), "child-size-request", |
- G_CALLBACK(OnChildSizeRequestThunk), |
- this); |
- |
- registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
- content::Source<ThemeService>(theme_service_)); |
- UpdateBorderColor(); |
} |
InfoBarGtk::~InfoBarGtk() { |
@@ -109,6 +66,7 @@ |
} |
GdkColor InfoBarGtk::GetBorderColor() const { |
+ DCHECK(theme_service_); |
return theme_service_->GetBorderColor(); |
} |
@@ -121,10 +79,12 @@ |
} |
GtkWidget* InfoBarGtk::CreateLabel(const std::string& text) { |
+ DCHECK(theme_service_); |
return theme_service_->BuildLabel(text, ui::kGdkBlack); |
} |
GtkWidget* InfoBarGtk::CreateLinkButton(const std::string& text) { |
+ DCHECK(theme_service_); |
return theme_service_->BuildChromeLinkButton(text); |
} |
@@ -158,6 +118,7 @@ |
const string16& link_text, |
size_t link_offset, |
GCallback callback) { |
+ DCHECK(hbox_); |
GtkWidget* link_button = CreateLinkButton(UTF16ToUTF8(link_text)); |
gtk_util::ForceFontSizePixels( |
GTK_CHROME_LINK_BUTTON(link_button)->label, 13.4); |
@@ -200,6 +161,7 @@ |
void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type, |
double* r, double* g, double* b) { |
+ DCHECK(theme_service_); |
SkColor color = theme_service_->UsingNativeTheme() ? |
theme_service_->GetColor(ThemeProperties::COLOR_TOOLBAR) : |
GetInfoBarTopColor(type); |
@@ -210,6 +172,7 @@ |
void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, |
double* r, double* g, double* b) { |
+ DCHECK(theme_service_); |
SkColor color = theme_service_->UsingNativeTheme() ? |
theme_service_->GetColor(ThemeProperties::COLOR_TOOLBAR) : |
GetInfoBarBottomColor(type); |
@@ -219,13 +182,14 @@ |
} |
void InfoBarGtk::UpdateBorderColor() { |
+ DCHECK(widget()); |
gtk_widget_queue_draw(widget()); |
} |
void InfoBarGtk::OnCloseButton(GtkWidget* button) { |
// If we're not owned, we're already closing, so don't call |
// InfoBarDismissed(), since this can lead to us double-recording dismissals. |
- if (delegate() && owned()) |
+ if (delegate() && owner()) |
delegate()->InfoBarDismissed(); |
RemoveSelf(); |
} |
@@ -233,6 +197,7 @@ |
gboolean InfoBarGtk::OnBackgroundExpose(GtkWidget* sender, |
GdkEventExpose* event) { |
TRACE_EVENT0("ui::gtk", "InfoBarGtk::OnBackgroundExpose"); |
+ DCHECK(theme_service_); |
GtkAllocation allocation; |
gtk_widget_get_allocation(sender, &allocation); |
@@ -277,6 +242,11 @@ |
} |
void InfoBarGtk::PlatformSpecificShow(bool animate) { |
+ if (!theme_service_) |
+ InitWidgets(); |
+ DCHECK(bg_box_); |
+ |
+ DCHECK(widget()); |
gtk_widget_show_all(widget_.get()); |
gtk_widget_set_size_request(widget_.get(), -1, bar_height()); |
@@ -293,6 +263,8 @@ |
} |
void InfoBarGtk::PlatformSpecificOnHeightsRecalculated() { |
+ DCHECK(bg_box_); |
+ DCHECK(widget()); |
gtk_widget_set_size_request(bg_box_, -1, bar_target_height()); |
gtk_expanded_container_move(GTK_EXPANDED_CONTAINER(widget_.get()), |
bg_box_, 0, |
@@ -305,6 +277,56 @@ |
void InfoBarGtk::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
+ DCHECK(widget()); |
+ UpdateBorderColor(); |
+} |
+ |
+void InfoBarGtk::InitWidgets() { |
+ theme_service_ = GtkThemeService::GetFrom(Profile::FromBrowserContext( |
+ owner()->GetWebContents()->GetBrowserContext())); |
+ |
+ // Create |hbox_| and pad the sides. |
+ hbox_ = gtk_hbox_new(FALSE, kElementPadding); |
+ |
+ // Make the whole infor bar horizontally shrinkable. |
+ gtk_widget_set_size_request(hbox_, 0, -1); |
+ |
+ GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1); |
+ gtk_alignment_set_padding(GTK_ALIGNMENT(padding), |
+ 0, 0, kLeftPadding, kRightPadding); |
+ |
+ bg_box_ = gtk_event_box_new(); |
+ gtk_widget_set_app_paintable(bg_box_, TRUE); |
+ g_signal_connect(bg_box_, "expose-event", |
+ G_CALLBACK(OnBackgroundExposeThunk), this); |
+ gtk_container_add(GTK_CONTAINER(padding), hbox_); |
+ gtk_container_add(GTK_CONTAINER(bg_box_), padding); |
+ |
+ // Add the icon on the left, if any. |
+ gfx::Image* icon = delegate()->GetIcon(); |
+ if (icon) { |
+ GtkWidget* image = gtk_image_new_from_pixbuf(icon->ToGdkPixbuf()); |
+ |
+ gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5); |
+ |
+ gtk_box_pack_start(GTK_BOX(hbox_), image, FALSE, FALSE, 0); |
+ } |
+ |
+ close_button_.reset(CustomDrawButton::CloseButtonBar(theme_service_)); |
+ gtk_util::CenterWidgetInHBox(hbox_, close_button_->widget(), true, 0); |
+ signals_->Connect(close_button_->widget(), "clicked", |
+ G_CALLBACK(OnCloseButtonThunk), this); |
+ |
+ widget_.Own(gtk_expanded_container_new()); |
+ gtk_container_add(GTK_CONTAINER(widget_.get()), bg_box_); |
+ gtk_widget_set_size_request(widget_.get(), -1, 0); |
+ |
+ g_signal_connect(widget_.get(), "child-size-request", |
+ G_CALLBACK(OnChildSizeRequestThunk), |
+ this); |
+ |
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
+ content::Source<ThemeService>(theme_service_)); |
UpdateBorderColor(); |
} |