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

Side by Side Diff: chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.cc

Issue 231733005: Delete the GTK+ port of Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remerge to ToT Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/gtk/tab_modal_confirm_dialog_gtk.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_dialogs.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/gtk/event_utils.h"
14 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
15 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
16 #include "components/web_modal/web_contents_modal_dialog_manager.h"
17 #include "content/public/browser/notification_types.h"
18 #include "grit/generated_resources.h"
19 #include "ui/base/gtk/gtk_hig_constants.h"
20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/gfx/image/image.h"
22
23 using web_modal::WebContentsModalDialogManager;
24
25 TabModalConfirmDialog* TabModalConfirmDialog::Create(
26 TabModalConfirmDialogDelegate* delegate,
27 content::WebContents* web_contents) {
28 return new TabModalConfirmDialogGtk(delegate, web_contents);
29 }
30
31 TabModalConfirmDialogGtk::TabModalConfirmDialogGtk(
32 TabModalConfirmDialogDelegate* delegate,
33 content::WebContents* web_contents)
34 : delegate_(delegate),
35 window_(NULL),
36 closing_(false) {
37 dialog_ = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
38 GtkWidget* label = gtk_label_new(
39 base::UTF16ToUTF8(delegate->GetDialogMessage()).c_str());
40 gfx::Image* icon = delegate->GetIcon();
41 GtkWidget* image = icon ? gtk_image_new_from_pixbuf(icon->ToGdkPixbuf())
42 : gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
43 GTK_ICON_SIZE_DIALOG);
44 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
45
46 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
47 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
48 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
49
50 GtkWidget* hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
51
52 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
53
54 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
55
56 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
57
58 base::string16 link_text = delegate->GetLinkText();
59 if (!link_text.empty()) {
60 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
61 GtkThemeService* theme_service = GtkThemeService::GetFrom(
62 browser->profile());
63
64 GtkWidget* link = theme_service->BuildChromeLinkButton(base::UTF16ToUTF8(
65 link_text.c_str()));
66 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this);
67 GtkWidget* link_align = gtk_alignment_new(0, 0, 0, 0);
68 gtk_container_add(GTK_CONTAINER(link_align), link);
69
70 gtk_box_pack_end(GTK_BOX(vbox), link_align, FALSE, FALSE, 0);
71 }
72
73 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
74 gtk_box_pack_start(GTK_BOX(dialog_), hbox, FALSE, FALSE, 0);
75
76 GtkWidget* buttonBox = gtk_hbutton_box_new();
77 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
78 gtk_box_set_spacing(GTK_BOX(buttonBox), ui::kControlSpacing);
79 gtk_box_pack_end(GTK_BOX(dialog_), buttonBox, FALSE, TRUE, 0);
80
81 cancel_ = gtk_button_new_with_label(
82 base::UTF16ToUTF8(delegate->GetCancelButtonTitle()).c_str());
83 const char* cancel_button_icon_id = delegate->GetCancelButtonIcon();
84 if (cancel_button_icon_id) {
85 gtk_button_set_image(GTK_BUTTON(cancel_), gtk_image_new_from_stock(
86 cancel_button_icon_id, GTK_ICON_SIZE_BUTTON));
87 }
88 g_signal_connect(cancel_, "clicked", G_CALLBACK(OnCancelThunk), this);
89 gtk_box_pack_end(GTK_BOX(buttonBox), cancel_, FALSE, TRUE, 0);
90
91 ok_ = gtk_button_new_with_label(
92 base::UTF16ToUTF8(delegate->GetAcceptButtonTitle()).c_str());
93 const char* accept_button_icon_id = delegate->GetAcceptButtonIcon();
94 if (accept_button_icon_id) {
95 gtk_button_set_image(GTK_BUTTON(ok_), gtk_image_new_from_stock(
96 accept_button_icon_id, GTK_ICON_SIZE_BUTTON));
97 }
98 g_signal_connect(ok_, "clicked", G_CALLBACK(OnAcceptThunk), this);
99 gtk_box_pack_end(GTK_BOX(buttonBox), ok_, FALSE, TRUE, 0);
100
101 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroyThunk), this);
102
103 window_ = CreateWebContentsModalDialogGtk(dialog_, cancel_);
104 delegate_->set_close_delegate(this);
105
106 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
107 WebContentsModalDialogManager::FromWebContents(web_contents);
108 web_contents_modal_dialog_manager->ShowDialog(window_);
109 }
110
111 TabModalConfirmDialogGtk::~TabModalConfirmDialogGtk() {
112 // Provide a disposition in case the dialog was closed without accepting or
113 // cancelling.
114 delegate_->Close();
115
116 gtk_widget_destroy(dialog_);
117 }
118
119 void TabModalConfirmDialogGtk::AcceptTabModalDialog() {
120 OnAccept(NULL);
121 }
122
123 void TabModalConfirmDialogGtk::CancelTabModalDialog() {
124 OnCancel(NULL);
125 }
126
127 void TabModalConfirmDialogGtk::CloseDialog() {
128 if (!closing_) {
129 closing_ = true;
130 gtk_widget_destroy(window_);
131 }
132 }
133
134 void TabModalConfirmDialogGtk::OnAccept(GtkWidget* widget) {
135 delegate_->Accept();
136 }
137
138 void TabModalConfirmDialogGtk::OnCancel(GtkWidget* widget) {
139 delegate_->Cancel();
140 }
141
142 void TabModalConfirmDialogGtk::OnLinkClicked(GtkWidget* widget) {
143 delegate_->LinkClicked(event_utils::DispositionForCurrentButtonPressEvent());
144 }
145
146 void TabModalConfirmDialogGtk::OnDestroy(GtkWidget* widget) {
147 delete this;
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698