Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc

Issue 7066031: GTK: Buttons on Confirm Infobars should have matching sizes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/infobars/confirm_infobar_gtk.h" 5 #include "chrome/browser/ui/gtk/infobars/confirm_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/ui/gtk/gtk_chrome_link_button.h" 10 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
11 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h" 11 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h"
12 #include "chrome/browser/ui/gtk/gtk_util.h" 12 #include "chrome/browser/ui/gtk/gtk_util.h"
13 13
14 // ConfirmInfoBarDelegate ------------------------------------------------------ 14 // ConfirmInfoBarDelegate ------------------------------------------------------
15 15
16 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { 16 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() {
17 return new ConfirmInfoBarGtk(this); 17 return new ConfirmInfoBarGtk(this);
18 } 18 }
19 19
20 // ConfirmInfoBarGtk ----------------------------------------------------------- 20 // ConfirmInfoBarGtk -----------------------------------------------------------
21 21
22 ConfirmInfoBarGtk::ConfirmInfoBarGtk(ConfirmInfoBarDelegate* delegate) 22 ConfirmInfoBarGtk::ConfirmInfoBarGtk(ConfirmInfoBarDelegate* delegate)
23 : InfoBar(delegate) { 23 : InfoBar(delegate),
24 size_group_(NULL) {
24 confirm_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE, 25 confirm_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE,
25 kEndOfLabelSpacing); 26 kEndOfLabelSpacing);
26 // This alignment allocates the confirm hbox only as much space as it 27 // This alignment allocates the confirm hbox only as much space as it
27 // requests, and less if there is not enough available. 28 // requests, and less if there is not enough available.
28 GtkWidget* align = gtk_alignment_new(0, 0, 0, 1); 29 GtkWidget* align = gtk_alignment_new(0, 0, 0, 1);
29 gtk_container_add(GTK_CONTAINER(align), confirm_hbox_); 30 gtk_container_add(GTK_CONTAINER(align), confirm_hbox_);
30 gtk_box_pack_start(GTK_BOX(hbox_), align, TRUE, TRUE, 0); 31 gtk_box_pack_start(GTK_BOX(hbox_), align, TRUE, TRUE, 0);
31 32
32 // We add the buttons in reverse order and pack end instead of start so 33 // We add the buttons in reverse order and pack end instead of start so
33 // that the first widget to get shrunk is the label rather than the button(s). 34 // that the first widget to get shrunk is the label rather than the button(s).
34 AddButton(ConfirmInfoBarDelegate::BUTTON_OK); 35 AddButton(ConfirmInfoBarDelegate::BUTTON_OK);
35 AddButton(ConfirmInfoBarDelegate::BUTTON_CANCEL); 36 AddButton(ConfirmInfoBarDelegate::BUTTON_CANCEL);
Elliot Glaysher 2011/05/24 20:27:29 Despite the class comments, this appears to be the
36 37
37 std::string label_text = UTF16ToUTF8(delegate->GetMessageText()); 38 std::string label_text = UTF16ToUTF8(delegate->GetMessageText());
38 GtkWidget* label = gtk_label_new(label_text.c_str()); 39 GtkWidget* label = gtk_label_new(label_text.c_str());
39 gtk_util::ForceFontSizePixels(label, 13.4); 40 gtk_util::ForceFontSizePixels(label, 13.4);
40 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); 41 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
41 gtk_util::CenterWidgetInHBox(confirm_hbox_, label, true, 0); 42 gtk_util::CenterWidgetInHBox(confirm_hbox_, label, true, 0);
42 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gtk_util::kGdkBlack); 43 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gtk_util::kGdkBlack);
43 g_signal_connect(label, "map", 44 g_signal_connect(label, "map",
44 G_CALLBACK(gtk_util::InitLabelSizeRequestAndEllipsizeMode), 45 G_CALLBACK(gtk_util::InitLabelSizeRequestAndEllipsizeMode),
45 NULL); 46 NULL);
46 47
47 std::string link_text = UTF16ToUTF8(delegate->GetLinkText()); 48 std::string link_text = UTF16ToUTF8(delegate->GetLinkText());
48 if (link_text.empty()) 49 if (link_text.empty())
49 return; 50 return;
50 51
51 GtkWidget* link = gtk_chrome_link_button_new(link_text.c_str()); 52 GtkWidget* link = gtk_chrome_link_button_new(link_text.c_str());
52 gtk_misc_set_alignment(GTK_MISC(GTK_CHROME_LINK_BUTTON(link)->label), 0, 0.5); 53 gtk_misc_set_alignment(GTK_MISC(GTK_CHROME_LINK_BUTTON(link)->label), 0, 0.5);
53 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this); 54 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this);
54 gtk_util::SetButtonTriggersNavigation(link); 55 gtk_util::SetButtonTriggersNavigation(link);
55 // Until we switch to vector graphics, force the font size. 56 // Until we switch to vector graphics, force the font size.
56 // 13.4px == 10pt @ 96dpi 57 // 13.4px == 10pt @ 96dpi
57 gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link)->label, 13.4); 58 gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link)->label, 13.4);
58 gtk_util::CenterWidgetInHBox(hbox_, link, true, kEndOfLabelSpacing); 59 gtk_util::CenterWidgetInHBox(hbox_, link, true, kEndOfLabelSpacing);
59 } 60 }
60 61
61 ConfirmInfoBarGtk::~ConfirmInfoBarGtk() { 62 ConfirmInfoBarGtk::~ConfirmInfoBarGtk() {
63 if (size_group_)
64 g_object_unref(size_group_);
62 } 65 }
63 66
64 void ConfirmInfoBarGtk::AddButton(ConfirmInfoBarDelegate::InfoBarButton type) { 67 void ConfirmInfoBarGtk::AddButton(ConfirmInfoBarDelegate::InfoBarButton type) {
65 if (delegate_->AsConfirmInfoBarDelegate()->GetButtons() & type) { 68 if (delegate_->AsConfirmInfoBarDelegate()->GetButtons() & type) {
69 if (!size_group_)
70 size_group_ = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
71
66 GtkWidget* button = gtk_button_new_with_label(UTF16ToUTF8( 72 GtkWidget* button = gtk_button_new_with_label(UTF16ToUTF8(
67 delegate_->AsConfirmInfoBarDelegate()->GetButtonLabel(type)).c_str()); 73 delegate_->AsConfirmInfoBarDelegate()->GetButtonLabel(type)).c_str());
74 gtk_size_group_add_widget(size_group_, button);
75
68 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, true, 0); 76 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, true, 0);
69 g_signal_connect(button, "clicked", 77 g_signal_connect(button, "clicked",
70 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ? 78 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ?
71 OnOkButtonThunk : OnCancelButtonThunk), 79 OnOkButtonThunk : OnCancelButtonThunk),
72 this); 80 this);
73 } 81 }
74 } 82 }
75 83
76 void ConfirmInfoBarGtk::OnOkButton(GtkWidget* widget) { 84 void ConfirmInfoBarGtk::OnOkButton(GtkWidget* widget) {
77 if (delegate_->AsConfirmInfoBarDelegate()->Accept()) 85 if (delegate_->AsConfirmInfoBarDelegate()->Accept())
78 RemoveInfoBar(); 86 RemoveInfoBar();
79 } 87 }
80 88
81 void ConfirmInfoBarGtk::OnCancelButton(GtkWidget* widget) { 89 void ConfirmInfoBarGtk::OnCancelButton(GtkWidget* widget) {
82 if (delegate_->AsConfirmInfoBarDelegate()->Cancel()) 90 if (delegate_->AsConfirmInfoBarDelegate()->Cancel())
83 RemoveInfoBar(); 91 RemoveInfoBar();
84 } 92 }
85 93
86 void ConfirmInfoBarGtk::OnLinkClicked(GtkWidget* widget) { 94 void ConfirmInfoBarGtk::OnLinkClicked(GtkWidget* widget) {
87 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked( 95 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked(
88 gtk_util::DispositionForCurrentButtonPressEvent())) { 96 gtk_util::DispositionForCurrentButtonPressEvent())) {
89 RemoveInfoBar(); 97 RemoveInfoBar();
90 } 98 }
91 } 99 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698