| Index: chrome/browser/ui/gtk/tab_modal_dialog_gtk.cc
|
| diff --git a/chrome/browser/ui/gtk/tab_modal_dialog_gtk.cc b/chrome/browser/ui/gtk/tab_modal_dialog_gtk.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d5a70eb3a8d8265b7342c9b7b7c18c475cd40471
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/gtk/tab_modal_dialog_gtk.cc
|
| @@ -0,0 +1,108 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/gtk/tab_modal_dialog_gtk.h"
|
| +
|
| +#include "base/message_loop.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
|
| +#include "chrome/browser/ui/tab_modal_dialog_delegate.h"
|
| +#include "content/browser/tab_contents/navigation_controller.h"
|
| +#include "content/browser/tab_contents/tab_contents.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/notification_types.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "ui/base/gtk/gtk_hig_constants.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/gfx/image/image.h"
|
| +
|
| +namespace browser {
|
| +
|
| +// Declared in browser_dialogs.h so others don't have to depend on our header.
|
| +void ShowTabModalDialog(TabModalDialogDelegate* delegate,
|
| + gfx::NativeWindow parent_window,
|
| + TabContents* tab_contents) {
|
| + new TabModalDialogGtk(parent_window, delegate, tab_contents);
|
| +}
|
| +
|
| +}
|
| +
|
| +TabModalDialogGtk::TabModalDialogGtk(GtkWindow* parent,
|
| + TabModalDialogDelegate* delegate,
|
| + TabContents* tab_contents)
|
| + : delegate_(delegate) {
|
| + dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaBorder);
|
| + gtk_box_set_spacing(GTK_BOX(dialog_), ui::kContentAreaSpacing);
|
| + GtkWidget* label = gtk_label_new(
|
| + UTF16ToUTF8(delegate->GetMessage()).c_str());
|
| + gfx::Image* icon = delegate->GetIcon();
|
| + GtkWidget* image = icon ? gtk_image_new_from_pixbuf(icon->ToGdkPixbuf())
|
| + : gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
|
| + GTK_ICON_SIZE_DIALOG);
|
| + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
|
| +
|
| + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
|
| + gtk_label_set_selectable(GTK_LABEL(label), TRUE);
|
| +
|
| + GtkWidget *hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
|
| +
|
| + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
|
| +
|
| + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
|
| +
|
| + gtk_box_pack_start(GTK_BOX(dialog_), hbox, FALSE, FALSE, 0);
|
| +
|
| + GtkWidget* buttonBox = gtk_hbutton_box_new();
|
| + gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
|
| + gtk_box_set_spacing(GTK_BOX(buttonBox), ui::kControlSpacing);
|
| + gtk_box_pack_end(GTK_BOX(dialog_), buttonBox, FALSE, TRUE, 0);
|
| +
|
| + cancel_ = gtk_button_new_with_label(
|
| + UTF16ToUTF8(delegate->GetCancelButtonTitle()).c_str());
|
| + const char* cancel_button_icon_id = delegate->GetCancelButtonIcon();
|
| + if (cancel_button_icon_id) {
|
| + gtk_button_set_image(GTK_BUTTON(cancel_), gtk_image_new_from_stock(
|
| + cancel_button_icon_id, GTK_ICON_SIZE_BUTTON));
|
| + }
|
| + g_signal_connect(cancel_, "clicked", G_CALLBACK(OnCancelThunk), this);
|
| + gtk_box_pack_end(GTK_BOX(buttonBox), cancel_, FALSE, TRUE, 0);
|
| +
|
| + ok_ = gtk_button_new_with_label(
|
| + UTF16ToUTF8(delegate->GetAcceptButtonTitle()).c_str());
|
| + const char* accept_button_icon_id = delegate->GetAcceptButtonIcon();
|
| + if (accept_button_icon_id) {
|
| + gtk_button_set_image(GTK_BUTTON(ok_), gtk_image_new_from_stock(
|
| + accept_button_icon_id, GTK_ICON_SIZE_BUTTON));
|
| + }
|
| + g_signal_connect(ok_, "clicked", G_CALLBACK(OnRefreshThunk), this);
|
| + gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0);
|
| +
|
| + TabContentsWrapper* wrapper =
|
| + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
|
| + delegate->set_window(new ConstrainedWindowGtk(wrapper, this));
|
| +}
|
| +
|
| +GtkWidget* TabModalDialogGtk::GetWidgetRoot() {
|
| + return dialog_;
|
| +}
|
| +
|
| +GtkWidget* TabModalDialogGtk::GetFocusWidget() {
|
| + return cancel_;
|
| +}
|
| +
|
| +void TabModalDialogGtk::DeleteDelegate() {
|
| + delete this;
|
| +}
|
| +
|
| +TabModalDialogGtk::~TabModalDialogGtk() {
|
| + gtk_widget_destroy(dialog_);
|
| +}
|
| +
|
| +void TabModalDialogGtk::OnRefresh(GtkWidget* widget) {
|
| + delegate_->Accept();
|
| +}
|
| +
|
| +void TabModalDialogGtk::OnCancel(GtkWidget* widget) {
|
| + delegate_->Cancel();
|
| +}
|
|
|