OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell_javascript_dialog.h" | 5 #include "content/shell/browser/shell_javascript_dialog.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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "content/shell/app/resource.h" | 12 #include "content/shell/app/resource.h" |
13 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
14 #include "content/shell/browser/shell_javascript_dialog_manager.h" | 14 #include "content/shell/browser/shell_javascript_dialog_manager.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 const char kPromptTextId[] = "content_shell_prompt_text"; | 18 const char kPromptTextId[] = "content_shell_prompt_text"; |
19 | 19 |
20 // If there's a text entry in the dialog, get the text from the first one and | 20 // If there's a text entry in the dialog, get the text from the first one and |
21 // return it. | 21 // return it. |
22 base::string16 GetPromptText(GtkDialog* dialog) { | 22 base::string16 GetPromptText(GtkDialog* dialog) { |
23 GtkWidget* widget = static_cast<GtkWidget*>( | 23 GtkWidget* widget = static_cast<GtkWidget*>( |
24 g_object_get_data(G_OBJECT(dialog), kPromptTextId)); | 24 g_object_get_data(G_OBJECT(dialog), kPromptTextId)); |
25 if (widget) | 25 if (widget) |
26 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(widget))); | 26 return base::UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(widget))); |
27 return base::string16(); | 27 return base::string16(); |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 | 32 |
33 namespace content { | 33 namespace content { |
34 | 34 |
35 ShellJavaScriptDialog::ShellJavaScriptDialog( | 35 ShellJavaScriptDialog::ShellJavaScriptDialog( |
36 ShellJavaScriptDialogManager* manager, | 36 ShellJavaScriptDialogManager* manager, |
(...skipping 26 matching lines...) Expand all Loading... |
63 | 63 |
64 default: | 64 default: |
65 NOTREACHED(); | 65 NOTREACHED(); |
66 } | 66 } |
67 | 67 |
68 gtk_dialog_ = gtk_message_dialog_new(parent_window_, | 68 gtk_dialog_ = gtk_message_dialog_new(parent_window_, |
69 GTK_DIALOG_MODAL, | 69 GTK_DIALOG_MODAL, |
70 gtk_message_type, | 70 gtk_message_type, |
71 buttons, | 71 buttons, |
72 "%s", | 72 "%s", |
73 UTF16ToUTF8(message_text).c_str()); | 73 base::UTF16ToUTF8(message_text).c_str()); |
74 g_signal_connect(gtk_dialog_, | 74 g_signal_connect(gtk_dialog_, |
75 "delete-event", | 75 "delete-event", |
76 G_CALLBACK(gtk_widget_hide_on_delete), | 76 G_CALLBACK(gtk_widget_hide_on_delete), |
77 NULL); | 77 NULL); |
78 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), "JavaScript"); | 78 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), "JavaScript"); |
79 | 79 |
80 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), | 80 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), |
81 GTK_STOCK_OK, | 81 GTK_STOCK_OK, |
82 GTK_RESPONSE_OK); | 82 GTK_RESPONSE_OK); |
83 | 83 |
84 if (message_type != content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) | 84 if (message_type != content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) |
85 gtk_widget_grab_focus(ok_button); | 85 gtk_widget_grab_focus(ok_button); |
86 | 86 |
87 if (message_type == content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { | 87 if (message_type == content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { |
88 GtkWidget* content_area = | 88 GtkWidget* content_area = |
89 gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_)); | 89 gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_)); |
90 GtkWidget* text_box = gtk_entry_new(); | 90 GtkWidget* text_box = gtk_entry_new(); |
91 gtk_entry_set_text(GTK_ENTRY(text_box), | 91 gtk_entry_set_text(GTK_ENTRY(text_box), |
92 UTF16ToUTF8(default_prompt_text).c_str()); | 92 base::UTF16ToUTF8(default_prompt_text).c_str()); |
93 gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0); | 93 gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0); |
94 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); | 94 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); |
95 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); | 95 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); |
96 } | 96 } |
97 | 97 |
98 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); | 98 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); |
99 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 99 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
100 gtk_widget_show_all(GTK_WIDGET(gtk_dialog_)); | 100 gtk_widget_show_all(GTK_WIDGET(gtk_dialog_)); |
101 } | 101 } |
102 | 102 |
(...skipping 15 matching lines...) Expand all Loading... |
118 default: | 118 default: |
119 NOTREACHED(); | 119 NOTREACHED(); |
120 } | 120 } |
121 | 121 |
122 gtk_widget_destroy(dialog); | 122 gtk_widget_destroy(dialog); |
123 | 123 |
124 manager_->DialogClosed(this); | 124 manager_->DialogClosed(this); |
125 } | 125 } |
126 | 126 |
127 } // namespace content | 127 } // namespace content |
OLD | NEW |