| 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" |
| 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" | 16 #include "ui/base/message_box_flags.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // 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 |
| 21 // after dialog creation. | 21 // after dialog creation. |
| 22 const char kPromptTextId[] = "chrome_prompt_text"; | 22 const char kPromptTextId[] = "chrome_prompt_text"; |
| 23 const char kSuppressCheckboxId[] = "chrome_suppress_checkbox"; | 23 const char kSuppressCheckboxId[] = "chrome_suppress_checkbox"; |
| 24 | 24 |
| 25 // 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 |
| 26 // return it. | 26 // return it. |
| 27 std::wstring GetPromptText(GtkDialog* dialog) { | 27 string16 GetPromptText(GtkDialog* dialog) { |
| 28 GtkWidget* widget = static_cast<GtkWidget*>( | 28 GtkWidget* widget = static_cast<GtkWidget*>( |
| 29 g_object_get_data(G_OBJECT(dialog), kPromptTextId)); | 29 g_object_get_data(G_OBJECT(dialog), kPromptTextId)); |
| 30 if (widget) | 30 if (widget) |
| 31 return UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(widget))); | 31 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(widget))); |
| 32 return std::wstring(); | 32 return string16(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // If there's a toggle button in the dialog, return the toggled state. | 35 // If there's a toggle button in the dialog, return the toggled state. |
| 36 // Otherwise, return false. | 36 // Otherwise, return false. |
| 37 bool ShouldSuppressJSDialogs(GtkDialog* dialog) { | 37 bool ShouldSuppressJSDialogs(GtkDialog* dialog) { |
| 38 GtkWidget* widget = static_cast<GtkWidget*>( | 38 GtkWidget* widget = static_cast<GtkWidget*>( |
| 39 g_object_get_data(G_OBJECT(dialog), kSuppressCheckboxId)); | 39 g_object_get_data(G_OBJECT(dialog), kSuppressCheckboxId)); |
| 40 if (widget) | 40 if (widget) |
| 41 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | 41 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
| 42 return false; | 42 return false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 default: | 80 default: |
| 81 NOTREACHED(); | 81 NOTREACHED(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // 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 |
| 85 // same window group. | 85 // same window group. |
| 86 gtk_util::MakeAppModalWindowGroup(); | 86 gtk_util::MakeAppModalWindowGroup(); |
| 87 | 87 |
| 88 gtk_dialog_ = gtk_message_dialog_new(parent_window, | 88 gtk_dialog_ = gtk_message_dialog_new(parent_window, |
| 89 GTK_DIALOG_MODAL, message_type, buttons, "%s", | 89 GTK_DIALOG_MODAL, message_type, buttons, "%s", |
| 90 WideToUTF8(dialog_->message_text()).c_str()); | 90 UTF16ToUTF8(dialog_->message_text()).c_str()); |
| 91 g_signal_connect(gtk_dialog_, "delete-event", | 91 g_signal_connect(gtk_dialog_, "delete-event", |
| 92 G_CALLBACK(gtk_widget_hide_on_delete), NULL); | 92 G_CALLBACK(gtk_widget_hide_on_delete), NULL); |
| 93 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_); | 93 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_); |
| 94 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), | 94 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), |
| 95 WideToUTF8(dialog_->title()).c_str()); | 95 UTF16ToUTF8(dialog_->title()).c_str()); |
| 96 | 96 |
| 97 // 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 |
| 98 // suppression check box. | 98 // suppression check box. |
| 99 if (ui::MessageBoxFlags::kIsJavascriptPrompt == dialog_->dialog_flags()) { | 99 if (ui::MessageBoxFlags::kIsJavascriptPrompt == dialog_->dialog_flags()) { |
| 100 // TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+ | 100 // TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+ |
| 101 GtkWidget* contents_vbox = GTK_DIALOG(gtk_dialog_)->vbox; | 101 GtkWidget* contents_vbox = GTK_DIALOG(gtk_dialog_)->vbox; |
| 102 GtkWidget* text_box = gtk_entry_new(); | 102 GtkWidget* text_box = gtk_entry_new(); |
| 103 gtk_entry_set_text(GTK_ENTRY(text_box), | 103 gtk_entry_set_text(GTK_ENTRY(text_box), |
| 104 WideToUTF8(dialog_->default_prompt_text()).c_str()); | 104 UTF16ToUTF8(dialog_->default_prompt_text()).c_str()); |
| 105 gtk_box_pack_start(GTK_BOX(contents_vbox), text_box, TRUE, TRUE, 0); | 105 gtk_box_pack_start(GTK_BOX(contents_vbox), text_box, TRUE, TRUE, 0); |
| 106 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); | 106 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); |
| 107 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); | 107 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); |
| 108 } | 108 } |
| 109 | 109 |
| 110 if (dialog_->display_suppress_checkbox()) { | 110 if (dialog_->display_suppress_checkbox()) { |
| 111 GtkWidget* contents_vbox = GTK_DIALOG(gtk_dialog_)->vbox; | 111 GtkWidget* contents_vbox = GTK_DIALOG(gtk_dialog_)->vbox; |
| 112 GtkWidget* check_box = gtk_check_button_new_with_label( | 112 GtkWidget* check_box = gtk_check_button_new_with_label( |
| 113 l10n_util::GetStringUTF8( | 113 l10n_util::GetStringUTF8( |
| 114 IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION).c_str()); | 114 IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION).c_str()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 //////////////////////////////////////////////////////////////////////////////// | 217 //////////////////////////////////////////////////////////////////////////////// |
| 218 // NativeAppModalDialog, public: | 218 // NativeAppModalDialog, public: |
| 219 | 219 |
| 220 // static | 220 // static |
| 221 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 221 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
| 222 JavaScriptAppModalDialog* dialog, | 222 JavaScriptAppModalDialog* dialog, |
| 223 gfx::NativeWindow parent_window) { | 223 gfx::NativeWindow parent_window) { |
| 224 return new JSModalDialogGtk(dialog, parent_window); | 224 return new JSModalDialogGtk(dialog, parent_window); |
| 225 } | 225 } |
| OLD | NEW |