Skip to content

Commit d35aea2

Browse files
author
tc@google.com
committed
Implement a couple more methods for dialog boxes including the prompt box.
BUG=9623 Review URL: http://codereview.chromium.org/100124 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14791 0039d316-1c4b-4281-b951-d872f2087c98
1 parent 07fb778 commit d35aea2

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

chrome/browser/app_modal_dialog_gtk.cc

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@
1616

1717
namespace {
1818

19+
// If there's a text entry in the dialog, get the text from the first one and
20+
// return it.
21+
std::wstring GetPromptText(GtkDialog* dialog) {
22+
// TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+
23+
GtkWidget* contents_vbox = dialog->vbox;
24+
GList* first_child = gtk_container_get_children(GTK_CONTAINER(contents_vbox));
25+
for (GList* item = first_child; item; g_list_next(item)) {
26+
if (GTK_IS_ENTRY(item->data)) {
27+
return UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(item->data)));
28+
}
29+
}
30+
return std::wstring();
31+
}
32+
1933
void OnDialogResponse(GtkDialog* dialog, gint response_id,
2034
AppModalDialog* app_modal_dialog) {
2135
switch (response_id) {
2236
case GTK_RESPONSE_OK:
2337
// The first arg is the prompt text and the second is true if we want to
2438
// suppress additional popups from the page.
25-
app_modal_dialog->OnAccept(std::wstring(), false);
39+
app_modal_dialog->OnAccept(GetPromptText(dialog), false);
2640
break;
2741

2842
case GTK_RESPONSE_CANCEL:
@@ -63,13 +77,7 @@ void AppModalDialog::CreateAndShowDialog() {
6377
break;
6478

6579
case MessageBoxFlags::kIsJavascriptPrompt:
66-
// We need to make a custom message box for javascript prompts. For now
67-
// just have an OK button and send back an empty string. Maybe we can
68-
// cram a GtkEntry into the content area of the message box via
69-
// gtk_dialog_get_content_area.
70-
// http://crbug.com/9623
71-
NOTIMPLEMENTED();
72-
buttons = GTK_BUTTONS_OK;
80+
buttons = GTK_BUTTONS_OK_CANCEL;
7381
message_type = GTK_MESSAGE_QUESTION;
7482
break;
7583

@@ -92,18 +100,26 @@ void AppModalDialog::CreateAndShowDialog() {
92100
IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
93101
gtk_dialog_add_button(GTK_DIALOG(dialog_), button_text.c_str(),
94102
GTK_RESPONSE_CANCEL);
103+
} else if (MessageBoxFlags::kIsJavascriptPrompt == dialog_flags_) {
104+
// TODO(tc): Replace with gtk_dialog_get_content_area() when using GTK 2.14+
105+
GtkWidget* contents_vbox = GTK_DIALOG(dialog_)->vbox;
106+
GtkWidget* text_box = gtk_entry_new();
107+
gtk_entry_set_text(GTK_ENTRY(text_box),
108+
WideToUTF8(default_prompt_text_).c_str());
109+
gtk_widget_show(text_box);
110+
gtk_box_pack_start(GTK_BOX(contents_vbox), text_box, TRUE, TRUE, 0);
95111
}
96112

97113
g_signal_connect(dialog_, "response", G_CALLBACK(OnDialogResponse), this);
98114
gtk_widget_show(GTK_WIDGET(GTK_DIALOG(dialog_)));
99115
}
100116

101117
void AppModalDialog::ActivateModalDialog() {
102-
NOTIMPLEMENTED();
118+
gtk_window_present(GTK_WINDOW(dialog_));
103119
}
104120

105121
void AppModalDialog::CloseModalDialog() {
106-
NOTIMPLEMENTED();
122+
OnDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_DELETE_EVENT, this);
107123
}
108124

109125
int AppModalDialog::GetDialogButtons() {

0 commit comments

Comments
 (0)