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
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/gtk/repost_form_warning_gtk.h"
6
7#include "base/message_loop.h"
8#include "chrome/browser/repost_form_warning_controller.h"
9#include "chrome/browser/ui/gtk/gtk_util.h"
10#include "content/browser/browser_thread.h"
11#include "content/browser/tab_contents/navigation_controller.h"
12#include "content/browser/tab_contents/tab_contents.h"
13#include "content/common/notification_type.h"
14#include "grit/generated_resources.h"
15#include "ui/base/l10n/l10n_util.h"
16
17RepostFormWarningGtk::RepostFormWarningGtk(GtkWindow* parent,
18                                           TabContents* tab_contents)
19    : controller_(new RepostFormWarningController(tab_contents)) {
20  dialog_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaBorder);
21  gtk_box_set_spacing(GTK_BOX(dialog_), gtk_util::kContentAreaSpacing);
22  GtkWidget* label = gtk_label_new(
23      l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING).c_str());
24  GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
25                                              GTK_ICON_SIZE_DIALOG);
26  gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
27
28  gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
29  gtk_label_set_selectable(GTK_LABEL(label), TRUE);
30
31  GtkWidget *hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing);
32
33  gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
34
35  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
36
37  gtk_box_pack_start(GTK_BOX(dialog_), hbox, FALSE, FALSE, 0);
38
39  GtkWidget* buttonBox = gtk_hbutton_box_new();
40  gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
41  gtk_box_set_spacing(GTK_BOX(buttonBox), gtk_util::kControlSpacing);
42  gtk_box_pack_end(GTK_BOX(dialog_), buttonBox, FALSE, TRUE, 0);
43
44  cancel_ = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
45  gtk_button_set_label(GTK_BUTTON(cancel_),
46                       l10n_util::GetStringUTF8(IDS_CANCEL).c_str());
47  g_signal_connect(cancel_, "clicked", G_CALLBACK(OnCancelThunk), this);
48  gtk_box_pack_end(GTK_BOX(buttonBox), cancel_, FALSE, TRUE, 0);
49
50  ok_ = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
51  gtk_button_set_label(
52      GTK_BUTTON(ok_),
53      l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_RESEND).c_str());
54  g_signal_connect(ok_, "clicked", G_CALLBACK(OnRefreshThunk), this);
55  gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0);
56
57  controller_->Show(this);
58}
59
60GtkWidget* RepostFormWarningGtk::GetWidgetRoot() {
61  return dialog_;
62}
63
64GtkWidget* RepostFormWarningGtk::GetFocusWidget() {
65  return cancel_;
66}
67
68void RepostFormWarningGtk::DeleteDelegate() {
69  delete this;
70}
71
72RepostFormWarningGtk::~RepostFormWarningGtk() {
73  gtk_widget_destroy(dialog_);
74}
75
76void RepostFormWarningGtk::OnRefresh(GtkWidget* widget) {
77  controller_->Continue();
78}
79
80void RepostFormWarningGtk::OnCancel(GtkWidget* widget) {
81  controller_->Cancel();
82}
83