Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / infobars / confirm_infobar_gtk.cc
blobd32cb3011b5dfaa9654cbf276e476001d314d8d3
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h"
7 #include <gtk/gtk.h>
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/gtk/event_utils.h"
11 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
12 #include "chrome/browser/ui/gtk/gtk_chrome_shrinkable_hbox.h"
13 #include "chrome/browser/ui/gtk/gtk_util.h"
14 #include "ui/base/gtk/gtk_signal_registrar.h"
17 // ConfirmInfoBarDelegate ------------------------------------------------------
19 // static
20 scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar(
21 scoped_ptr<ConfirmInfoBarDelegate> delegate) {
22 return scoped_ptr<InfoBar>(new ConfirmInfoBarGtk(delegate.Pass()));
26 // ConfirmInfoBarGtk -----------------------------------------------------------
28 ConfirmInfoBarGtk::ConfirmInfoBarGtk(
29 scoped_ptr<ConfirmInfoBarDelegate> delegate)
30 : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()),
31 confirm_hbox_(NULL),
32 size_group_(NULL) {
35 ConfirmInfoBarGtk::~ConfirmInfoBarGtk() {
36 if (size_group_)
37 g_object_unref(size_group_);
40 void ConfirmInfoBarGtk::PlatformSpecificSetOwner() {
41 InfoBarGtk::PlatformSpecificSetOwner();
43 confirm_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE,
44 kEndOfLabelSpacing);
45 // This alignment allocates the confirm hbox only as much space as it
46 // requests, and less if there is not enough available.
47 GtkWidget* align = gtk_alignment_new(0, 0, 0, 1);
48 gtk_container_add(GTK_CONTAINER(align), confirm_hbox_);
49 gtk_box_pack_start(GTK_BOX(hbox()), align, TRUE, TRUE, 0);
51 // We add the buttons in reverse order and pack end instead of start so
52 // that the first widget to get shrunk is the label rather than the button(s).
53 AddButton(ConfirmInfoBarDelegate::BUTTON_OK);
54 AddButton(ConfirmInfoBarDelegate::BUTTON_CANCEL);
56 std::string label_text = base::UTF16ToUTF8(GetDelegate()->GetMessageText());
57 GtkWidget* label = CreateLabel(label_text);
58 gtk_util::ForceFontSizePixels(label, 13.4);
59 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
60 gtk_util::CenterWidgetInHBox(confirm_hbox_, label, true, 0);
61 signals()->Connect(label, "map",
62 G_CALLBACK(gtk_util::InitLabelSizeRequestAndEllipsizeMode),
63 NULL);
65 std::string link_text = base::UTF16ToUTF8(GetDelegate()->GetLinkText());
66 if (link_text.empty())
67 return;
69 GtkWidget* link = CreateLinkButton(link_text);
70 gtk_misc_set_alignment(GTK_MISC(GTK_CHROME_LINK_BUTTON(link)->label), 0, 0.5);
71 signals()->Connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this);
72 gtk_util::SetButtonTriggersNavigation(link);
73 // Until we switch to vector graphics, force the font size.
74 // 13.4px == 10pt @ 96dpi
75 gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link)->label, 13.4);
76 gtk_util::CenterWidgetInHBox(hbox(), link, true, kEndOfLabelSpacing);
79 ConfirmInfoBarDelegate* ConfirmInfoBarGtk::GetDelegate() {
80 return delegate()->AsConfirmInfoBarDelegate();
83 void ConfirmInfoBarGtk::AddButton(ConfirmInfoBarDelegate::InfoBarButton type) {
84 DCHECK(confirm_hbox_);
85 if (delegate()->AsConfirmInfoBarDelegate()->GetButtons() & type) {
86 if (!size_group_)
87 size_group_ = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
89 GtkWidget* button = gtk_button_new_with_label(base::UTF16ToUTF8(
90 delegate()->AsConfirmInfoBarDelegate()->GetButtonLabel(type)).c_str());
91 gtk_size_group_add_widget(size_group_, button);
93 gtk_util::CenterWidgetInHBox(confirm_hbox_, button, true, 0);
94 signals()->Connect(button, "clicked",
95 G_CALLBACK(type == ConfirmInfoBarDelegate::BUTTON_OK ?
96 OnOkButtonThunk : OnCancelButtonThunk),
97 this);
101 void ConfirmInfoBarGtk::OnOkButton(GtkWidget* widget) {
102 if (delegate()->AsConfirmInfoBarDelegate()->Accept())
103 RemoveSelf();
106 void ConfirmInfoBarGtk::OnCancelButton(GtkWidget* widget) {
107 if (delegate()->AsConfirmInfoBarDelegate()->Cancel())
108 RemoveSelf();
111 void ConfirmInfoBarGtk::OnLinkClicked(GtkWidget* widget) {
112 if (delegate()->AsConfirmInfoBarDelegate()->LinkClicked(
113 event_utils::DispositionForCurrentButtonPressEvent()))
114 RemoveSelf();