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

Side by Side Diff: chrome/browser/app_modal_dialog_gtk.cc

Issue 100124: Implement a couple more methods for dialog boxes. (Closed)
Patch Set: comments Created 11 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/app_modal_dialog.h" 5 #include "chrome/browser/app_modal_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/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/browser/tab_contents/web_contents.h" 11 #include "chrome/browser/tab_contents/web_contents.h"
12 #include "chrome/browser/tab_contents/tab_contents_view.h" 12 #include "chrome/browser/tab_contents/tab_contents_view.h"
13 #include "chrome/common/l10n_util.h" 13 #include "chrome/common/l10n_util.h"
14 #include "chrome/common/message_box_flags.h" 14 #include "chrome/common/message_box_flags.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 16
17 namespace { 17 namespace {
18 18
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
19 void OnDialogResponse(GtkDialog* dialog, gint response_id, 33 void OnDialogResponse(GtkDialog* dialog, gint response_id,
20 AppModalDialog* app_modal_dialog) { 34 AppModalDialog* app_modal_dialog) {
21 switch (response_id) { 35 switch (response_id) {
22 case GTK_RESPONSE_OK: 36 case GTK_RESPONSE_OK:
23 // The first arg is the prompt text and the second is true if we want to 37 // The first arg is the prompt text and the second is true if we want to
24 // suppress additional popups from the page. 38 // suppress additional popups from the page.
25 app_modal_dialog->OnAccept(std::wstring(), false); 39 app_modal_dialog->OnAccept(GetPromptText(dialog), false);
26 break; 40 break;
27 41
28 case GTK_RESPONSE_CANCEL: 42 case GTK_RESPONSE_CANCEL:
29 case GTK_RESPONSE_DELETE_EVENT: // User hit the X on the dialog. 43 case GTK_RESPONSE_DELETE_EVENT: // User hit the X on the dialog.
30 app_modal_dialog->OnCancel(); 44 app_modal_dialog->OnCancel();
31 break; 45 break;
32 46
33 default: 47 default:
34 NOTREACHED(); 48 NOTREACHED();
35 } 49 }
(...skipping 20 matching lines...) Expand all
56 // onbeforeunload also uses a confirm prompt, it just has custom 70 // onbeforeunload also uses a confirm prompt, it just has custom
57 // buttons. We add the buttons using gtk_dialog_add_button below. 71 // buttons. We add the buttons using gtk_dialog_add_button below.
58 buttons = GTK_BUTTONS_NONE; 72 buttons = GTK_BUTTONS_NONE;
59 } else { 73 } else {
60 buttons = GTK_BUTTONS_OK_CANCEL; 74 buttons = GTK_BUTTONS_OK_CANCEL;
61 } 75 }
62 message_type = GTK_MESSAGE_QUESTION; 76 message_type = GTK_MESSAGE_QUESTION;
63 break; 77 break;
64 78
65 case MessageBoxFlags::kIsJavascriptPrompt: 79 case MessageBoxFlags::kIsJavascriptPrompt:
66 // We need to make a custom message box for javascript prompts. For now 80 buttons = GTK_BUTTONS_OK_CANCEL;
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;
73 message_type = GTK_MESSAGE_QUESTION; 81 message_type = GTK_MESSAGE_QUESTION;
74 break; 82 break;
75 83
76 default: 84 default:
77 NOTREACHED(); 85 NOTREACHED();
78 } 86 }
79 87
80 GtkWindow* window = web_contents_->view()->GetTopLevelNativeWindow(); 88 GtkWindow* window = web_contents_->view()->GetTopLevelNativeWindow();
81 dialog_ = gtk_message_dialog_new(window, GTK_DIALOG_MODAL, 89 dialog_ = gtk_message_dialog_new(window, GTK_DIALOG_MODAL,
82 message_type, buttons, "%s", WideToUTF8(message_text_).c_str()); 90 message_type, buttons, "%s", WideToUTF8(message_text_).c_str());
83 gtk_window_set_title(GTK_WINDOW(dialog_), WideToUTF8(title_).c_str()); 91 gtk_window_set_title(GTK_WINDOW(dialog_), WideToUTF8(title_).c_str());
84 92
85 if (is_before_unload_dialog_) { 93 if (is_before_unload_dialog_) {
86 std::string button_text = l10n_util::GetStringUTF8( 94 std::string button_text = l10n_util::GetStringUTF8(
87 IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL); 95 IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL);
88 gtk_dialog_add_button(GTK_DIALOG(dialog_), button_text.c_str(), 96 gtk_dialog_add_button(GTK_DIALOG(dialog_), button_text.c_str(),
89 GTK_RESPONSE_OK); 97 GTK_RESPONSE_OK);
90 98
91 button_text = l10n_util::GetStringUTF8( 99 button_text = l10n_util::GetStringUTF8(
92 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL); 100 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
93 gtk_dialog_add_button(GTK_DIALOG(dialog_), button_text.c_str(), 101 gtk_dialog_add_button(GTK_DIALOG(dialog_), button_text.c_str(),
94 GTK_RESPONSE_CANCEL); 102 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);
95 } 111 }
96 112
97 g_signal_connect(dialog_, "response", G_CALLBACK(OnDialogResponse), this); 113 g_signal_connect(dialog_, "response", G_CALLBACK(OnDialogResponse), this);
98 gtk_widget_show(GTK_WIDGET(GTK_DIALOG(dialog_))); 114 gtk_widget_show(GTK_WIDGET(GTK_DIALOG(dialog_)));
99 } 115 }
100 116
101 void AppModalDialog::ActivateModalDialog() { 117 void AppModalDialog::ActivateModalDialog() {
102 NOTIMPLEMENTED(); 118 gtk_window_present(GTK_WINDOW(dialog_));
103 } 119 }
104 120
105 void AppModalDialog::CloseModalDialog() { 121 void AppModalDialog::CloseModalDialog() {
106 NOTIMPLEMENTED(); 122 OnDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_DELETE_EVENT, this);
107 } 123 }
108 124
109 int AppModalDialog::GetDialogButtons() { 125 int AppModalDialog::GetDialogButtons() {
110 switch (dialog_flags_) { 126 switch (dialog_flags_) {
111 case MessageBoxFlags::kIsJavascriptAlert: 127 case MessageBoxFlags::kIsJavascriptAlert:
112 return MessageBoxFlags::DIALOGBUTTON_OK; 128 return MessageBoxFlags::DIALOGBUTTON_OK;
113 129
114 case MessageBoxFlags::kIsJavascriptConfirm: 130 case MessageBoxFlags::kIsJavascriptConfirm:
115 return MessageBoxFlags::DIALOGBUTTON_OK | 131 return MessageBoxFlags::DIALOGBUTTON_OK |
116 MessageBoxFlags::DIALOGBUTTON_CANCEL; 132 MessageBoxFlags::DIALOGBUTTON_CANCEL;
117 133
118 case MessageBoxFlags::kIsJavascriptPrompt: 134 case MessageBoxFlags::kIsJavascriptPrompt:
119 return MessageBoxFlags::DIALOGBUTTON_OK; 135 return MessageBoxFlags::DIALOGBUTTON_OK;
120 136
121 default: 137 default:
122 NOTREACHED(); 138 NOTREACHED();
123 return 0; 139 return 0;
124 } 140 }
125 } 141 }
126 142
127 void AppModalDialog::AcceptWindow() { 143 void AppModalDialog::AcceptWindow() {
128 OnDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_OK, this); 144 OnDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_OK, this);
129 } 145 }
130 146
131 void AppModalDialog::CancelWindow() { 147 void AppModalDialog::CancelWindow() {
132 OnDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_CANCEL, this); 148 OnDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_CANCEL, this);
133 } 149 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698