diff options
-rw-r--r-- | chrome/browser/browser.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser.h | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/about_chrome_dialog.cc | 157 | ||||
-rw-r--r-- | chrome/browser/gtk/about_chrome_dialog.h | 14 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 3 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
6 files changed, 178 insertions, 4 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 36e3be6..2c7a637 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1135,12 +1135,12 @@ void Browser::OpenKeywordEditor() { void Browser::OpenPasswordManager() { window_->ShowPasswordManager(); } +#endif void Browser::OpenAboutChromeDialog() { UserMetrics::RecordAction(L"AboutChrome", profile_); window_->ShowAboutChromeDialog(); } -#endif void Browser::OpenHelpTab() { GURL help_url(WideToASCII(l10n_util::GetString(IDS_HELP_CONTENT_URL))); @@ -1354,8 +1354,8 @@ void Browser::ExecuteCommandWithDisposition( case IDC_OPTIONS: OpenOptionsDialog(); break; case IDC_EDIT_SEARCH_ENGINES: OpenKeywordEditor(); break; case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; - case IDC_ABOUT: OpenAboutChromeDialog(); break; #endif + case IDC_ABOUT: OpenAboutChromeDialog(); break; case IDC_HELP_PAGE: OpenHelpTab(); break; default: diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 9566d1f..bfb1050 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -373,8 +373,8 @@ class Browser : public TabStripModelDelegate, void OpenOptionsDialog(); void OpenKeywordEditor(); void OpenPasswordManager(); - void OpenAboutChromeDialog(); #endif + void OpenAboutChromeDialog(); void OpenHelpTab(); ///////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/gtk/about_chrome_dialog.cc b/chrome/browser/gtk/about_chrome_dialog.cc new file mode 100644 index 0000000..8ec471ce --- /dev/null +++ b/chrome/browser/gtk/about_chrome_dialog.cc @@ -0,0 +1,157 @@ +// Copyright (c) 2009 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/gtk/about_chrome_dialog.h" + +#include <gtk/gtk.h> +#include <wchar.h> + +#include "base/file_version_info.h" +#include "base/gfx/gtk_util.h" +#include "chrome/common/l10n_util.h" +#include "chrome/common/resource_bundle.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/browser/profile.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 { +// The pixel width of the version text field. Ideally, we'd like to have the +// bounds set to the edge of the icon. However, the icon is not a view but a +// part of the background, so we have to hard code the width to make sure +// the version field doesn't overlap it. +const int kVersionFieldWidth = 195; + +// The URLs that you navigate to when clicking the links in the About dialog. +const wchar_t* const kChromiumUrl = L"http://www.chromium.org/"; +const wchar_t* const kAcknowledgements = L"about:credits"; +const wchar_t* const kTOS = L"about:terms"; + +// Left or right margin. +const int kPanelHorizMargin = 13; + +// Top or bottom margin. +const int kPanelVertMargin = 13; + +// These are used as placeholder text around the links in the text in the about +// dialog. +const wchar_t* kBeginLinkChr = L"BEGIN_LINK_CHR"; +const wchar_t* kBeginLinkOss = L"BEGIN_LINK_OSS"; +const wchar_t* kEndLinkChr = L"END_LINK_CHR"; +const wchar_t* kEndLinkOss = L"END_LINK_OSS"; +const wchar_t* kBeginLink = L"BEGIN_LINK"; +const wchar_t* kEndLink = L"END_LINK"; + +void RemoveText(std::wstring* text, const wchar_t* to_remove) { + size_t start = text->find(to_remove, 0); + if (start != std::string::npos) { + size_t length = wcslen(to_remove); + *text = text->substr(0, start) + text->substr(start + length); + } +} + +void OnDialogResponse(GtkDialog* dialog, int response_id) { + // We're done. + gtk_widget_destroy(GTK_WIDGET(dialog)); +} + +GtkWidget* MakeMarkupLabel(const char* format, const std::wstring& str) { + GtkWidget* label = gtk_label_new(NULL); + char* markup = g_markup_printf_escaped( + format, WideToUTF8(str).c_str()); + gtk_label_set_markup(GTK_LABEL(label), markup); + g_free(markup); + + return label; +} + +} // namespace + +void ShowAboutDialogForProfile(GtkWindow* parent, Profile* profile) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + static GdkPixbuf* background = rb.GetPixbufNamed(IDR_ABOUT_BACKGROUND); + scoped_ptr<FileVersionInfo> version_info( + FileVersionInfo::CreateFileVersionInfoForCurrentModule()); + std::wstring current_version = version_info->file_version(); +#if !defined(GOOGLE_CHROME_BUILD) + current_version += L" ("; + current_version += version_info->last_change(); + current_version += L")"; +#endif + + // Build the dialog. + GtkWidget* dialog = gtk_dialog_new_with_buttons( + l10n_util::GetStringUTF8(IDS_ABOUT_CHROME_TITLE).c_str(), + parent, + GTK_DIALOG_MODAL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + + 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_modify_bg(ebox, GTK_STATE_NORMAL, &gfx::kGdkWhite); + + 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, 0); + + GtkWidget* product_label = MakeMarkupLabel( + "<span font_desc=\"18\" weight=\"bold\" style=\"normal\">%s</span>", + l10n_util::GetString(IDS_PRODUCT_NAME)); + gtk_box_pack_start(GTK_BOX(text_vbox), product_label, FALSE, FALSE, 0); + + GtkWidget* version_label = MakeMarkupLabel( + "<span style=\"italic\">%s</span>", + current_version); + gtk_label_set_selectable(GTK_LABEL(version_label), TRUE); + 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, FALSE, 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); + + GtkWidget* copyright_label = MakeMarkupLabel( + "<span size=\"smaller\">%s</span>", + l10n_util::GetString(IDS_ABOUT_VERSION_COPYRIGHT)); + gtk_box_pack_start(GTK_BOX(content_area), copyright_label, TRUE, TRUE, 5); + + // TODO(erg): Figure out how to really insert links. We could just depend on + // (or include the source of) libsexy's SexyUrlLabel gtk widget... + std::wstring license = l10n_util::GetString(IDS_ABOUT_VERSION_LICENSE); + RemoveText(&license, kBeginLinkChr); + RemoveText(&license, kBeginLinkOss); + RemoveText(&license, kBeginLink); + RemoveText(&license, kEndLinkChr); + RemoveText(&license, kEndLinkOss); + RemoveText(&license, kEndLink); + + GtkWidget* license_label = MakeMarkupLabel( + "<span size=\"smaller\">%s</span>", license); + + gtk_label_set_line_wrap(GTK_LABEL(license_label), TRUE); + gtk_misc_set_alignment(GTK_MISC(license_label), 0, 0); + gtk_box_pack_start(GTK_BOX(content_area), license_label, TRUE, TRUE, 0); + + g_signal_connect(dialog, "response", G_CALLBACK(OnDialogResponse), NULL); + gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); + gtk_widget_show_all(dialog); +} diff --git a/chrome/browser/gtk/about_chrome_dialog.h b/chrome/browser/gtk/about_chrome_dialog.h new file mode 100644 index 0000000..5f1f8d3 --- /dev/null +++ b/chrome/browser/gtk/about_chrome_dialog.h @@ -0,0 +1,14 @@ +// Copyright (c) 2009 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. + +#ifndef CHROME_BROWSER_GTK_ABOUT_CHROME_DIALOG_H_ +#define CHROME_BROWSER_GTK_ABOUT_CHROME_DIALOG_H_ + +class Profile; +typedef struct _GtkWindow GtkWindow; + +// Displays the about box, using data copied from |profile|. +void ShowAboutDialogForProfile(GtkWindow* parent, Profile* profile); + +#endif // CHROME_BROWSER_GTK_ABOUT_CHROME_DIALOG_H_ diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 4e0618c..43d7c95 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -18,6 +18,7 @@ #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/gtk/about_chrome_dialog.h" #include "chrome/browser/gtk/bookmark_bar_gtk.h" #include "chrome/browser/gtk/browser_toolbar_gtk.h" #include "chrome/browser/gtk/go_button_gtk.h" @@ -466,7 +467,7 @@ void BrowserWindowGtk::ToggleBookmarkBar() { } void BrowserWindowGtk::ShowAboutChromeDialog() { - NOTIMPLEMENTED(); + ShowAboutDialogForProfile(window_, browser_->profile()); } void BrowserWindowGtk::ShowBookmarkManager() { diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index eebd53c..8ccab4d 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -712,6 +712,8 @@ 'browser/google_url_tracker.h', 'browser/google_util.cc', 'browser/google_util.h', + 'browser/gtk/about_chrome_dialog.cc', + 'browser/gtk/about_chrome_dialog.h', 'browser/gtk/back_forward_menu_model_gtk.cc', 'browser/gtk/back_forward_menu_model_gtk.h', 'browser/gtk/bookmark_bar_gtk.cc', |