summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 20:02:29 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 20:02:29 +0000
commitfc9e60e86ec510dcf50fa27b6d5c9bf29cb7976f (patch)
tree747eb07b9b35ac012abfb81137a0b566e7ab1dbf
parentb629252f80a6c5230e19f9bfa4d1a07936ab3771 (diff)
downloadchromium_src-fc9e60e86ec510dcf50fa27b6d5c9bf29cb7976f.zip
chromium_src-fc9e60e86ec510dcf50fa27b6d5c9bf29cb7976f.tar.gz
chromium_src-fc9e60e86ec510dcf50fa27b6d5c9bf29cb7976f.tar.bz2
Linux: Move some duplicated code to gtk_util::CreateBoldLabel and LeftAlignMisc.
BUG=none TEST=none Review URL: http://codereview.chromium.org/657065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39913 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_dialog_gtk.cc12
-rw-r--r--chrome/browser/gtk/certificate_viewer.cc35
-rw-r--r--chrome/browser/gtk/options/options_layout_gtk.cc18
-rw-r--r--chrome/browser/gtk/options/url_picker_dialog_gtk.cc15
-rw-r--r--chrome/common/gtk_util.cc16
-rw-r--r--chrome/common/gtk_util.h6
6 files changed, 39 insertions, 63 deletions
diff --git a/chrome/browser/autofill/autofill_dialog_gtk.cc b/chrome/browser/autofill/autofill_dialog_gtk.cc
index df55e3a..a94513a 100644
--- a/chrome/browser/autofill/autofill_dialog_gtk.cc
+++ b/chrome/browser/autofill/autofill_dialog_gtk.cc
@@ -23,9 +23,6 @@
namespace {
-// Style for dialog group titles.
-const char kDialogGroupTitleMarkup[] = "<span weight='bold'>%s</span>";
-
// The name of the object property used to store an entry widget pointer on
// another widget.
const char kButtonDataKey[] = "label-entry";
@@ -617,13 +614,8 @@ GtkWidget* AutoFillDialog::InitGroup(int name_id,
GtkWidget* vbox = gtk_vbox_new(false, gtk_util::kControlSpacing);
// Group label.
- GtkWidget* label = gtk_label_new(NULL);
- char* markup = g_markup_printf_escaped(
- kDialogGroupTitleMarkup,
- l10n_util::GetStringUTF8(name_id).c_str());
- gtk_label_set_markup(GTK_LABEL(label), markup);
- g_free(markup);
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+ GtkWidget* label = gtk_util::CreateBoldLabel(
+ l10n_util::GetStringUTF8(name_id));
gtk_box_pack_start(GTK_BOX(vbox),
IndentWidget(label, kAutoFillDialogIndent),
FALSE, FALSE, 0);
diff --git a/chrome/browser/gtk/certificate_viewer.cc b/chrome/browser/gtk/certificate_viewer.cc
index 6c14cab..5f539fb 100644
--- a/chrome/browser/gtk/certificate_viewer.cc
+++ b/chrome/browser/gtk/certificate_viewer.cc
@@ -260,26 +260,9 @@ std::string ProcessSubjectPublicKeyInfo(CERTSubjectPublicKeyInfo* spki) {
////////////////////////////////////////////////////////////////////////////////
// Gtk utility functions.
-GtkWidget* LeftAlign(GtkWidget* label) {
- gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- return label;
-}
-
-const char kOptionGroupTitleMarkup[] = "<span weight='bold'>%s</span>";
-
-GtkWidget* BoldLabel(const std::string& text) {
- GtkWidget* label = gtk_label_new(NULL);
- char* markup = g_markup_printf_escaped(kOptionGroupTitleMarkup,
- text.c_str());
- gtk_label_set_markup(GTK_LABEL(label), markup);
- g_free(markup);
-
- return LeftAlign(label);
-}
-
void AddTitle(GtkTable* table, int row, const std::string& text) {
gtk_table_attach_defaults(table,
- BoldLabel(text),
+ gtk_util::CreateBoldLabel(text),
0, 2,
row, row + 1);
}
@@ -288,11 +271,12 @@ void AddKeyValue(GtkTable* table, int row, const std::string& text,
const std::string& value) {
gtk_table_attach_defaults(
table,
- gtk_util::IndentWidget(LeftAlign(gtk_label_new(text.c_str()))),
+ gtk_util::IndentWidget(
+ gtk_util::LeftAlignMisc(gtk_label_new(text.c_str()))),
0, 1, row, row + 1);
gtk_table_attach_defaults(
table,
- LeftAlign(gtk_label_new(value.c_str())),
+ gtk_util::LeftAlignMisc(gtk_label_new(value.c_str())),
1, 2, row, row + 1);
}
@@ -435,7 +419,8 @@ void CertificateViewer::InitGeneralPage() {
gtk_box_pack_start(GTK_BOX(general_page_vbox_), uses_vbox, FALSE, FALSE, 0);
gtk_box_pack_start(
GTK_BOX(uses_vbox),
- BoldLabel(l10n_util::GetStringUTF8(IDS_CERT_INFO_VERIFIED_USAGES_GROUP)),
+ gtk_util::CreateBoldLabel(
+ l10n_util::GetStringUTF8(IDS_CERT_INFO_VERIFIED_USAGES_GROUP)),
FALSE, FALSE, 0);
SECCertificateUsage usages = 0;
@@ -463,7 +448,7 @@ void CertificateViewer::InitGeneralPage() {
if (usages & usageStringMap[i].usage)
gtk_box_pack_start(
GTK_BOX(uses_vbox),
- gtk_util::IndentWidget(LeftAlign(gtk_label_new(
+ gtk_util::IndentWidget(gtk_util::LeftAlignMisc(gtk_label_new(
l10n_util::GetStringUTF8(
usageStringMap[i].string_id).c_str()))),
FALSE, FALSE, 0);
@@ -749,7 +734,7 @@ void CertificateViewer::InitDetailsPage() {
FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hierarchy_vbox),
- BoldLabel(l10n_util::GetStringUTF8(
+ gtk_util::CreateBoldLabel(l10n_util::GetStringUTF8(
IDS_CERT_DETAILS_CERTIFICATE_HIERARCHY_LABEL)),
FALSE, FALSE, 0);
@@ -786,7 +771,7 @@ void CertificateViewer::InitDetailsPage() {
gtk_box_pack_start(GTK_BOX(details_page_vbox_), fields_vbox,
TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(fields_vbox),
- BoldLabel(l10n_util::GetStringUTF8(
+ gtk_util::CreateBoldLabel(l10n_util::GetStringUTF8(
IDS_CERT_DETAILS_CERTIFICATE_FIELDS_LABEL)),
FALSE, FALSE, 0);
@@ -816,7 +801,7 @@ void CertificateViewer::InitDetailsPage() {
gtk_box_pack_start(GTK_BOX(details_page_vbox_), value_vbox,
TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(value_vbox),
- BoldLabel(l10n_util::GetStringUTF8(
+ gtk_util::CreateBoldLabel(l10n_util::GetStringUTF8(
IDS_CERT_DETAILS_CERTIFICATE_FIELD_VALUE_LABEL)),
FALSE, FALSE, 0);
diff --git a/chrome/browser/gtk/options/options_layout_gtk.cc b/chrome/browser/gtk/options/options_layout_gtk.cc
index 4261f8a..4fe42b9 100644
--- a/chrome/browser/gtk/options/options_layout_gtk.cc
+++ b/chrome/browser/gtk/options/options_layout_gtk.cc
@@ -6,13 +6,6 @@
#include "chrome/common/gtk_util.h"
-namespace {
-
-// Style for option group titles
-const char kOptionGroupTitleMarkup[] = "<span weight='bold'>%s</span>";
-
-} // namespace
-
OptionsLayoutBuilderGtk::OptionsLayoutBuilderGtk() {
page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing);
gtk_container_set_border_width(GTK_CONTAINER(page_),
@@ -22,17 +15,10 @@ OptionsLayoutBuilderGtk::OptionsLayoutBuilderGtk() {
void OptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title,
GtkWidget* content,
bool expandable) {
- GtkWidget* title_label = gtk_label_new(NULL);
- char* markup = g_markup_printf_escaped(kOptionGroupTitleMarkup,
- title.c_str());
- gtk_label_set_markup(GTK_LABEL(title_label), markup);
- g_free(markup);
-
- GtkWidget* title_alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
- gtk_container_add(GTK_CONTAINER(title_alignment), title_label);
+ GtkWidget* title_label = gtk_util::CreateBoldLabel(title);
GtkWidget* group = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
- gtk_box_pack_start(GTK_BOX(group), title_alignment, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(group), title_label, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(group), gtk_util::IndentWidget(content));
gtk_box_pack_start(GTK_BOX(page_), group, expandable, expandable, 0);
diff --git a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc
index 49e0f0b..7177434 100644
--- a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc
+++ b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc
@@ -24,9 +24,6 @@
namespace {
-// Style for recent history label.
-const char kHistoryLabelMarkup[] = "<span weight='bold'>%s</span>";
-
// Column ids for |history_list_store_|.
enum {
COL_FAVICON,
@@ -79,15 +76,9 @@ UrlPickerDialogGtk::UrlPickerDialogGtk(UrlPickerCallback* callback,
// Recent history description label.
GtkWidget* history_vbox = gtk_vbox_new(FALSE, gtk_util::kLabelSpacing);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), history_vbox);
- GtkWidget* history_label = gtk_label_new(NULL);
- char* markup = g_markup_printf_escaped(kHistoryLabelMarkup,
- l10n_util::GetStringUTF8(IDS_ASI_DESCRIPTION).c_str());
- gtk_label_set_markup(GTK_LABEL(history_label), markup);
- g_free(markup);
- GtkWidget* history_label_alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
- gtk_container_add(GTK_CONTAINER(history_label_alignment), history_label);
- gtk_box_pack_start(GTK_BOX(history_vbox), history_label_alignment,
- FALSE, FALSE, 0);
+ GtkWidget* history_label = gtk_util::CreateBoldLabel(
+ l10n_util::GetStringUTF8(IDS_ASI_DESCRIPTION));
+ gtk_box_pack_start(GTK_BOX(history_vbox), history_label, FALSE, FALSE, 0);
// Recent history list.
GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL);
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
index 7972edb..a1537c0 100644
--- a/chrome/common/gtk_util.cc
+++ b/chrome/common/gtk_util.cc
@@ -24,6 +24,8 @@
namespace {
+const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>";
+
// Callback used in RemoveAllChildren.
void RemoveWidget(GtkWidget* widget, gpointer container) {
gtk_container_remove(GTK_CONTAINER(container), widget);
@@ -184,6 +186,20 @@ GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
return ebox;
}
+GtkWidget* LeftAlignMisc(GtkWidget* misc) {
+ gtk_misc_set_alignment(GTK_MISC(misc), 0, 0.5);
+ return misc;
+}
+
+GtkWidget* CreateBoldLabel(const std::string& text) {
+ GtkWidget* label = gtk_label_new(NULL);
+ char* markup = g_markup_printf_escaped(kBoldLabelMarkup, text.c_str());
+ gtk_label_set_markup(GTK_LABEL(label), markup);
+ g_free(markup);
+
+ return LeftAlignMisc(label);
+}
+
void GetWidgetSizeFromResources(GtkWidget* widget, int width_chars,
int height_lines, int* width, int* height) {
DCHECK(GTK_WIDGET_REALIZED(widget))
diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h
index 93533fd..1caf748 100644
--- a/chrome/common/gtk_util.h
+++ b/chrome/common/gtk_util.h
@@ -72,6 +72,12 @@ GtkWidget* CreateLabeledControlsGroup(
GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
int top, int bottom, int left, int right);
+// Left-align the given GtkMisc and return the same pointer.
+GtkWidget* LeftAlignMisc(GtkWidget* misc);
+
+// Create a left-aligned label with the given text in bold.
+GtkWidget* CreateBoldLabel(const std::string& text);
+
// Calculates the size of given widget based on the size specified in
// number of characters/lines (in locale specific resource file) and
// font metrics.