Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Side by Side Diff: chrome/browser/ui/gtk/js_modal_dialog_gtk.cc

Issue 6257006: Move a bunch of random other files to src/ui/base... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/message_box_flags.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" 12 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
14 #include "chrome/browser/ui/gtk/gtk_util.h" 13 #include "chrome/browser/ui/gtk/gtk_util.h"
15 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
16 #include "grit/locale_settings.h" 15 #include "grit/locale_settings.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.
(...skipping 22 matching lines...) Expand all
49 49
50 JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog, 50 JSModalDialogGtk::JSModalDialogGtk(JavaScriptAppModalDialog* dialog,
51 gfx::NativeWindow parent_window) 51 gfx::NativeWindow parent_window)
52 : dialog_(dialog) { 52 : dialog_(dialog) {
53 GtkButtonsType buttons = GTK_BUTTONS_NONE; 53 GtkButtonsType buttons = GTK_BUTTONS_NONE;
54 GtkMessageType message_type = GTK_MESSAGE_OTHER; 54 GtkMessageType message_type = GTK_MESSAGE_OTHER;
55 55
56 // We add in the OK button manually later because we want to focus it 56 // We add in the OK button manually later because we want to focus it
57 // explicitly. 57 // explicitly.
58 switch (dialog_->dialog_flags()) { 58 switch (dialog_->dialog_flags()) {
59 case MessageBoxFlags::kIsJavascriptAlert: 59 case ui::MessageBoxFlags::kIsJavascriptAlert:
60 buttons = GTK_BUTTONS_NONE; 60 buttons = GTK_BUTTONS_NONE;
61 message_type = GTK_MESSAGE_WARNING; 61 message_type = GTK_MESSAGE_WARNING;
62 break; 62 break;
63 63
64 case MessageBoxFlags::kIsJavascriptConfirm: 64 case ui::MessageBoxFlags::kIsJavascriptConfirm:
65 if (dialog_->is_before_unload_dialog()) { 65 if (dialog_->is_before_unload_dialog()) {
66 // onbeforeunload also uses a confirm prompt, it just has custom 66 // onbeforeunload also uses a confirm prompt, it just has custom
67 // buttons. We add the buttons using gtk_dialog_add_button below. 67 // buttons. We add the buttons using gtk_dialog_add_button below.
68 buttons = GTK_BUTTONS_NONE; 68 buttons = GTK_BUTTONS_NONE;
69 } else { 69 } else {
70 buttons = GTK_BUTTONS_CANCEL; 70 buttons = GTK_BUTTONS_CANCEL;
71 } 71 }
72 message_type = GTK_MESSAGE_QUESTION; 72 message_type = GTK_MESSAGE_QUESTION;
73 break; 73 break;
74 74
75 case MessageBoxFlags::kIsJavascriptPrompt: 75 case ui::MessageBoxFlags::kIsJavascriptPrompt:
76 buttons = GTK_BUTTONS_CANCEL; 76 buttons = GTK_BUTTONS_CANCEL;
77 message_type = GTK_MESSAGE_QUESTION; 77 message_type = GTK_MESSAGE_QUESTION;
78 break; 78 break;
79 79
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 WideToUTF8(dialog_->message_text()).c_str());
91 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_); 91 gtk_util::ApplyMessageDialogQuirks(gtk_dialog_);
92 gtk_window_set_title(GTK_WINDOW(gtk_dialog_), 92 gtk_window_set_title(GTK_WINDOW(gtk_dialog_),
93 WideToUTF8(dialog_->title()).c_str()); 93 WideToUTF8(dialog_->title()).c_str());
94 94
95 // Adjust content area as needed. Set up the prompt text entry or 95 // Adjust content area as needed. Set up the prompt text entry or
96 // suppression check box. 96 // suppression check box.
97 if (MessageBoxFlags::kIsJavascriptPrompt == dialog_->dialog_flags()) { 97 if (ui::MessageBoxFlags::kIsJavascriptPrompt == dialog_->dialog_flags()) {
98 // TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+ 98 // TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+
99 GtkWidget* contents_vbox = GTK_DIALOG(gtk_dialog_)->vbox; 99 GtkWidget* contents_vbox = GTK_DIALOG(gtk_dialog_)->vbox;
100 GtkWidget* text_box = gtk_entry_new(); 100 GtkWidget* text_box = gtk_entry_new();
101 gtk_entry_set_text(GTK_ENTRY(text_box), 101 gtk_entry_set_text(GTK_ENTRY(text_box),
102 WideToUTF8(dialog_->default_prompt_text()).c_str()); 102 WideToUTF8(dialog_->default_prompt_text()).c_str());
103 gtk_box_pack_start(GTK_BOX(contents_vbox), text_box, TRUE, TRUE, 0); 103 gtk_box_pack_start(GTK_BOX(contents_vbox), text_box, TRUE, TRUE, 0);
104 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); 104 g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box);
105 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); 105 gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE);
106 } 106 }
107 107
(...skipping 14 matching lines...) Expand all
122 GTK_RESPONSE_OK); 122 GTK_RESPONSE_OK);
123 123
124 button_text = l10n_util::GetStringUTF8( 124 button_text = l10n_util::GetStringUTF8(
125 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); 125 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
126 gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), button_text.c_str(), 126 gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), button_text.c_str(),
127 GTK_RESPONSE_CANCEL); 127 GTK_RESPONSE_CANCEL);
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 (ui::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(OnDialogResponseThunk), this); 138 G_CALLBACK(OnDialogResponseThunk), this);
139 } 139 }
140 140
141 JSModalDialogGtk::~JSModalDialogGtk() { 141 JSModalDialogGtk::~JSModalDialogGtk() {
142 } 142 }
143 143
144 //////////////////////////////////////////////////////////////////////////////// 144 ////////////////////////////////////////////////////////////////////////////////
145 // JSModalDialogGtk, NativeAppModalDialog implementation: 145 // JSModalDialogGtk, NativeAppModalDialog implementation:
146 146
147 int JSModalDialogGtk::GetAppModalDialogButtons() const { 147 int JSModalDialogGtk::GetAppModalDialogButtons() const {
148 switch (dialog_->dialog_flags()) { 148 switch (dialog_->dialog_flags()) {
149 case MessageBoxFlags::kIsJavascriptAlert: 149 case ui::MessageBoxFlags::kIsJavascriptAlert:
150 return MessageBoxFlags::DIALOGBUTTON_OK; 150 return ui::MessageBoxFlags::DIALOGBUTTON_OK;
151 151
152 case MessageBoxFlags::kIsJavascriptConfirm: 152 case ui::MessageBoxFlags::kIsJavascriptConfirm:
153 return MessageBoxFlags::DIALOGBUTTON_OK | 153 return ui::MessageBoxFlags::DIALOGBUTTON_OK |
154 MessageBoxFlags::DIALOGBUTTON_CANCEL; 154 ui::MessageBoxFlags::DIALOGBUTTON_CANCEL;
155 155
156 case MessageBoxFlags::kIsJavascriptPrompt: 156 case ui::MessageBoxFlags::kIsJavascriptPrompt:
157 return MessageBoxFlags::DIALOGBUTTON_OK; 157 return ui::MessageBoxFlags::DIALOGBUTTON_OK;
158 158
159 default: 159 default:
160 NOTREACHED(); 160 NOTREACHED();
161 return 0; 161 return 0;
162 } 162 }
163 } 163 }
164 164
165 void JSModalDialogGtk::ShowAppModalDialog() { 165 void JSModalDialogGtk::ShowAppModalDialog() {
166 gtk_util::ShowModalDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_), 166 gtk_util::ShowModalDialogWithMinLocalizedWidth(GTK_WIDGET(gtk_dialog_),
167 IDS_ALERT_DIALOG_WIDTH_CHARS); 167 IDS_ALERT_DIALOG_WIDTH_CHARS);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 //////////////////////////////////////////////////////////////////////////////// 216 ////////////////////////////////////////////////////////////////////////////////
217 // NativeAppModalDialog, public: 217 // NativeAppModalDialog, public:
218 218
219 // static 219 // static
220 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( 220 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt(
221 JavaScriptAppModalDialog* dialog, 221 JavaScriptAppModalDialog* dialog,
222 gfx::NativeWindow parent_window) { 222 gfx::NativeWindow parent_window) {
223 return new JSModalDialogGtk(dialog, parent_window); 223 return new JSModalDialogGtk(dialog, parent_window);
224 } 224 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/js_modal_dialog_gtk.h ('k') | chrome/browser/ui/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698