| OLD | NEW |
| 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/platform_util.h" | 5 #include "chrome/browser/simple_message_box.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 11 #include "base/process_util.h" | |
| 12 #include "base/string_util.h" | |
| 13 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/ui/gtk/gtk_util.h" | 9 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 15 #include "content/common/process_watcher.h" | |
| 16 #include "googleurl/src/gurl.h" | |
| 17 #include "ui/gfx/native_widget_types.h" | |
| 18 | 10 |
| 19 namespace { | 11 namespace { |
| 20 | 12 |
| 21 void SetDialogTitle(GtkWidget* dialog, const string16& title) { | 13 void SetDialogTitle(GtkWidget* dialog, const string16& title) { |
| 22 gtk_window_set_title(GTK_WINDOW(dialog), UTF16ToUTF8(title).c_str()); | 14 gtk_window_set_title(GTK_WINDOW(dialog), UTF16ToUTF8(title).c_str()); |
| 23 | 15 |
| 24 #if !defined(OS_CHROMEOS) | 16 #if !defined(OS_CHROMEOS) |
| 25 // The following code requires the dialog to be realized. However, we host | 17 // The following code requires the dialog to be realized. However, we host |
| 26 // dialog's content in a Chrome window without really realize the dialog | 18 // dialog's content in a Chrome window without really realize the dialog |
| 27 // on ChromeOS. Thus, skip the following code for ChromeOS. | 19 // on ChromeOS. Thus, skip the following code for ChromeOS. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 // actual title text. | 30 // actual title text. |
| 39 width = width * 1.2 + 50; | 31 width = width * 1.2 + 50; |
| 40 | 32 |
| 41 if (width > req.width) | 33 if (width > req.width) |
| 42 gtk_widget_set_size_request(dialog, width, -1); | 34 gtk_widget_set_size_request(dialog, width, -1); |
| 43 #endif // !defined(OS_CHROMEOS) | 35 #endif // !defined(OS_CHROMEOS) |
| 44 } | 36 } |
| 45 | 37 |
| 46 int g_dialog_response; | 38 int g_dialog_response; |
| 47 | 39 |
| 48 void HandleOnResponseDialog(GtkWidget* widget, | 40 void HandleOnResponseDialog(GtkWidget* widget, int response, void* user_data) { |
| 49 int response, | |
| 50 void* user_data) { | |
| 51 g_dialog_response = response; | 41 g_dialog_response = response; |
| 52 gtk_widget_destroy(widget); | 42 gtk_widget_destroy(widget); |
| 53 MessageLoop::current()->QuitNow(); | 43 MessageLoop::current()->QuitNow(); |
| 54 } | 44 } |
| 55 | 45 |
| 56 } // namespace | 46 } // namespace |
| 57 | 47 |
| 58 namespace platform_util { | 48 namespace browser { |
| 59 | 49 |
| 60 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { | 50 void ShowErrorBox(gfx::NativeWindow parent, |
| 61 // A detached widget won't have a toplevel window as an ancestor, so we can't | 51 const string16& title, |
| 62 // assume that the query for toplevel will return a window. | 52 const string16& message) { |
| 63 GtkWidget* toplevel = gtk_widget_get_ancestor(view, GTK_TYPE_WINDOW); | 53 GtkWidget* dialog = gtk_message_dialog_new(parent, |
| 64 return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL; | 54 GTK_DIALOG_MODAL, |
| 65 } | 55 GTK_MESSAGE_ERROR, |
| 66 | 56 GTK_BUTTONS_OK, |
| 67 gfx::NativeView GetParent(gfx::NativeView view) { | 57 "%s", |
| 68 return gtk_widget_get_parent(view); | 58 UTF16ToUTF8(message).c_str()); |
| 69 } | |
| 70 | |
| 71 bool IsWindowActive(gfx::NativeWindow window) { | |
| 72 return gtk_window_is_active(window); | |
| 73 } | |
| 74 | |
| 75 void ActivateWindow(gfx::NativeWindow window) { | |
| 76 gtk_window_present(window); | |
| 77 } | |
| 78 | |
| 79 bool IsVisible(gfx::NativeView view) { | |
| 80 return gtk_widget_get_visible(view); | |
| 81 } | |
| 82 | |
| 83 void SimpleErrorBox(gfx::NativeWindow parent, | |
| 84 const string16& title, | |
| 85 const string16& message) { | |
| 86 GtkWidget* dialog = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL, | |
| 87 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", UTF16ToUTF8(message).c_str()); | |
| 88 gtk_util::ApplyMessageDialogQuirks(dialog); | 59 gtk_util::ApplyMessageDialogQuirks(dialog); |
| 89 SetDialogTitle(dialog, title); | 60 SetDialogTitle(dialog, title); |
| 90 | 61 |
| 91 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); | 62 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); |
| 92 g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL); | 63 g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL); |
| 93 gtk_util::ShowDialog(dialog); | 64 gtk_util::ShowDialog(dialog); |
| 94 } | 65 } |
| 95 | 66 |
| 96 bool SimpleYesNoBox(gfx::NativeWindow parent, | 67 bool ShowYesNoBox(gfx::NativeWindow parent, |
| 97 const string16& title, | 68 const string16& title, |
| 98 const string16& message) { | 69 const string16& message) { |
| 99 GtkWidget* dialog = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL, | 70 GtkWidget* dialog = gtk_message_dialog_new(parent, |
| 100 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", | 71 GTK_DIALOG_MODAL, |
| 101 UTF16ToUTF8(message).c_str()); | 72 GTK_MESSAGE_QUESTION, |
| 73 GTK_BUTTONS_YES_NO, |
| 74 "%s", |
| 75 UTF16ToUTF8(message).c_str()); |
| 102 gtk_util::ApplyMessageDialogQuirks(dialog); | 76 gtk_util::ApplyMessageDialogQuirks(dialog); |
| 103 SetDialogTitle(dialog, title); | 77 SetDialogTitle(dialog, title); |
| 104 | 78 |
| 105 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES); | 79 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES); |
| 106 g_signal_connect(dialog, | 80 g_signal_connect(dialog, |
| 107 "response", | 81 "response", |
| 108 G_CALLBACK(HandleOnResponseDialog), | 82 G_CALLBACK(HandleOnResponseDialog), |
| 109 NULL); | 83 NULL); |
| 110 gtk_util::ShowDialog(dialog); | 84 gtk_util::ShowDialog(dialog); |
| 111 // Not gtk_dialog_run as it prevents timers from running in the unit tests. | 85 // Not gtk_dialog_run as it prevents timers from running in the unit tests. |
| 112 MessageLoop::current()->Run(); | 86 MessageLoop::current()->Run(); |
| 113 return g_dialog_response == GTK_RESPONSE_YES; | 87 return g_dialog_response == GTK_RESPONSE_YES; |
| 114 } | 88 } |
| 115 | 89 |
| 116 } // namespace platform_util | 90 } // namespace browser |
| OLD | NEW |