| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/gtk/tab_modal_dialog_gtk.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 10 #include "chrome/browser/ui/tab_modal_dialog_delegate.h" |
| 11 #include "content/browser/tab_contents/navigation_controller.h" |
| 12 #include "content/browser/tab_contents/tab_contents.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/notification_types.h" |
| 15 #include "grit/generated_resources.h" |
| 16 #include "ui/base/gtk/gtk_hig_constants.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/gfx/image/image.h" |
| 19 |
| 20 namespace browser { |
| 21 |
| 22 // Declared in browser_dialogs.h so others don't have to depend on our header. |
| 23 void ShowTabModalDialog(TabModalDialogDelegate* delegate, |
| 24 gfx::NativeWindow parent_window, |
| 25 TabContents* tab_contents) { |
| 26 new TabModalDialogGtk(parent_window, delegate, tab_contents); |
| 27 } |
| 28 |
| 29 } |
| 30 |
| 31 TabModalDialogGtk::TabModalDialogGtk(GtkWindow* parent, |
| 32 TabModalDialogDelegate* delegate, |
| 33 TabContents* tab_contents) |
| 34 : delegate_(delegate) { |
| 35 dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaBorder); |
| 36 gtk_box_set_spacing(GTK_BOX(dialog_), ui::kContentAreaSpacing); |
| 37 GtkWidget* label = gtk_label_new( |
| 38 UTF16ToUTF8(delegate->GetMessage()).c_str()); |
| 39 gfx::Image* icon = delegate->GetIcon(); |
| 40 GtkWidget* image = icon ? gtk_image_new_from_pixbuf(icon->ToGdkPixbuf()) |
| 41 : gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, |
| 42 GTK_ICON_SIZE_DIALOG); |
| 43 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); |
| 44 |
| 45 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
| 46 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 47 |
| 48 GtkWidget *hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); |
| 49 |
| 50 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); |
| 51 |
| 52 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); |
| 53 |
| 54 gtk_box_pack_start(GTK_BOX(dialog_), hbox, FALSE, FALSE, 0); |
| 55 |
| 56 GtkWidget* buttonBox = gtk_hbutton_box_new(); |
| 57 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END); |
| 58 gtk_box_set_spacing(GTK_BOX(buttonBox), ui::kControlSpacing); |
| 59 gtk_box_pack_end(GTK_BOX(dialog_), buttonBox, FALSE, TRUE, 0); |
| 60 |
| 61 cancel_ = gtk_button_new_with_label( |
| 62 UTF16ToUTF8(delegate->GetCancelButtonTitle()).c_str()); |
| 63 const char* cancel_button_icon_id = delegate->GetCancelButtonIcon(); |
| 64 if (cancel_button_icon_id) { |
| 65 gtk_button_set_image(GTK_BUTTON(cancel_), gtk_image_new_from_stock( |
| 66 cancel_button_icon_id, GTK_ICON_SIZE_BUTTON)); |
| 67 } |
| 68 g_signal_connect(cancel_, "clicked", G_CALLBACK(OnCancelThunk), this); |
| 69 gtk_box_pack_end(GTK_BOX(buttonBox), cancel_, FALSE, TRUE, 0); |
| 70 |
| 71 ok_ = gtk_button_new_with_label( |
| 72 UTF16ToUTF8(delegate->GetAcceptButtonTitle()).c_str()); |
| 73 const char* accept_button_icon_id = delegate->GetAcceptButtonIcon(); |
| 74 if (accept_button_icon_id) { |
| 75 gtk_button_set_image(GTK_BUTTON(ok_), gtk_image_new_from_stock( |
| 76 accept_button_icon_id, GTK_ICON_SIZE_BUTTON)); |
| 77 } |
| 78 g_signal_connect(ok_, "clicked", G_CALLBACK(OnRefreshThunk), this); |
| 79 gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0); |
| 80 |
| 81 TabContentsWrapper* wrapper = |
| 82 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
| 83 delegate->set_window(new ConstrainedWindowGtk(wrapper, this)); |
| 84 } |
| 85 |
| 86 GtkWidget* TabModalDialogGtk::GetWidgetRoot() { |
| 87 return dialog_; |
| 88 } |
| 89 |
| 90 GtkWidget* TabModalDialogGtk::GetFocusWidget() { |
| 91 return cancel_; |
| 92 } |
| 93 |
| 94 void TabModalDialogGtk::DeleteDelegate() { |
| 95 delete this; |
| 96 } |
| 97 |
| 98 TabModalDialogGtk::~TabModalDialogGtk() { |
| 99 gtk_widget_destroy(dialog_); |
| 100 } |
| 101 |
| 102 void TabModalDialogGtk::OnRefresh(GtkWidget* widget) { |
| 103 delegate_->Accept(); |
| 104 } |
| 105 |
| 106 void TabModalDialogGtk::OnCancel(GtkWidget* widget) { |
| 107 delegate_->Cancel(); |
| 108 } |
| OLD | NEW |