| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/infobar_gtk.h" | 5 #include "chrome/browser/gtk/infobar_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "app/gfx/gtk_util.h" | 9 #include "app/gfx/gtk_util.h" |
| 10 #include "base/gfx/gtk_util.h" | 10 #include "base/gfx/gtk_util.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 // Add the icon on the left, if any. | 57 // Add the icon on the left, if any. |
| 58 SkBitmap* icon = delegate->GetIcon(); | 58 SkBitmap* icon = delegate->GetIcon(); |
| 59 if (icon) { | 59 if (icon) { |
| 60 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(icon); | 60 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(icon); |
| 61 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); | 61 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 62 g_object_unref(pixbuf); | 62 g_object_unref(pixbuf); |
| 63 gtk_box_pack_start(GTK_BOX(hbox_), image, FALSE, FALSE, 0); | 63 gtk_box_pack_start(GTK_BOX(hbox_), image, FALSE, FALSE, 0); |
| 64 } | 64 } |
| 65 | 65 |
| 66 close_button_.reset(CustomDrawButton::AddBarCloseButton(hbox_, 0)); | 66 close_button_.reset(CustomDrawButton::CloseButton()); |
| 67 gtk_util::CenterWidgetInHBox(hbox_, close_button_->widget(), true, 0); |
| 67 g_signal_connect(close_button_->widget(), "clicked", | 68 g_signal_connect(close_button_->widget(), "clicked", |
| 68 G_CALLBACK(OnCloseButton), this); | 69 G_CALLBACK(OnCloseButton), this); |
| 69 | 70 |
| 70 slide_widget_.reset(new SlideAnimatorGtk(border_bin_.get(), | 71 slide_widget_.reset(new SlideAnimatorGtk(border_bin_.get(), |
| 71 SlideAnimatorGtk::DOWN, | 72 SlideAnimatorGtk::DOWN, |
| 72 0, true, this)); | 73 0, true, this)); |
| 73 // We store a pointer back to |this| so we can refer to it from the infobar | 74 // We store a pointer back to |this| so we can refer to it from the infobar |
| 74 // container. | 75 // container. |
| 75 g_object_set_data(G_OBJECT(slide_widget_->widget()), "info-bar", this); | 76 g_object_set_data(G_OBJECT(slide_widget_->widget()), "info-bar", this); |
| 76 } | 77 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 GtkWidget* trailing_label = gtk_label_new( | 165 GtkWidget* trailing_label = gtk_label_new( |
| 165 WideToUTF8(display_text.substr(link_offset)).c_str()); | 166 WideToUTF8(display_text.substr(link_offset)).c_str()); |
| 166 | 167 |
| 167 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); | 168 gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); |
| 168 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); | 169 gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, &gfx::kGdkBlack); |
| 169 | 170 |
| 170 // We don't want any spacing between the elements, so we pack them into | 171 // We don't want any spacing between the elements, so we pack them into |
| 171 // this hbox that doesn't use kElementPadding. | 172 // this hbox that doesn't use kElementPadding. |
| 172 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | 173 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
| 173 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0); | 174 gtk_box_pack_start(GTK_BOX(hbox), initial_label, FALSE, FALSE, 0); |
| 174 gtk_box_pack_start(GTK_BOX(hbox), link_button_->widget(), | 175 gtk_util::CenterWidgetInHBox(hbox, link_button_->widget(), false, 0); |
| 175 FALSE, FALSE, 0); | |
| 176 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); | 176 gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); |
| 177 gtk_box_pack_start(GTK_BOX(hbox_), hbox, FALSE, FALSE, 0); | 177 gtk_box_pack_start(GTK_BOX(hbox_), hbox, FALSE, FALSE, 0); |
| 178 } | 178 } |
| 179 | 179 |
| 180 gtk_widget_show_all(border_bin_.get()); | 180 gtk_widget_show_all(border_bin_.get()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { | 184 static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { |
| 185 // TODO(estade): we need an equivalent for DispositionFromEventFlags(). | 185 // TODO(estade): we need an equivalent for DispositionFromEventFlags(). |
| (...skipping 19 matching lines...) Expand all Loading... |
| 205 gtk_widget_show_all(border_bin_.get()); | 205 gtk_widget_show_all(border_bin_.get()); |
| 206 } | 206 } |
| 207 | 207 |
| 208 private: | 208 private: |
| 209 // Adds a button to the info bar by type. It will do nothing if the delegate | 209 // Adds a button to the info bar by type. It will do nothing if the delegate |
| 210 // doesn't specify a button of the given type. | 210 // doesn't specify a button of the given type. |
| 211 void AddConfirmButton(ConfirmInfoBarDelegate::InfoBarButton type) { | 211 void AddConfirmButton(ConfirmInfoBarDelegate::InfoBarButton type) { |
| 212 if (delegate_->AsConfirmInfoBarDelegate()->GetButtons() & type) { | 212 if (delegate_->AsConfirmInfoBarDelegate()->GetButtons() & type) { |
| 213 GtkWidget* button = gtk_button_new_with_label(WideToUTF8( | 213 GtkWidget* button = gtk_button_new_with_label(WideToUTF8( |
| 214 delegate_->AsConfirmInfoBarDelegate()->GetButtonLabel(type)).c_str()); | 214 delegate_->AsConfirmInfoBarDelegate()->GetButtonLabel(type)).c_str()); |
| 215 GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0); | 215 gtk_util::CenterWidgetInHBox(hbox_, button, true, 0); |
| 216 gtk_box_pack_end(GTK_BOX(centering_vbox), button, TRUE, FALSE, 0); | |
| 217 gtk_box_pack_end(GTK_BOX(hbox_), centering_vbox, FALSE, FALSE, 0); | |
| 218 g_signal_connect(button, "clicked", | 216 g_signal_connect(button, "clicked", |
| 219 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? | 217 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? |
| 220 OnOkButton : OnCancelButton), | 218 OnOkButton : OnCancelButton), |
| 221 this); | 219 this); |
| 222 } | 220 } |
| 223 } | 221 } |
| 224 | 222 |
| 225 static void OnCancelButton(GtkWidget* button, ConfirmInfoBar* info_bar) { | 223 static void OnCancelButton(GtkWidget* button, ConfirmInfoBar* info_bar) { |
| 226 if (info_bar->delegate_->AsConfirmInfoBarDelegate()->Cancel()) | 224 if (info_bar->delegate_->AsConfirmInfoBarDelegate()->Cancel()) |
| 227 info_bar->RemoveInfoBar(); | 225 info_bar->RemoveInfoBar(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 243 | 241 |
| 244 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { | 242 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { |
| 245 return new LinkInfoBar(this); | 243 return new LinkInfoBar(this); |
| 246 } | 244 } |
| 247 | 245 |
| 248 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- | 246 // ConfirmInfoBarDelegate, InfoBarDelegate overrides: -------------------------- |
| 249 | 247 |
| 250 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 248 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
| 251 return new ConfirmInfoBar(this); | 249 return new ConfirmInfoBar(this); |
| 252 } | 250 } |
| OLD | NEW |