| OLD | NEW |
| 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" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog, | 51 JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog, |
| 52 gfx::NativeWindow parent_window) | 52 gfx::NativeWindow parent_window) |
| 53 : dialog_(dialog) { | 53 : dialog_(dialog) { |
| 54 GtkButtonsType buttons = GTK_BUTTONS_NONE; | 54 GtkButtonsType buttons = GTK_BUTTONS_NONE; |
| 55 GtkMessageType message_type = GTK_MESSAGE_OTHER; | 55 GtkMessageType message_type = GTK_MESSAGE_OTHER; |
| 56 | 56 |
| 57 // We add in the OK button manually later because we want to focus it | 57 // We add in the OK button manually later because we want to focus it |
| 58 // explicitly. | 58 // explicitly. |
| 59 switch (dialog_->dialog_flags()) { | 59 switch (dialog_->dialog_flags()) { |
| 60 case ui::MessageBoxFlags::kIsJavascriptAlert: | 60 case ui::MESSAGE_BOX_IS_JAVASCRIPT_ALERT_DIALOG: |
| 61 buttons = GTK_BUTTONS_NONE; | 61 buttons = GTK_BUTTONS_NONE; |
| 62 message_type = GTK_MESSAGE_WARNING; | 62 message_type = GTK_MESSAGE_WARNING; |
| 63 break; | 63 break; |
| 64 | 64 |
| 65 case ui::MessageBoxFlags::kIsJavascriptConfirm: | 65 case ui::MESSAGE_BOX_IS_JAVASCRIPT_CONFIRM_DIALOG: |
| 66 if (dialog_->is_before_unload_dialog()) { | 66 if (dialog_->is_before_unload_dialog()) { |
| 67 // onbeforeunload also uses a confirm prompt, it just has custom | 67 // onbeforeunload also uses a confirm prompt, it just has custom |
| 68 // buttons. We add the buttons using gtk_dialog_add_button below. | 68 // buttons. We add the buttons using gtk_dialog_add_button below. |
| 69 buttons = GTK_BUTTONS_NONE; | 69 buttons = GTK_BUTTONS_NONE; |
| 70 } else { | 70 } else { |
| 71 buttons = GTK_BUTTONS_CANCEL; | 71 buttons = GTK_BUTTONS_CANCEL; |
| 72 } | 72 } |
| 73 message_type = GTK_MESSAGE_QUESTION; | 73 message_type = GTK_MESSAGE_QUESTION; |
| 74 break; | 74 break; |
| 75 | 75 |
| 76 case ui::MessageBoxFlags::kIsJavascriptPrompt: | 76 case ui::MESSAGE_BOX_IS_JAVASCRIPT_PROMPT_DIALOG: |
| 77 buttons = GTK_BUTTONS_CANCEL; | 77 buttons = GTK_BUTTONS_CANCEL; |
| 78 message_type = GTK_MESSAGE_QUESTION; | 78 message_type = GTK_MESSAGE_QUESTION; |
| 79 break; | 79 break; |
| 80 | 80 |
| 81 default: | 81 default: |
| 82 NOTREACHED(); | 82 NOTREACHED(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // We want the alert to be app modal so put all the browser windows into the | 85 // We want the alert to be app modal so put all the browser windows into the |
| 86 // same window group. | 86 // same window group. |
| 87 gtk_util::MakeAppModalWindowGroup(); | 87 gtk_util::MakeAppModalWindowGroup(); |
| 88 | 88 |
| 89 gtk_dialog_ = gtk_message_dialog_new(parent_window, | 89 gtk_dialog_ = gtk_message_dialog_new(parent_window, |
| 90 GTK_DIALOG_MODAL, message_type, buttons, "%s", | 90 GTK_DIALOG_MODAL, message_type, buttons, "%s", |
| 91 UTF16ToUTF8(dialog_->message_text()).c_str()); | 91 UTF16ToUTF8(dialog_->message_text()).c_str()); |
| 92 g_signal_connect(gtk_dialog_, "delete-event", | 92 g_signal_connect(gtk_dialog_, "delete-event", |
| 93 G_CALLBACK(gtk_widget_hide_on_delete), NULL); | 93 G_CALLBACK(gtk_widget_hide_on_delete), NULL); |
| 94 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_); | 94 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_); |
| 95 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), | 95 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), |
| 96 UTF16ToUTF8(dialog_->title()).c_str()); | 96 UTF16ToUTF8(dialog_->title()).c_str()); |
| 97 | 97 |
| 98 // Adjust content area as needed. Set up the prompt text entry or | 98 // Adjust content area as needed. Set up the prompt text entry or |
| 99 // suppression check box. | 99 // suppression check box. |
| 100 if (ui::MessageBoxFlags::kIsJavascriptPrompt == dialog_->dialog_flags()) { | 100 if (ui::MESSAGE_BOX_IS_JAVASCRIPT_PROMPT_DIALOG == dialog_->dialog_flags()) { |
| 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 Loading... |
| 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 (ui::MESSAGE_BOX_IS_JAVASCRIPT_PROMPT_DIALOG != dialog_->dialog_flags()) |
| 137 gtk_widget_grab_focus(ok_button); | 137 gtk_widget_grab_focus(ok_button); |
| 138 } | 138 } |
| 139 | 139 |
| 140 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); | 140 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); |
| 141 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 141 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
| 142 } | 142 } |
| 143 | 143 |
| 144 JSModalDialogGtk::~JSModalDialogGtk() { | 144 JSModalDialogGtk::~JSModalDialogGtk() { |
| 145 } | 145 } |
| 146 | 146 |
| 147 //////////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////////// |
| 148 // JSModalDialogGtk, NativeAppModalDialog implementation: | 148 // JSModalDialogGtk, NativeAppModalDialog implementation: |
| 149 | 149 |
| 150 int JSModalDialogGtk::GetAppModalDialogButtons() const { | 150 int JSModalDialogGtk::GetAppModalDialogButtons() const { |
| 151 switch (dialog_->dialog_flags()) { | 151 switch (dialog_->dialog_flags()) { |
| 152 case ui::MessageBoxFlags::kIsJavascriptAlert: | 152 case ui::MESSAGE_BOX_IS_JAVASCRIPT_ALERT_DIALOG: |
| 153 return ui::DIALOG_BUTTON_OK; | 153 return ui::DIALOG_BUTTON_OK; |
| 154 | 154 |
| 155 case ui::MessageBoxFlags::kIsJavascriptConfirm: | 155 case ui::MESSAGE_BOX_IS_JAVASCRIPT_CONFIRM_DIALOG: |
| 156 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | 156 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| 157 | 157 |
| 158 case ui::MessageBoxFlags::kIsJavascriptPrompt: | 158 case ui::MESSAGE_BOX_IS_JAVASCRIPT_PROMPT_DIALOG: |
| 159 return ui::DIALOG_BUTTON_OK; | 159 return ui::DIALOG_BUTTON_OK; |
| 160 | 160 |
| 161 default: | 161 default: |
| 162 NOTREACHED(); | 162 NOTREACHED(); |
| 163 return 0; | 163 return 0; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 void JSModalDialogGtk::ShowAppModalDialog() { | 167 void JSModalDialogGtk::ShowAppModalDialog() { |
| 168 gtk_util::ShowDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), | 168 gtk_util::ShowDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 //////////////////////////////////////////////////////////////////////////////// | 218 //////////////////////////////////////////////////////////////////////////////// |
| 219 // NativeAppModalDialog, public: | 219 // NativeAppModalDialog, public: |
| 220 | 220 |
| 221 // static | 221 // static |
| 222 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 222 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
| 223 JavaScriptAppModalDialog* dialog, | 223 JavaScriptAppModalDialog* dialog, |
| 224 gfx::NativeWindow parent_window) { | 224 gfx::NativeWindow parent_window) { |
| 225 return new JSModalDialogGtk(dialog, parent_window); | 225 return new JSModalDialogGtk(dialog, parent_window); |
| 226 } | 226 } |
| OLD | NEW |