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

Side by Side Diff: chrome/browser/ui/gtk/js_modal_dialog_gtk.cc

Issue 8553001: views: Add an Options enum to MessageBoxView control. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adding an IPC_MESSAGE_EXPORT to line 30 of param_traits_macro.h makes it link in shared build Created 9 years 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
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/js_modal_dialog_gtk.h" 5 #include "chrome/browser/ui/gtk/js_modal_dialog_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" 11 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
12 #include "chrome/browser/ui/gtk/gtk_util.h" 12 #include "chrome/browser/ui/gtk/gtk_util.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "grit/locale_settings.h" 14 #include "grit/locale_settings.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/message_box_flags.h"
17 #include "ui/base/ui_base_types.h" 16 #include "ui/base/ui_base_types.h"
18 17
19 namespace { 18 namespace {
20 19
21 // We stash pointers to widgets on the gtk_dialog so we can refer to them 20 // We stash pointers to widgets on the gtk_dialog so we can refer to them
22 // after dialog creation. 21 // after dialog creation.
23 const char kPromptTextId[] = "chrome_prompt_text"; 22 const char kPromptTextId[] = "chrome_prompt_text";
24 const char kSuppressCheckboxId[] = "chrome_suppress_checkbox"; 23 const char kSuppressCheckboxId[] = "chrome_suppress_checkbox";
25 24
26 // If there's a text entry in the dialog, get the text from the first one and 25 // If there's a text entry in the dialog, get the text from the first one and
(...skipping 22 matching lines...) Expand all
49 // JSModalDialogGtk, public: 48 // JSModalDialogGtk, public:
50 49
51 JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog, 50 JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog,
52 gfx::NativeWindow parent_window) 51 gfx::NativeWindow parent_window)
53 : dialog_(dialog) { 52 : dialog_(dialog) {
54 GtkButtonsType buttons = GTK_BUTTONS_NONE; 53 GtkButtonsType buttons = GTK_BUTTONS_NONE;
55 GtkMessageType message_type = GTK_MESSAGE_OTHER; 54 GtkMessageType message_type = GTK_MESSAGE_OTHER;
56 55
57 // We add in the OK button manually later because we want to focus it 56 // We add in the OK button manually later because we want to focus it
58 // explicitly. 57 // explicitly.
59 switch (dialog_->dialog_flags()) { 58 switch (dialog_->javascript_message_type()) {
60 case ui::MessageBoxFlags::kIsJavascriptAlert: 59 case ui::JAVASCRIPT_MESSAGE_TYPE_ALERT:
61 buttons = GTK_BUTTONS_NONE; 60 buttons = GTK_BUTTONS_NONE;
62 message_type = GTK_MESSAGE_WARNING; 61 message_type = GTK_MESSAGE_WARNING;
63 break; 62 break;
64 63
65 case ui::MessageBoxFlags::kIsJavascriptConfirm: 64 case ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
66 if (dialog_->is_before_unload_dialog()) { 65 if (dialog_->is_before_unload_dialog()) {
67 // onbeforeunload also uses a confirm prompt, it just has custom 66 // onbeforeunload also uses a confirm prompt, it just has custom
68 // buttons. We add the buttons using gtk_dialog_add_button below. 67 // buttons. We add the buttons using gtk_dialog_add_button below.
69 buttons = GTK_BUTTONS_NONE; 68 buttons = GTK_BUTTONS_NONE;
70 } else { 69 } else {
71 buttons = GTK_BUTTONS_CANCEL; 70 buttons = GTK_BUTTONS_CANCEL;
72 } 71 }
73 message_type = GTK_MESSAGE_QUESTION; 72 message_type = GTK_MESSAGE_QUESTION;
74 break; 73 break;
75 74
76 case ui::MessageBoxFlags::kIsJavascriptPrompt: 75 case ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT:
77 buttons = GTK_BUTTONS_CANCEL; 76 buttons = GTK_BUTTONS_CANCEL;
78 message_type = GTK_MESSAGE_QUESTION; 77 message_type = GTK_MESSAGE_QUESTION;
79 break; 78 break;
80 79
81 default: 80 default:
82 NOTREACHED(); 81 NOTREACHED();
83 } 82 }
84 83
85 // We want the alert to be app modal so put all the browser windows into the 84 // We want the alert to be app modal so put all the browser windows into the
86 // same window group. 85 // same window group.
87 gtk_util::MakeAppModalWindowGroup(); 86 gtk_util::MakeAppModalWindowGroup();
88 87
89 gtk_dialog_ = gtk_message_dialog_new(parent_window, 88 gtk_dialog_ = gtk_message_dialog_new(parent_window,
90 GTK_DIALOG_MODAL, message_type, buttons, "%s", 89 GTK_DIALOG_MODAL, message_type, buttons, "%s",
91 UTF16ToUTF8(dialog_->message_text()).c_str()); 90 UTF16ToUTF8(dialog_->message_text()).c_str());
92 g_signal_connect(gtk_dialog_, "delete-event", 91 g_signal_connect(gtk_dialog_, "delete-event",
93 G_CALLBACK(gtk_widget_hide_on_delete), NULL); 92 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
94 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_); 93 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_);
95 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), 94 gtk_window_set_title(GTK_WINDOW(gtk_dialog_),
96 UTF16ToUTF8(dialog_->title()).c_str()); 95 UTF16ToUTF8(dialog_->title()).c_str());
97 96
98 // Adjust content area as needed. Set up the prompt text entry or 97 // Adjust content area as needed. Set up the prompt text entry or
99 // suppression check box. 98 // suppression check box.
100 if (ui::MessageBoxFlags::kIsJavascriptPrompt == dialog_->dialog_flags()) { 99 if (dialog_->javascript_message_type() ==
100 ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) {
101 GtkWidget* content_area = 101 GtkWidget* content_area =
102 gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_)); 102 gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_));
103 GtkWidget* text_box = gtk_entry_new(); 103 GtkWidget* text_box = gtk_entry_new();
104 gtk_entry_set_text(GTK_ENTRY(text_box), 104 gtk_entry_set_text(GTK_ENTRY(text_box),
105 UTF16ToUTF8(dialog_->default_prompt_text()).c_str()); 105 UTF16ToUTF8(dialog_->default_prompt_text()).c_str());
106 gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0); 106 gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0);
107 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); 107 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box);
108 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); 108 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE);
109 } 109 }
110 110
(...skipping 15 matching lines...) Expand all
126 GTK_RESPONSE_OK); 126 GTK_RESPONSE_OK);
127 127
128 button_text = l10n_util::GetStringUTF8( 128 button_text = l10n_util::GetStringUTF8(
129 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); 129 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
130 gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), button_text.c_str(), 130 gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), button_text.c_str(),
131 GTK_RESPONSE_CANCEL); 131 GTK_RESPONSE_CANCEL);
132 } else { 132 } else {
133 // Add the OK button and focus it. 133 // Add the OK button and focus it.
134 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), 134 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_),
135 GTK_STOCK_OK, GTK_RESPONSE_OK); 135 GTK_STOCK_OK, GTK_RESPONSE_OK);
136 if (ui::MessageBoxFlags::kIsJavascriptPrompt != dialog_->dialog_flags()) 136 if (dialog_->javascript_message_type() !=
137 ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT)
137 gtk_widget_grab_focus(ok_button); 138 gtk_widget_grab_focus(ok_button);
138 } 139 }
139 140
140 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); 141 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK);
141 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); 142 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this);
142 } 143 }
143 144
144 JSModalDialogGtk::~JSModalDialogGtk() { 145 JSModalDialogGtk::~JSModalDialogGtk() {
145 } 146 }
146 147
147 //////////////////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////////////
148 // JSModalDialogGtk, NativeAppModalDialog implementation: 149 // JSModalDialogGtk, NativeAppModalDialog implementation:
149 150
150 int JSModalDialogGtk::GetAppModalDialogButtons() const { 151 int JSModalDialogGtk::GetAppModalDialogButtons() const {
151 switch (dialog_->dialog_flags()) { 152 switch (dialog_->javascript_message_type()) {
152 case ui::MessageBoxFlags::kIsJavascriptAlert: 153 case ui::JAVASCRIPT_MESSAGE_TYPE_ALERT:
153 return ui::DIALOG_BUTTON_OK; 154 return ui::DIALOG_BUTTON_OK;
154 155
155 case ui::MessageBoxFlags::kIsJavascriptConfirm: 156 case ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
156 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; 157 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
157 158
158 case ui::MessageBoxFlags::kIsJavascriptPrompt: 159 case ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT:
159 return ui::DIALOG_BUTTON_OK; 160 return ui::DIALOG_BUTTON_OK;
160 161
161 default: 162 default:
162 NOTREACHED(); 163 NOTREACHED();
163 return 0; 164 return 0;
164 } 165 }
165 } 166 }
166 167
167 void JSModalDialogGtk::ShowAppModalDialog() { 168 void JSModalDialogGtk::ShowAppModalDialog() {
168 gtk_util::ShowDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), 169 gtk_util::ShowDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 218
218 //////////////////////////////////////////////////////////////////////////////// 219 ////////////////////////////////////////////////////////////////////////////////
219 // NativeAppModalDialog, public: 220 // NativeAppModalDialog, public:
220 221
221 // static 222 // static
222 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( 223 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt(
223 JavaScriptAppModalDialog* dialog, 224 JavaScriptAppModalDialog* dialog,
224 gfx::NativeWindow parent_window) { 225 gfx::NativeWindow parent_window) {
225 return new JSModalDialogGtk(dialog, parent_window); 226 return new JSModalDialogGtk(dialog, parent_window);
226 } 227 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/js_modal_dialog_cocoa.mm ('k') | chrome/browser/ui/views/external_protocol_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698