| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tab_modal_confirm_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/browser_dialogs.h" | 9 #include "chrome/browser/ui/browser_dialogs.h" |
| 10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 11 #include "content/public/browser/notification_types.h" | 11 #include "content/public/browser/notification_types.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "ui/base/gtk/gtk_hig_constants.h" | 13 #include "ui/base/gtk/gtk_hig_constants.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 | 16 |
| 17 TabModalConfirmDialog* TabModalConfirmDialog::Create( | 17 TabModalConfirmDialog* TabModalConfirmDialog::Create( |
| 18 TabModalConfirmDialogDelegate* delegate, | 18 TabModalConfirmDialogDelegate* delegate, |
| 19 content::WebContents* web_contents) { | 19 content::WebContents* web_contents) { |
| 20 return new TabModalConfirmDialogGtk(delegate, web_contents); | 20 return new TabModalConfirmDialogGtk(delegate, web_contents); |
| 21 } | 21 } |
| 22 | 22 |
| 23 TabModalConfirmDialogGtk::TabModalConfirmDialogGtk( | 23 TabModalConfirmDialogGtk::TabModalConfirmDialogGtk( |
| 24 TabModalConfirmDialogDelegate* delegate, | 24 TabModalConfirmDialogDelegate* delegate, |
| 25 content::WebContents* web_contents) | 25 content::WebContents* web_contents) |
| 26 : delegate_(delegate) { | 26 : delegate_(delegate), |
| 27 window_(NULL) { |
| 27 dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); | 28 dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); |
| 28 GtkWidget* label = gtk_label_new( | 29 GtkWidget* label = gtk_label_new( |
| 29 UTF16ToUTF8(delegate->GetMessage()).c_str()); | 30 UTF16ToUTF8(delegate->GetMessage()).c_str()); |
| 30 gfx::Image* icon = delegate->GetIcon(); | 31 gfx::Image* icon = delegate->GetIcon(); |
| 31 GtkWidget* image = icon ? gtk_image_new_from_pixbuf(icon->ToGdkPixbuf()) | 32 GtkWidget* image = icon ? gtk_image_new_from_pixbuf(icon->ToGdkPixbuf()) |
| 32 : gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, | 33 : gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, |
| 33 GTK_ICON_SIZE_DIALOG); | 34 GTK_ICON_SIZE_DIALOG); |
| 34 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); | 35 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); |
| 35 | 36 |
| 36 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 37 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 62 ok_ = gtk_button_new_with_label( | 63 ok_ = gtk_button_new_with_label( |
| 63 UTF16ToUTF8(delegate->GetAcceptButtonTitle()).c_str()); | 64 UTF16ToUTF8(delegate->GetAcceptButtonTitle()).c_str()); |
| 64 const char* accept_button_icon_id = delegate->GetAcceptButtonIcon(); | 65 const char* accept_button_icon_id = delegate->GetAcceptButtonIcon(); |
| 65 if (accept_button_icon_id) { | 66 if (accept_button_icon_id) { |
| 66 gtk_button_set_image(GTK_BUTTON(ok_), gtk_image_new_from_stock( | 67 gtk_button_set_image(GTK_BUTTON(ok_), gtk_image_new_from_stock( |
| 67 accept_button_icon_id, GTK_ICON_SIZE_BUTTON)); | 68 accept_button_icon_id, GTK_ICON_SIZE_BUTTON)); |
| 68 } | 69 } |
| 69 g_signal_connect(ok_, "clicked", G_CALLBACK(OnAcceptThunk), this); | 70 g_signal_connect(ok_, "clicked", G_CALLBACK(OnAcceptThunk), this); |
| 70 gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0); | 71 gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0); |
| 71 | 72 |
| 72 delegate->set_window(new ConstrainedWindowGtk(web_contents, this)); | 73 window_ = new ConstrainedWindowGtk(web_contents, this); |
| 74 delegate_->set_close_delegate(this); |
| 73 } | 75 } |
| 74 | 76 |
| 75 GtkWidget* TabModalConfirmDialogGtk::GetWidgetRoot() { | 77 GtkWidget* TabModalConfirmDialogGtk::GetWidgetRoot() { |
| 76 return dialog_; | 78 return dialog_; |
| 77 } | 79 } |
| 78 | 80 |
| 79 GtkWidget* TabModalConfirmDialogGtk::GetFocusWidget() { | 81 GtkWidget* TabModalConfirmDialogGtk::GetFocusWidget() { |
| 80 return cancel_; | 82 return cancel_; |
| 81 } | 83 } |
| 82 | 84 |
| 83 void TabModalConfirmDialogGtk::DeleteDelegate() { | 85 void TabModalConfirmDialogGtk::DeleteDelegate() { |
| 84 delete this; | 86 delete this; |
| 85 } | 87 } |
| 86 | 88 |
| 87 TabModalConfirmDialogGtk::~TabModalConfirmDialogGtk() { | 89 TabModalConfirmDialogGtk::~TabModalConfirmDialogGtk() { |
| 88 gtk_widget_destroy(dialog_); | 90 gtk_widget_destroy(dialog_); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void TabModalConfirmDialogGtk::AcceptTabModalDialog() { | 93 void TabModalConfirmDialogGtk::AcceptTabModalDialog() { |
| 92 OnAccept(NULL); | 94 OnAccept(NULL); |
| 93 } | 95 } |
| 94 | 96 |
| 95 void TabModalConfirmDialogGtk::CancelTabModalDialog() { | 97 void TabModalConfirmDialogGtk::CancelTabModalDialog() { |
| 96 OnCancel(NULL); | 98 OnCancel(NULL); |
| 97 } | 99 } |
| 98 | 100 |
| 101 void TabModalConfirmDialogGtk::CloseDialog() { |
| 102 window_->CloseWebContentsModalDialog(); |
| 103 } |
| 104 |
| 99 void TabModalConfirmDialogGtk::OnAccept(GtkWidget* widget) { | 105 void TabModalConfirmDialogGtk::OnAccept(GtkWidget* widget) { |
| 100 delegate_->Accept(); | 106 delegate_->Accept(); |
| 101 } | 107 } |
| 102 | 108 |
| 103 void TabModalConfirmDialogGtk::OnCancel(GtkWidget* widget) { | 109 void TabModalConfirmDialogGtk::OnCancel(GtkWidget* widget) { |
| 104 delegate_->Cancel(); | 110 delegate_->Cancel(); |
| 105 } | 111 } |
| OLD | NEW |