1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
// 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/about_chrome_dialog.h"
#include <gtk/gtk.h>
#include <string>
#include <vector>
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/gtk/cairo_cached_surface.h"
#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/ui/gtk/gtk_theme_provider.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/url_constants.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
#include "webkit/glue/webkit_glue.h"
namespace {
// Left or right margin.
const int kPanelHorizMargin = 13;
// Top or bottom margin.
const int kPanelVertMargin = 20;
// Extra spacing between product name and version number.
const int kExtraLineSpacing = 5;
// These are used as placeholder text around the links in the text in the about
// dialog.
const char* kBeginLinkChr = "BEGIN_LINK_CHR";
const char* kBeginLinkOss = "BEGIN_LINK_OSS";
// We don't actually use this one.
// const char* kEndLinkChr = "END_LINK_CHR";
const char* kEndLinkOss = "END_LINK_OSS";
const char* kBeginLink = "BEGIN_LINK";
const char* kEndLink = "END_LINK";
void OnDialogResponse(GtkDialog* dialog, int response_id) {
// We're done.
gtk_widget_destroy(GTK_WIDGET(dialog));
}
void FixLabelWrappingCallback(GtkWidget *label,
GtkAllocation *allocation,
gpointer data) {
gtk_widget_set_size_request(label, allocation->width, -1);
}
GtkWidget* MakeMarkupLabel(const char* format, const std::string& str) {
GtkWidget* label = gtk_label_new(NULL);
char* markup = g_markup_printf_escaped(format, str.c_str());
gtk_label_set_markup(GTK_LABEL(label), markup);
g_free(markup);
// Left align it.
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
return label;
}
void OnLinkButtonClick(GtkWidget* button, const char* url) {
BrowserList::GetLastActive()->
OpenURL(GURL(url), GURL(), NEW_WINDOW, PageTransition::LINK);
}
const char* GetChromiumUrl() {
static GURL url = google_util::AppendGoogleLocaleParam(
GURL(chrome::kChromiumProjectURL));
return url.spec().c_str();
}
gboolean OnEventBoxExpose(GtkWidget* event_box,
GdkEventExpose* expose,
gboolean user_data) {
cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(event_box->window));
gdk_cairo_rectangle(cr, &expose->area);
cairo_clip(cr);
GtkThemeProvider* theme_provider =
GtkThemeProvider::GetFrom(BrowserList::GetLastActive()->profile());
CairoCachedSurface* background = theme_provider->GetSurfaceNamed(
IDR_ABOUT_BACKGROUND_COLOR, event_box);
background->SetSource(cr, 0, 0);
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
gdk_cairo_rectangle(cr, &expose->area);
cairo_fill(cr);
cairo_destroy(cr);
return FALSE;
}
} // namespace
void ShowAboutDialogForProfile(GtkWindow* parent, Profile* profile) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
static GdkPixbuf* background = rb.GetPixbufNamed(IDR_ABOUT_BACKGROUND);
chrome::VersionInfo version_info;
std::string current_version = version_info.Version();
#if !defined(GOOGLE_CHROME_BUILD)
current_version += " (";
current_version += version_info.LastChange();
current_version += ")";
#endif
std::string channel = platform_util::GetVersionStringModifier();
if (!channel.empty())
current_version += " " + channel;
// Build the dialog.
GtkWidget* dialog = gtk_dialog_new_with_buttons(
l10n_util::GetStringUTF8(IDS_ABOUT_CHROME_TITLE).c_str(),
parent,
GTK_DIALOG_MODAL,
NULL);
// Pick up the style set in gtk_util.cc:InitRCStyles().
// The layout of this dialog is special because the logo should be flush
// with the edges of the window.
gtk_widget_set_name(dialog, "about-dialog");
gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
GtkWidget* close_button = gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
GtkWidget* content_area = GTK_DIALOG(dialog)->vbox;
// Use an event box to get the background painting correctly
GtkWidget* ebox = gtk_event_box_new();
gtk_widget_set_app_paintable(ebox, TRUE);
g_signal_connect(ebox, "expose-event", G_CALLBACK(OnEventBoxExpose), NULL);
GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
GtkWidget* text_alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
gtk_alignment_set_padding(GTK_ALIGNMENT(text_alignment),
kPanelVertMargin, kPanelVertMargin,
kPanelHorizMargin, kPanelHorizMargin);
GtkWidget* text_vbox = gtk_vbox_new(FALSE, kExtraLineSpacing);
GdkColor black = gtk_util::kGdkBlack;
GtkWidget* product_label = MakeMarkupLabel(
"<span font_desc=\"18\" style=\"normal\">%s</span>",
l10n_util::GetStringUTF8(IDS_PRODUCT_NAME));
gtk_widget_modify_fg(product_label, GTK_STATE_NORMAL, &black);
gtk_box_pack_start(GTK_BOX(text_vbox), product_label, FALSE, FALSE, 0);
GtkWidget* version_label = gtk_label_new(current_version.c_str());
gtk_misc_set_alignment(GTK_MISC(version_label), 0.0, 0.5);
gtk_label_set_selectable(GTK_LABEL(version_label), TRUE);
gtk_widget_modify_fg(version_label, GTK_STATE_NORMAL, &black);
gtk_box_pack_start(GTK_BOX(text_vbox), version_label, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(text_alignment), text_vbox);
gtk_box_pack_start(GTK_BOX(hbox), text_alignment, TRUE, TRUE, 0);
GtkWidget* image_vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_end(GTK_BOX(image_vbox),
gtk_image_new_from_pixbuf(background),
FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), image_vbox, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(ebox), hbox);
gtk_box_pack_start(GTK_BOX(content_area), ebox, TRUE, TRUE, 0);
// We use a separate box for the licensing etc. text. See the comment near
// the top of this function about using a special layout for this dialog.
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
GtkWidget* copyright_label = gtk_label_new(
l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_COPYRIGHT).c_str());
gtk_misc_set_alignment(GTK_MISC(copyright_label), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(vbox), copyright_label, FALSE, FALSE, 5);
std::string license = l10n_util::GetStringUTF8(IDS_ABOUT_VERSION_LICENSE);
bool chromium_url_appears_first =
license.find(kBeginLinkChr) < license.find(kBeginLinkOss);
size_t link1 = license.find(kBeginLink);
DCHECK(link1 != std::string::npos);
size_t link1_end = license.find(kEndLink, link1);
DCHECK(link1_end != std::string::npos);
size_t link2 = license.find(kBeginLink, link1_end);
DCHECK(link2 != std::string::npos);
size_t link2_end = license.find(kEndLink, link2);
DCHECK(link1_end != std::string::npos);
GtkWidget* license_chunk1 = gtk_label_new(license.substr(0, link1).c_str());
gtk_misc_set_alignment(GTK_MISC(license_chunk1), 0.0, 0.5);
GtkWidget* license_chunk2 = gtk_label_new(
license.substr(link1_end + strlen(kEndLinkOss),
link2 - link1_end - strlen(kEndLinkOss)).c_str());
gtk_misc_set_alignment(GTK_MISC(license_chunk2), 0.0, 0.5);
GtkWidget* license_chunk3 = gtk_label_new(
license.substr(link2_end + strlen(kEndLinkOss)).c_str());
gtk_misc_set_alignment(GTK_MISC(license_chunk3), 0.0, 0.5);
std::string first_link_text =
license.substr(link1 + strlen(kBeginLinkOss),
link1_end - link1 - strlen(kBeginLinkOss));
std::string second_link_text =
license.substr(link2 + strlen(kBeginLinkOss),
link2_end - link2 - strlen(kBeginLinkOss));
GtkWidget* first_link = gtk_chrome_link_button_new(first_link_text.c_str());
GtkWidget* second_link = gtk_chrome_link_button_new(second_link_text.c_str());
if (!chromium_url_appears_first) {
GtkWidget* swap = second_link;
second_link = first_link;
first_link = swap;
}
g_signal_connect(chromium_url_appears_first ? first_link : second_link,
"clicked", G_CALLBACK(OnLinkButtonClick),
const_cast<char*>(GetChromiumUrl()));
g_signal_connect(chromium_url_appears_first ? second_link : first_link,
"clicked", G_CALLBACK(OnLinkButtonClick),
const_cast<char*>(chrome::kAboutCreditsURL));
GtkWidget* license_hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(license_hbox), license_chunk1,
FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(license_hbox), first_link,
FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(license_hbox), license_chunk2,
FALSE, FALSE, 0);
// Since there's no good way to dynamically wrap the license block, force
// a line break right before the second link (which matches en-US Windows
// chromium).
GtkWidget* license_hbox2 = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(license_hbox2), second_link,
FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(license_hbox2), license_chunk3,
FALSE, FALSE, 0);
GtkWidget* license_vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(license_vbox), license_hbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(license_vbox), license_hbox2, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), license_vbox, FALSE, FALSE, 0);
#if defined(GOOGLE_CHROME_BUILD)
// Spacing line.
gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new(""), FALSE, FALSE, 0);
std::vector<size_t> url_offsets;
string16 text = l10n_util::GetStringFUTF16(IDS_ABOUT_TERMS_OF_SERVICE,
string16(),
string16(),
&url_offsets);
GtkWidget* tos_chunk1 = gtk_label_new(
UTF16ToUTF8(text.substr(0, url_offsets[0])).c_str());
gtk_misc_set_alignment(GTK_MISC(tos_chunk1), 0.0, 0.5);
GtkWidget* tos_link = gtk_chrome_link_button_new(
l10n_util::GetStringUTF8(IDS_TERMS_OF_SERVICE).c_str());
GtkWidget* tos_chunk2 = gtk_label_new(
UTF16ToUTF8(text.substr(url_offsets[0])).c_str());
gtk_misc_set_alignment(GTK_MISC(tos_chunk2), 0.0, 0.5);
GtkWidget* tos_hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(tos_hbox), tos_chunk1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(tos_hbox), tos_link, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(tos_hbox), tos_chunk2, FALSE, FALSE, 0);
g_signal_connect(tos_link, "clicked", G_CALLBACK(OnLinkButtonClick),
const_cast<char*>(chrome::kAboutTermsURL));
gtk_box_pack_start(GTK_BOX(vbox), tos_hbox, TRUE, TRUE, 0);
#endif
GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
gtk_util::kContentAreaBorder, 0,
gtk_util::kContentAreaBorder, gtk_util::kContentAreaBorder);
gtk_container_add(GTK_CONTAINER(alignment), vbox);
gtk_box_pack_start(GTK_BOX(content_area), alignment, FALSE, FALSE, 0);
g_signal_connect(dialog, "response", G_CALLBACK(OnDialogResponse), NULL);
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
gtk_widget_show_all(dialog);
gtk_widget_grab_focus(close_button);
}
|