OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/javascript_app_modal_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/javascript_app_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 JavaScriptAppModalDialogGtk::JavaScriptAppModalDialogGtk( | 50 JavaScriptAppModalDialogGtk::JavaScriptAppModalDialogGtk( |
51 JavaScriptAppModalDialog* dialog, | 51 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_->javascript_message_type()) { | 59 switch (dialog_->javascript_message_type()) { |
60 case ui::JAVASCRIPT_MESSAGE_TYPE_ALERT: | 60 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: |
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::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: | 65 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: |
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::JAVASCRIPT_MESSAGE_TYPE_PROMPT: | 76 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: |
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 (dialog_->javascript_message_type() == | 100 if (dialog_->javascript_message_type() == |
101 ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { | 101 content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) { |
102 GtkWidget* content_area = | 102 GtkWidget* content_area = |
103 gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_)); | 103 gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_)); |
104 GtkWidget* text_box = gtk_entry_new(); | 104 GtkWidget* text_box = gtk_entry_new(); |
105 gtk_entry_set_text(GTK_ENTRY(text_box), | 105 gtk_entry_set_text(GTK_ENTRY(text_box), |
106 UTF16ToUTF8(dialog_->default_prompt_text()).c_str()); | 106 UTF16ToUTF8(dialog_->default_prompt_text()).c_str()); |
107 gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0); | 107 gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0); |
108 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); | 108 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); |
109 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); | 109 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); |
110 } | 110 } |
111 | 111 |
(...skipping 20 matching lines...) Expand all Loading... |
132 dialog_->is_reload() ? | 132 dialog_->is_reload() ? |
133 IDS_BEFORERELOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL : | 133 IDS_BEFORERELOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL : |
134 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); | 134 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); |
135 gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), button_text.c_str(), | 135 gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), button_text.c_str(), |
136 GTK_RESPONSE_CANCEL); | 136 GTK_RESPONSE_CANCEL); |
137 } else { | 137 } else { |
138 // Add the OK button and focus it. | 138 // Add the OK button and focus it. |
139 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), | 139 GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), |
140 GTK_STOCK_OK, GTK_RESPONSE_OK); | 140 GTK_STOCK_OK, GTK_RESPONSE_OK); |
141 if (dialog_->javascript_message_type() != | 141 if (dialog_->javascript_message_type() != |
142 ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) | 142 content::JAVASCRIPT_MESSAGE_TYPE_PROMPT) |
143 gtk_widget_grab_focus(ok_button); | 143 gtk_widget_grab_focus(ok_button); |
144 } | 144 } |
145 | 145 |
146 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); | 146 gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); |
147 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 147 g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
148 } | 148 } |
149 | 149 |
150 JavaScriptAppModalDialogGtk::~JavaScriptAppModalDialogGtk() { | 150 JavaScriptAppModalDialogGtk::~JavaScriptAppModalDialogGtk() { |
151 } | 151 } |
152 | 152 |
153 //////////////////////////////////////////////////////////////////////////////// | 153 //////////////////////////////////////////////////////////////////////////////// |
154 // JavaScriptAppModalDialogGtk, NativeAppModalDialog implementation: | 154 // JavaScriptAppModalDialogGtk, NativeAppModalDialog implementation: |
155 | 155 |
156 int JavaScriptAppModalDialogGtk::GetAppModalDialogButtons() const { | 156 int JavaScriptAppModalDialogGtk::GetAppModalDialogButtons() const { |
157 switch (dialog_->javascript_message_type()) { | 157 switch (dialog_->javascript_message_type()) { |
158 case ui::JAVASCRIPT_MESSAGE_TYPE_ALERT: | 158 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: |
159 return ui::DIALOG_BUTTON_OK; | 159 return ui::DIALOG_BUTTON_OK; |
160 | 160 |
161 case ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: | 161 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: |
162 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | 162 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
163 | 163 |
164 case ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT: | 164 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: |
165 return ui::DIALOG_BUTTON_OK; | 165 return ui::DIALOG_BUTTON_OK; |
166 | 166 |
167 default: | 167 default: |
168 NOTREACHED(); | 168 NOTREACHED(); |
169 return 0; | 169 return 0; |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 void JavaScriptAppModalDialogGtk::ShowAppModalDialog() { | 173 void JavaScriptAppModalDialogGtk::ShowAppModalDialog() { |
174 gtk_util::ShowDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), | 174 gtk_util::ShowDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 //////////////////////////////////////////////////////////////////////////////// | 225 //////////////////////////////////////////////////////////////////////////////// |
226 // NativeAppModalDialog, public: | 226 // NativeAppModalDialog, public: |
227 | 227 |
228 // static | 228 // static |
229 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 229 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
230 JavaScriptAppModalDialog* dialog, | 230 JavaScriptAppModalDialog* dialog, |
231 gfx::NativeWindow parent_window) { | 231 gfx::NativeWindow parent_window) { |
232 return new JavaScriptAppModalDialogGtk(dialog, parent_window); | 232 return new JavaScriptAppModalDialogGtk(dialog, parent_window); |
233 } | 233 } |
OLD | NEW |