OLD | NEW |
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/js_modal_dialog_gtk.h" | 5 #include "chrome/browser/gtk/js_modal_dialog_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/message_box_flags.h" | 10 #include "app/message_box_flags.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } else { | 128 } else { |
129 // Add the OK button and focus it. | 129 // Add the OK button and focus it. |
130 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), | 130 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), |
131 GTK_STOCK_OK, GTK_RESPONSE_OK); | 131 GTK_STOCK_OK, GTK_RESPONSE_OK); |
132 if (MessageBoxFlags::kIsJavascriptPrompt != dialog_->dialog_flags()) | 132 if (MessageBoxFlags::kIsJavascriptPrompt != dialog_->dialog_flags()) |
133 gtk_widget_grab_focus(ok_button); | 133 gtk_widget_grab_focus(ok_button); |
134 } | 134 } |
135 | 135 |
136 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); | 136 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); |
137 g_signal_connect(gtk_dialog_, "response", | 137 g_signal_connect(gtk_dialog_, "response", |
138 G_CALLBACK(JSModalDialogGtk::OnDialogResponse), | 138 G_CALLBACK(OnDialogResponseThunk), this); |
139 reinterpret_cast<JSModalDialogGtk*>(this)); | |
140 } | 139 } |
141 | 140 |
142 JSModalDialogGtk::~JSModalDialogGtk() { | 141 JSModalDialogGtk::~JSModalDialogGtk() { |
143 } | 142 } |
144 | 143 |
145 //////////////////////////////////////////////////////////////////////////////// | 144 //////////////////////////////////////////////////////////////////////////////// |
146 // JSModalDialogGtk, NativeAppModalDialog implementation: | 145 // JSModalDialogGtk, NativeAppModalDialog implementation: |
147 | 146 |
148 int JSModalDialogGtk::GetAppModalDialogButtons() const { | 147 int JSModalDialogGtk::GetAppModalDialogButtons() const { |
149 switch (dialog_->dialog_flags()) { | 148 switch (dialog_->dialog_flags()) { |
(...skipping 17 matching lines...) Expand all Loading... |
167 gtk_util::ShowModalDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), | 166 gtk_util::ShowModalDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), |
168 IDS_ALERT_DIALOG_WIDTH_CHARS); | 167 IDS_ALERT_DIALOG_WIDTH_CHARS); |
169 } | 168 } |
170 | 169 |
171 void JSModalDialogGtk::ActivateAppModalDialog() { | 170 void JSModalDialogGtk::ActivateAppModalDialog() { |
172 DCHECK(gtk_dialog_); | 171 DCHECK(gtk_dialog_); |
173 gtk_window_present(GTK_WINDOW(gtk_dialog_));} | 172 gtk_window_present(GTK_WINDOW(gtk_dialog_));} |
174 | 173 |
175 void JSModalDialogGtk::CloseAppModalDialog() { | 174 void JSModalDialogGtk::CloseAppModalDialog() { |
176 DCHECK(gtk_dialog_); | 175 DCHECK(gtk_dialog_); |
177 HandleDialogResponse(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_DELETE_EVENT); | 176 OnDialogResponse(gtk_dialog_, GTK_RESPONSE_DELETE_EVENT); |
178 } | 177 } |
179 | 178 |
180 void JSModalDialogGtk::AcceptAppModalDialog() { | 179 void JSModalDialogGtk::AcceptAppModalDialog() { |
181 HandleDialogResponse(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); | 180 OnDialogResponse(gtk_dialog_, GTK_RESPONSE_OK); |
182 } | 181 } |
183 | 182 |
184 void JSModalDialogGtk::CancelAppModalDialog() { | 183 void JSModalDialogGtk::CancelAppModalDialog() { |
185 HandleDialogResponse(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_CANCEL); | 184 OnDialogResponse(gtk_dialog_, GTK_RESPONSE_CANCEL); |
186 } | 185 } |
187 | 186 |
188 //////////////////////////////////////////////////////////////////////////////// | 187 //////////////////////////////////////////////////////////////////////////////// |
189 // JSModalDialogGtk, private: | 188 // JSModalDialogGtk, private: |
190 | 189 |
191 void JSModalDialogGtk::HandleDialogResponse(GtkDialog* dialog, | 190 void JSModalDialogGtk::OnDialogResponse(GtkWidget* dialog, |
192 gint response_id) { | 191 int response_id) { |
193 switch (response_id) { | 192 switch (response_id) { |
194 case GTK_RESPONSE_OK: | 193 case GTK_RESPONSE_OK: |
195 // The first arg is the prompt text and the second is true if we want to | 194 // The first arg is the prompt text and the second is true if we want to |
196 // suppress additional popups from the page. | 195 // suppress additional popups from the page. |
197 dialog_->OnAccept(GetPromptText(dialog), ShouldSuppressJSDialogs(dialog)); | 196 dialog_->OnAccept(GetPromptText(GTK_DIALOG(dialog)), |
| 197 ShouldSuppressJSDialogs(GTK_DIALOG(dialog))); |
198 break; | 198 break; |
199 | 199 |
200 case GTK_RESPONSE_CANCEL: | 200 case GTK_RESPONSE_CANCEL: |
201 case GTK_RESPONSE_DELETE_EVENT: // User hit the X on the dialog. | 201 case GTK_RESPONSE_DELETE_EVENT: // User hit the X on the dialog. |
202 dialog_->OnCancel(ShouldSuppressJSDialogs(dialog)); | 202 dialog_->OnCancel(ShouldSuppressJSDialogs(GTK_DIALOG(dialog))); |
203 break; | 203 break; |
204 | 204 |
205 default: | 205 default: |
206 NOTREACHED(); | 206 NOTREACHED(); |
207 } | 207 } |
208 gtk_widget_destroy(GTK_WIDGET(dialog)); | 208 gtk_widget_destroy(GTK_WIDGET(dialog)); |
209 | 209 |
210 // Now that the dialog is gone, we can put all the windows into separate | 210 // Now that the dialog is gone, we can put all the windows into separate |
211 // window groups so other dialogs are no longer app modal. | 211 // window groups so other dialogs are no longer app modal. |
212 gtk_util::AppModalDismissedUngroupWindows(); | 212 gtk_util::AppModalDismissedUngroupWindows(); |
213 delete this; | 213 delete this; |
214 } | 214 } |
215 | 215 |
216 // static | |
217 void JSModalDialogGtk::OnDialogResponse(GtkDialog* gtk_dialog, | |
218 gint response_id, | |
219 JSModalDialogGtk* dialog) { | |
220 dialog->HandleDialogResponse(gtk_dialog, response_id); | |
221 } | |
222 | |
223 //////////////////////////////////////////////////////////////////////////////// | 216 //////////////////////////////////////////////////////////////////////////////// |
224 // NativeAppModalDialog, public: | 217 // NativeAppModalDialog, public: |
225 | 218 |
226 // static | 219 // static |
227 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 220 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
228 JavaScriptAppModalDialog* dialog, | 221 JavaScriptAppModalDialog* dialog, |
229 gfx::NativeWindow parent_window) { | 222 gfx::NativeWindow parent_window) { |
230 return new JSModalDialogGtk(dialog, parent_window); | 223 return new JSModalDialogGtk(dialog, parent_window); |
231 } | 224 } |
232 | |
233 | |
OLD | NEW |