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

Side by Side Diff: chrome/browser/gtk/repost_form_warning_gtk.cc

Issue 660434: Make repost form warning tab-modal on Gtk. (Closed)
Patch Set: Fixed a small bug when two tabmodal dialogs were shown. Created 10 years, 9 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/repost_form_warning_gtk.h" 5 #include "chrome/browser/gtk/repost_form_warning_gtk.h"
6 6
7 #include "app/gtk_util.h" 7 #include "app/gtk_util.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/gtk/gtk_util.h" 10 #include "chrome/browser/gtk/gtk_util.h"
11 #include "chrome/browser/tab_contents/navigation_controller.h" 11 #include "chrome/browser/tab_contents/navigation_controller.h"
12 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/common/notification_service.h" 13 #include "chrome/common/notification_service.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 15
15 RepostFormWarningGtk::RepostFormWarningGtk( 16 RepostFormWarningGtk::RepostFormWarningGtk(GtkWindow* parent,
16 GtkWindow* parent, 17 TabContents* tab_contents)
17 NavigationController* navigation_controller) 18 : navigation_controller_(&tab_contents->controller()) {
18 : navigation_controller_(navigation_controller) { 19 dialog_ = gtk_vbox_new(NULL, gtk_util::kContentAreaBorder);
19 dialog_ = gtk_message_dialog_new( 20 gtk_box_set_spacing(GTK_BOX(dialog_), gtk_util::kContentAreaSpacing);
20 parent, 21 GtkWidget* label = gtk_label_new(
21 GTK_DIALOG_MODAL,
22 GTK_MESSAGE_QUESTION,
23 GTK_BUTTONS_NONE,
24 "%s",
25 l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING).c_str()); 22 l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING).c_str());
26 gtk_util::ApplyMessageDialogQuirks(dialog_); 23 GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
27 gtk_window_set_title(GTK_WINDOW(dialog_), 24 GTK_ICON_SIZE_DIALOG);
28 l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_TITLE).c_str()); 25 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
29 gtk_util::AddButtonToDialog(dialog_,
30 l10n_util::GetStringUTF8(IDS_CANCEL).c_str(),
31 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
32 gtk_util::AddButtonToDialog(dialog_,
33 l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_RESEND).c_str(),
34 GTK_STOCK_REFRESH, GTK_RESPONSE_OK);
35 gtk_util::SetWindowIcon(GTK_WINDOW(dialog_));
36 26
37 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponse), this); 27 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
38 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); 28 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
39 29
40 gtk_widget_show_all(dialog_); 30 GtkWidget *hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing);
31
32 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
33
34 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
35
36 gtk_box_pack_start(GTK_BOX(dialog_), hbox, FALSE, FALSE, 0);
37
38 GtkWidget* buttonBox = gtk_hbutton_box_new();
39 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
40 gtk_box_set_spacing(GTK_BOX(buttonBox), gtk_util::kControlSpacing);
41 gtk_box_pack_end(GTK_BOX(dialog_), buttonBox, FALSE, TRUE, 0);
42
43 cancel_ = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
44 gtk_button_set_label(GTK_BUTTON(cancel_),
45 l10n_util::GetStringUTF8(IDS_CANCEL).c_str());
46 g_signal_connect(cancel_, "clicked", G_CALLBACK(OnCancelThunk), this);
47 gtk_box_pack_end(GTK_BOX(buttonBox), cancel_, FALSE, TRUE, 0);
48
49 ok_ = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
50 gtk_button_set_label(
51 GTK_BUTTON(ok_),
52 l10n_util::GetStringUTF8(IDS_HTTP_POST_WARNING_RESEND).c_str());
53 g_signal_connect(ok_, "clicked", G_CALLBACK(OnRefreshThunk), this);
54 gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0);
55
56 g_signal_connect(cancel_, "hierarchy-changed",
57 G_CALLBACK(OnHierarchyChangedThunk), this);
58
59 window_ = tab_contents->CreateConstrainedDialog(this);
41 60
42 registrar_.Add(this, NotificationType::LOAD_START, 61 registrar_.Add(this, NotificationType::LOAD_START,
43 Source<NavigationController>(navigation_controller_)); 62 Source<NavigationController>(navigation_controller_));
44 registrar_.Add(this, NotificationType::TAB_CLOSING, 63 registrar_.Add(this, NotificationType::TAB_CLOSING,
45 Source<NavigationController>(navigation_controller_)); 64 Source<NavigationController>(navigation_controller_));
65 registrar_.Add(this, NotificationType::RELOADING,
66 Source<NavigationController>(navigation_controller_));
67
46 } 68 }
47 69
48 RepostFormWarningGtk::~RepostFormWarningGtk() { 70 RepostFormWarningGtk::~RepostFormWarningGtk() {
49 } 71 }
50 72
73 GtkWidget* RepostFormWarningGtk::GetWidgetRoot() {
74 return dialog_;
75 }
76
77 void RepostFormWarningGtk::DeleteDelegate() {
78 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
79 }
80
51 void RepostFormWarningGtk::Observe(NotificationType type, 81 void RepostFormWarningGtk::Observe(NotificationType type,
52 const NotificationSource& source, 82 const NotificationSource& source,
53 const NotificationDetails& details) { 83 const NotificationDetails& details) {
54 // Close the dialog if we load a page (because reloading might not apply to 84 // Close the dialog if we load a page (because reloading might not apply to
55 // the same page anymore) or if the tab is closed, because then we won't have 85 // the same page anymore) or if the tab is closed, because then we won't have
56 // a navigation controller anymore. 86 // a navigation controller anymore.
57 if (dialog_ && navigation_controller_ && 87 if (dialog_ && navigation_controller_ &&
58 (type == NotificationType::LOAD_START || 88 (type == NotificationType::LOAD_START ||
59 type == NotificationType::TAB_CLOSING)) { 89 type == NotificationType::TAB_CLOSING ||
90 type == NotificationType::RELOADING)) {
60 DCHECK_EQ(Source<NavigationController>(source).ptr(), 91 DCHECK_EQ(Source<NavigationController>(source).ptr(),
61 navigation_controller_); 92 navigation_controller_);
62 navigation_controller_ = NULL; 93 OnCancel(dialog_);
63 Destroy();
64 } 94 }
65 } 95 }
66 96
67 void RepostFormWarningGtk::Destroy() { 97 void RepostFormWarningGtk::Destroy() {
68 if (dialog_) { 98 if (dialog_) {
69 gtk_widget_destroy(dialog_); 99 gtk_widget_destroy(dialog_);
70 dialog_ = NULL; 100 dialog_ = NULL;
71 } 101 }
102 window_->CloseConstrainedWindow();
72 } 103 }
73 104
74 // static 105 void RepostFormWarningGtk::OnRefresh(GtkWidget* widget) {
75 void RepostFormWarningGtk::OnResponse(GtkWidget* widget, int response, 106 if (navigation_controller_) {
76 RepostFormWarningGtk* dialog) { 107 navigation_controller_->ContinuePendingReload();
77 dialog->Destroy(); 108 // reloading the page will close the dialog.
78 if (response == GTK_RESPONSE_OK) {
79 if (dialog->navigation_controller_)
80 dialog->navigation_controller_->Reload(false);
81 } 109 }
82 } 110 }
83 111
84 // static 112 void RepostFormWarningGtk::OnCancel(GtkWidget* widget) {
85 void RepostFormWarningGtk::OnWindowDestroy(GtkWidget* widget, 113 if (navigation_controller_) {
86 RepostFormWarningGtk* dialog) { 114 navigation_controller_->CancelPendingReload();
87 MessageLoop::current()->DeleteSoon(FROM_HERE, dialog); 115 }
116 Destroy();
88 } 117 }
118
119 void RepostFormWarningGtk::OnHierarchyChanged(GtkWidget* root,
120 GtkWidget* previous_toplevel) {
121 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
122 if (!GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(cancel_))) {
123 return;
124 }
125 gtk_widget_grab_focus(cancel_);
126 }
127
OLDNEW
« no previous file with comments | « chrome/browser/gtk/repost_form_warning_gtk.h ('k') | chrome/browser/tab_contents/tab_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698