Chromium Code Reviews| 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/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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/gtk/browser_window_gtk.h" | 10 #include "chrome/browser/gtk/browser_window_gtk.h" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 CHROMEGTK_CALLBACK_0(ConfirmInfoBar, void, OnLinkClicked); | 378 CHROMEGTK_CALLBACK_0(ConfirmInfoBar, void, OnLinkClicked); |
| 379 | 379 |
| 380 GtkWidget* confirm_hbox_; | 380 GtkWidget* confirm_hbox_; |
| 381 | 381 |
| 382 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBar); | 382 DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBar); |
| 383 }; | 383 }; |
| 384 | 384 |
| 385 ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) | 385 ConfirmInfoBar::ConfirmInfoBar(ConfirmInfoBarDelegate* delegate) |
| 386 : InfoBar(delegate) { | 386 : InfoBar(delegate) { |
| 387 confirm_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE, 0); | 387 confirm_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE, 0); |
| 388 gtk_box_pack_start(GTK_BOX(hbox_), confirm_hbox_, TRUE, TRUE, 0); | 388 // This alignment allocates the confirm hbox only as much space as it |
| 389 gtk_widget_set_size_request(confirm_hbox_, 0, -1); | 389 // requests, and less if there is not enough available. |
| 390 GtkWidget* align = gtk_alignment_new(0, 0, 0, 1); | |
| 391 gtk_container_add(GTK_CONTAINER(align), confirm_hbox_); | |
| 392 gtk_box_pack_start(GTK_BOX(hbox_), align, TRUE, TRUE, 0); | |
| 393 | |
| 394 // We add the buttons in reverse order and pack end instead of start so | |
| 395 // that the first widget to get shrunk is the label rather than the button(s). | |
| 396 AddButton(ConfirmInfoBarDelegate::BUTTON_OK); | |
| 397 AddButton(ConfirmInfoBarDelegate::BUTTON_CANCEL); | |
| 390 | 398 |
| 391 std::string label_text = UTF16ToUTF8(delegate->GetMessageText()); | 399 std::string label_text = UTF16ToUTF8(delegate->GetMessageText()); |
| 392 GtkWidget* label = gtk_label_new(label_text.c_str()); | 400 GtkWidget* label = gtk_label_new(label_text.c_str()); |
| 393 gtk_util::ForceFontSizePixels(label, 13.4); | 401 gtk_util::ForceFontSizePixels(label, 13.4); |
| 394 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | 402 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
| 395 gtk_util::CenterWidgetInHBox(confirm_hbox_, label, false, kEndOfLabelSpacing); | 403 gtk_util::CenterWidgetInHBox(confirm_hbox_, label, true, kEndOfLabelSpacing); |
| 396 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, >k_util::kGdkBlack); | 404 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, >k_util::kGdkBlack); |
| 397 g_signal_connect(label, "map", | 405 g_signal_connect(label, "map", |
| 398 G_CALLBACK(gtk_util::InitLabelSizeRequestAndEllipsizeMode), | 406 G_CALLBACK(gtk_util::InitLabelSizeRequestAndEllipsizeMode), |
| 399 NULL); | 407 NULL); |
| 400 | 408 |
| 401 AddButton(ConfirmInfoBarDelegate::BUTTON_CANCEL); | 409 std::string link_text = UTF16ToUTF8(delegate->GetLinkText()); |
| 402 AddButton(ConfirmInfoBarDelegate::BUTTON_OK); | 410 if (link_text.empty()) |
|
Mike Mammarella
2011/01/13 23:01:12
Is this related to the bug, or just incidentally a
Evan Stade
2011/01/13 23:14:18
incidental. I noticed that for the sessions restor
| |
| 411 return; | |
| 403 | 412 |
| 404 std::string link_text = UTF16ToUTF8(delegate->GetLinkText()); | |
| 405 GtkWidget* link = gtk_chrome_link_button_new(link_text.c_str()); | 413 GtkWidget* link = gtk_chrome_link_button_new(link_text.c_str()); |
| 406 gtk_misc_set_alignment(GTK_MISC(GTK_CHROME_LINK_BUTTON(link)->label), 0, 0.5); | 414 gtk_misc_set_alignment(GTK_MISC(GTK_CHROME_LINK_BUTTON(link)->label), 0, 0.5); |
| 407 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this); | 415 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this); |
| 408 gtk_util::SetButtonTriggersNavigation(link); | 416 gtk_util::SetButtonTriggersNavigation(link); |
| 409 // Until we switch to vector graphics, force the font size. | 417 // Until we switch to vector graphics, force the font size. |
| 410 // 13.4px == 10pt @ 96dpi | 418 // 13.4px == 10pt @ 96dpi |
| 411 gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link)->label, 13.4); | 419 gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link)->label, 13.4); |
| 412 gtk_util::CenterWidgetInHBox(hbox_, link, true, kEndOfLabelSpacing); | 420 gtk_util::CenterWidgetInHBox(hbox_, link, true, kEndOfLabelSpacing); |
| 413 } | 421 } |
| 414 | 422 |
| 415 void ConfirmInfoBar::AddButton(ConfirmInfoBarDelegate::InfoBarButton type) { | 423 void ConfirmInfoBar::AddButton(ConfirmInfoBarDelegate::InfoBarButton type) { |
| 416 if (delegate_->AsConfirmInfoBarDelegate()->GetButtons() & type) { | 424 if (delegate_->AsConfirmInfoBarDelegate()->GetButtons() & type) { |
| 417 GtkWidget* button = gtk_button_new_with_label(UTF16ToUTF8( | 425 GtkWidget* button = gtk_button_new_with_label(UTF16ToUTF8( |
| 418 delegate_->AsConfirmInfoBarDelegate()->GetButtonLabel(type)).c_str()); | 426 delegate_->AsConfirmInfoBarDelegate()->GetButtonLabel(type)).c_str()); |
| 419 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, false, | 427 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, true, |
| 420 kButtonButtonSpacing); | 428 kButtonButtonSpacing); |
| 421 g_signal_connect(button, "clicked", | 429 g_signal_connect(button, "clicked", |
| 422 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? | 430 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? |
| 423 OnOkButtonThunk : OnCancelButtonThunk), | 431 OnOkButtonThunk : OnCancelButtonThunk), |
| 424 this); | 432 this); |
| 425 } | 433 } |
| 426 } | 434 } |
| 427 | 435 |
| 428 void ConfirmInfoBar::OnCancelButton(GtkWidget* widget) { | 436 void ConfirmInfoBar::OnCancelButton(GtkWidget* widget) { |
| 429 if (delegate_->AsConfirmInfoBarDelegate()->Cancel()) | 437 if (delegate_->AsConfirmInfoBarDelegate()->Cancel()) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 444 | 452 |
| 445 InfoBar* AlertInfoBarDelegate::CreateInfoBar() { | 453 InfoBar* AlertInfoBarDelegate::CreateInfoBar() { |
| 446 return new AlertInfoBar(this); | 454 return new AlertInfoBar(this); |
| 447 } | 455 } |
| 448 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { | 456 InfoBar* LinkInfoBarDelegate::CreateInfoBar() { |
| 449 return new LinkInfoBar(this); | 457 return new LinkInfoBar(this); |
| 450 } | 458 } |
| 451 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { | 459 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { |
| 452 return new ConfirmInfoBar(this); | 460 return new ConfirmInfoBar(this); |
| 453 } | 461 } |
| OLD | NEW |