summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 00:35:27 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 00:35:27 +0000
commitd71cc6cc3834d8824c063b9fccf75b3559f545f3 (patch)
treec91fafa12acc5b2958e650106fb21179009751cb /chrome
parentd17c865366e935a09158cbbbf0bf7b93c24668ad (diff)
downloadchromium_src-d71cc6cc3834d8824c063b9fccf75b3559f545f3.zip
chromium_src-d71cc6cc3834d8824c063b9fccf75b3559f545f3.tar.gz
chromium_src-d71cc6cc3834d8824c063b9fccf75b3559f545f3.tar.bz2
GTK: Allow users to override fonts and font sizes in gtk-mode.
This works on both the location bar and the find bar, the only places I could find where we do weird stuff with widgets. We still force font sizes in chrome-theme mode. Effectively, while this doesn't completely solve 22614, it should mitigate the symptoms in a lot of cases. BUG=12195,22614 TEST=In GNOME, change your system font while chrome is in gtk-theme mode. The font in the location bar and in the find bar should match the application font. Review URL: http://codereview.chromium.org/2124005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47478 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc14
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc65
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h10
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc86
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h3
5 files changed, 103 insertions, 75 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index b78a9f6..5f4b1aaf 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -219,12 +219,6 @@ void AutocompleteEditViewGtk::Init() {
if (popup_window_mode_)
gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view_), false);
- // Until we switch to vector graphics, force the font size.
- gtk_util::ForceFontSizePixels(text_view_,
- popup_window_mode_ ?
- browser_defaults::kAutocompleteEditFontPixelSizeInPopup :
- browser_defaults::kAutocompleteEditFontPixelSize);
-
// One pixel left margin is necessary to make the cursor visible when UI
// language direction is LTR but |text_buffer_|'s content direction is RTL.
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_view_), 1);
@@ -626,6 +620,8 @@ void AutocompleteEditViewGtk::SetBaseColor() {
gtk_widget_modify_base(text_view_, GTK_STATE_ACTIVE, NULL);
gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, NULL);
+ gtk_util::UndoForceFontSize(text_view_);
+
// Grab the text colors out of the style and set our tags to use them.
GtkStyle* style = gtk_rc_get_style(text_view_);
@@ -667,6 +663,12 @@ void AutocompleteEditViewGtk::SetBaseColor() {
gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, &c);
#endif
+ // Until we switch to vector graphics, force the font size.
+ gtk_util::ForceFontSizePixels(text_view_,
+ popup_window_mode_ ?
+ browser_defaults::kAutocompleteEditFontPixelSizeInPopup :
+ browser_defaults::kAutocompleteEditFontPixelSize);
+
g_object_set(faded_text_tag_, "foreground", kTextBaseColor, NULL);
g_object_set(normal_text_tag_, "foreground", "#000000", NULL);
}
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index 6cd4d8e..afa9d27 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -131,41 +131,38 @@ void BrowserToolbarGtk::Init(Profile* profile,
G_CALLBACK(&OnAlignmentExposeThunk), this);
gtk_container_add(GTK_CONTAINER(event_box_), alignment_);
gtk_container_add(GTK_CONTAINER(alignment_), toolbar_);
- // Force the height of the toolbar so we get the right amount of padding
- // above and below the location bar. -1 for width means "let GTK do its
- // normal sizing".
- gtk_widget_set_size_request(toolbar_, -1, ShouldOnlyShowLocation() ?
- kToolbarHeightLocationBarOnly : kToolbarHeight);
- // Group back and forward into an hbox so there's no spacing between them.
- GtkWidget* back_forward_hbox_ = gtk_hbox_new(FALSE, 0);
+ toolbar_left_ = gtk_hbox_new(FALSE, 0);
+ GtkWidget* back_forward_hbox_ = gtk_hbox_new(FALSE, 0);
back_.reset(new BackForwardButtonGtk(browser_, false));
- gtk_box_pack_start(GTK_BOX(back_forward_hbox_), back_->widget(), FALSE,
- FALSE, 0);
g_signal_connect(back_->widget(), "clicked",
G_CALLBACK(OnButtonClickThunk), this);
+ gtk_box_pack_start(GTK_BOX(back_forward_hbox_), back_->widget(), FALSE,
+ FALSE, 0);
forward_.reset(new BackForwardButtonGtk(browser_, true));
- gtk_box_pack_start(GTK_BOX(back_forward_hbox_), forward_->widget(), FALSE,
- FALSE, 0);
g_signal_connect(forward_->widget(), "clicked",
G_CALLBACK(OnButtonClickThunk), this);
- gtk_box_pack_start(GTK_BOX(toolbar_), back_forward_hbox_, FALSE, FALSE,
- kToolbarWidgetSpacing);
+ gtk_box_pack_start(GTK_BOX(back_forward_hbox_), forward_->widget(), FALSE,
+ FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(toolbar_left_), back_forward_hbox_, FALSE,
+ FALSE, kToolbarWidgetSpacing);
home_.reset(BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0,
IDR_BUTTON_MASK,
l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME),
- GTK_STOCK_HOME));
+ GTK_STOCK_HOME, kToolbarWidgetSpacing));
gtk_util::SetButtonTriggersNavigation(home_->widget());
SetUpDragForHomeButton();
-
reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0,
IDR_RELOAD_MASK,
l10n_util::GetStringUTF8(IDS_TOOLTIP_RELOAD),
- GTK_STOCK_REFRESH));
+ GTK_STOCK_REFRESH, 0));
+
+ gtk_box_pack_start(GTK_BOX(toolbar_), toolbar_left_, FALSE, FALSE, 0);
location_hbox_ = gtk_hbox_new(FALSE, 0);
location_bar_->Init(ShouldOnlyShowLocation());
@@ -177,17 +174,17 @@ void BrowserToolbarGtk::Init(Profile* profile,
gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox_, TRUE, TRUE,
kToolbarWidgetSpacing + (ShouldOnlyShowLocation() ? 1 : 0));
+ toolbar_right_ = gtk_hbox_new(FALSE, 0);
+
go_.reset(new GoButtonGtk(location_bar_.get(), browser_));
- gtk_box_pack_start(GTK_BOX(toolbar_), go_->widget(), FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(toolbar_right_), go_->widget(), FALSE, FALSE, 0);
if (!ShouldOnlyShowLocation()) {
actions_toolbar_.reset(new BrowserActionsToolbarGtk(browser_));
- gtk_box_pack_start(GTK_BOX(toolbar_), actions_toolbar_->widget(),
+ gtk_box_pack_start(GTK_BOX(toolbar_right_), actions_toolbar_->widget(),
FALSE, FALSE, 0);
}
- // Group the menu buttons together in an hbox.
- GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0);
GtkWidget* page_menu = BuildToolbarMenuButton(
l10n_util::GetStringUTF8(IDS_PAGEMENU_TOOLTIP),
&page_menu_button_);
@@ -197,7 +194,7 @@ void BrowserToolbarGtk::Init(Profile* profile,
gtk_container_add(GTK_CONTAINER(page_menu), page_menu_image_);
page_menu_.reset(new MenuGtk(this, &page_menu_model_));
- gtk_box_pack_start(GTK_BOX(menus_hbox_), page_menu, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(toolbar_right_), page_menu, FALSE, FALSE, 0);
GtkWidget* chrome_menu = BuildToolbarMenuButton(
l10n_util::GetStringFUTF8(IDS_APPMENU_TOOLTIP,
@@ -209,10 +206,9 @@ void BrowserToolbarGtk::Init(Profile* profile,
gtk_container_add(GTK_CONTAINER(chrome_menu), app_menu_image_);
app_menu_.reset(new MenuGtk(this, &app_menu_model_));
- gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(toolbar_right_), chrome_menu, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE,
- kToolbarWidgetSpacing);
+ gtk_box_pack_start(GTK_BOX(toolbar_), toolbar_right_, FALSE, FALSE, 0);
if (ShouldOnlyShowLocation()) {
gtk_widget_show(event_box_);
@@ -385,7 +381,8 @@ void BrowserToolbarGtk::Observe(NotificationType type,
}
} else if (type == NotificationType::BROWSER_THEME_CHANGED) {
// Update the spacing around the menu buttons
- int border = theme_provider_->UseGtkTheme() ? 0 : 2;
+ bool use_gtk = theme_provider_->UseGtkTheme();
+ int border = use_gtk ? 0 : 2;
gtk_container_set_border_width(
GTK_CONTAINER(page_menu_button_.get()), border);
gtk_container_set_border_width(
@@ -410,6 +407,18 @@ void BrowserToolbarGtk::Observe(NotificationType type,
(ShouldOnlyShowLocation() ? 1 : 0),
GTK_PACK_START);
+ // Force the height of the toolbar so we get the right amount of padding
+ // above and below the location bar. We always force the size of the hboxes
+ // to either side of the location box, but we only force the location box
+ // size in chrome-theme mode because that's the only time we try to control
+ // the font size.
+ int toolbar_height = ShouldOnlyShowLocation() ?
+ kToolbarHeightLocationBarOnly : kToolbarHeight;
+ gtk_widget_set_size_request(toolbar_left_, -1, toolbar_height);
+ gtk_widget_set_size_request(toolbar_right_, -1, toolbar_height);
+ gtk_widget_set_size_request(location_hbox_, -1,
+ use_gtk ? -1 : toolbar_height);
+
// When using the GTK+ theme, we need to have the event box be visible so
// buttons don't get a halo color from the background. When using Chromium
// themes, we want to let the background show through the toolbar.
@@ -450,7 +459,7 @@ void BrowserToolbarGtk::UpdateTabContents(TabContents* contents,
CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton(
int normal_id, int active_id, int highlight_id, int depressed_id,
int background_id, const std::string& localized_tooltip,
- const char* stock_id) {
+ const char* stock_id, int spacing) {
CustomDrawButton* button = new CustomDrawButton(
GtkThemeProvider::GetFrom(profile_),
normal_id, active_id, highlight_id, depressed_id, background_id, stock_id,
@@ -461,8 +470,8 @@ CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton(
g_signal_connect(button->widget(), "clicked",
G_CALLBACK(OnButtonClickThunk), this);
- gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE,
- kToolbarWidgetSpacing);
+ gtk_box_pack_start(GTK_BOX(toolbar_left_), button->widget(), FALSE, FALSE,
+ spacing);
return button;
}
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h
index 9c5f2c8..1582982 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -126,7 +126,8 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
int depressed_id,
int background_id,
const std::string& localized_tooltip,
- const char* stock_id);
+ const char* stock_id,
+ int spacing);
// Create a menu for the toolbar given the icon id and tooltip. Returns the
// widget created.
@@ -181,6 +182,13 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
// toolbar placed side by side.
GtkWidget* toolbar_;
+ // All widgets to the left or right of the |location_hbox_|. We put the
+ // widgets on either side of location_hbox_ in their own toolbar so we can
+ // set their minimum sizes independently of |location_hbox_| which needs to
+ // grow/shrink in GTK+ mode.
+ GtkWidget* toolbar_left_;
+ GtkWidget* toolbar_right_;
+
// Contains all the widgets of the location bar.
GtkWidget* location_hbox_;
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index f52c086..e93e862 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -225,23 +225,21 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
G_CALLBACK(&OnEntryBoxSizeAllocateThunk), this);
// Tab to search (the keyword box on the left hand side).
- // Put full and partial labels into a GtkFixed, so that we can show one of
- // them and hide the other easily.
tab_to_search_full_label_ = gtk_label_new(NULL);
tab_to_search_partial_label_ = gtk_label_new(NULL);
- GtkWidget* tab_to_search_label_fixed = gtk_fixed_new();
- gtk_fixed_put(GTK_FIXED(tab_to_search_label_fixed),
- tab_to_search_full_label_, 0, 0);
- gtk_fixed_put(GTK_FIXED(tab_to_search_label_fixed),
- tab_to_search_partial_label_, 0, 0);
+ GtkWidget* tab_to_search_label_hbox = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(tab_to_search_label_hbox),
+ tab_to_search_full_label_, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(tab_to_search_label_hbox),
+ tab_to_search_partial_label_, FALSE, FALSE, 0);
GtkWidget* tab_to_search_hbox = gtk_hbox_new(FALSE, 0);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
GtkWidget* tab_to_search_lens = gtk_image_new_from_pixbuf(
rb.GetPixbufNamed(IDR_OMNIBOX_SEARCH));
gtk_box_pack_start(GTK_BOX(tab_to_search_hbox), tab_to_search_lens,
FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(tab_to_search_hbox), tab_to_search_label_fixed,
- FALSE, FALSE, 0);
+ gtk_util::CenterWidgetInHBox(tab_to_search_hbox, tab_to_search_label_hbox,
+ false, 0);
// This creates a box around the keyword text with a border, background color,
// and padding around the text.
@@ -258,25 +256,11 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
gtk_widget_hide(tab_to_search_partial_label_);
gtk_box_pack_start(GTK_BOX(entry_box), tab_to_search_box_, FALSE, FALSE, 0);
- GtkWidget* align = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
- // TODO(erg): Like in BrowserToolbarGtk, this used to have a code path on
- // construction for with GTK themes and without. Doing that only on
- // construction was wrong, and I can't see a difference between the two ways
- // anyway... Investigate more later.
- if (popup_window_mode_) {
- gtk_alignment_set_padding(GTK_ALIGNMENT(align),
- kTopMargin + kBorderThickness,
- kBottomMargin + kBorderThickness,
- kBorderThickness,
- kBorderThickness);
- } else {
- gtk_alignment_set_padding(GTK_ALIGNMENT(align),
- kTopMargin + kBorderThickness,
- kBottomMargin + kBorderThickness,
- 0, 0);
- }
- gtk_container_add(GTK_CONTAINER(align), location_entry_->GetNativeView());
- gtk_box_pack_start(GTK_BOX(entry_box), align, TRUE, TRUE, 0);
+ location_entry_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
+ gtk_container_add(GTK_CONTAINER(location_entry_alignment_),
+ location_entry_->GetNativeView());
+ gtk_box_pack_start(GTK_BOX(entry_box), location_entry_alignment_,
+ TRUE, TRUE, 0);
// Tab to search notification (the hint on the right hand side).
tab_to_search_hint_ = gtk_hbox_new(FALSE, 0);
@@ -330,18 +314,6 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(),
FALSE, FALSE, 0);
- // Until we switch to vector graphics, force the font size of labels.
- gtk_util::ForceFontSizePixels(security_info_label_,
- browser_defaults::kAutocompleteEditFontPixelSize);
- gtk_util::ForceFontSizePixels(tab_to_search_full_label_,
- browser_defaults::kAutocompleteEditFontPixelSize);
- gtk_util::ForceFontSizePixels(tab_to_search_partial_label_,
- browser_defaults::kAutocompleteEditFontPixelSize);
- gtk_util::ForceFontSizePixels(tab_to_search_hint_leading_label_,
- browser_defaults::kAutocompleteEditFontPixelSize);
- gtk_util::ForceFontSizePixels(tab_to_search_hint_trailing_label_,
- browser_defaults::kAutocompleteEditFontPixelSize);
-
registrar_.Add(this,
NotificationType::BROWSER_THEME_CHANGED,
NotificationService::AllSources());
@@ -747,6 +719,15 @@ void LocationBarViewGtk::Observe(NotificationType type,
gtk_util::SetLabelColor(tab_to_search_partial_label_, NULL);
gtk_util::SetLabelColor(tab_to_search_hint_leading_label_, NULL);
gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, NULL);
+
+ gtk_util::UndoForceFontSize(security_info_label_);
+ gtk_util::UndoForceFontSize(tab_to_search_full_label_);
+ gtk_util::UndoForceFontSize(tab_to_search_partial_label_);
+ gtk_util::UndoForceFontSize(tab_to_search_hint_leading_label_);
+ gtk_util::UndoForceFontSize(tab_to_search_hint_trailing_label_);
+
+ gtk_alignment_set_padding(GTK_ALIGNMENT(location_entry_alignment_),
+ 0, 0, 0, 0);
} else {
gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL,
&kKeywordBackgroundColor);
@@ -759,6 +740,31 @@ void LocationBarViewGtk::Observe(NotificationType type,
&kHintTextColor);
gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_,
&kHintTextColor);
+
+ // Until we switch to vector graphics, force the font size of labels.
+ gtk_util::ForceFontSizePixels(security_info_label_,
+ browser_defaults::kAutocompleteEditFontPixelSize);
+ gtk_util::ForceFontSizePixels(tab_to_search_full_label_,
+ browser_defaults::kAutocompleteEditFontPixelSize);
+ gtk_util::ForceFontSizePixels(tab_to_search_partial_label_,
+ browser_defaults::kAutocompleteEditFontPixelSize);
+ gtk_util::ForceFontSizePixels(tab_to_search_hint_leading_label_,
+ browser_defaults::kAutocompleteEditFontPixelSize);
+ gtk_util::ForceFontSizePixels(tab_to_search_hint_trailing_label_,
+ browser_defaults::kAutocompleteEditFontPixelSize);
+
+ if (popup_window_mode_) {
+ gtk_alignment_set_padding(GTK_ALIGNMENT(location_entry_alignment_),
+ kTopMargin + kBorderThickness,
+ kBottomMargin + kBorderThickness,
+ kBorderThickness,
+ kBorderThickness);
+ } else {
+ gtk_alignment_set_padding(GTK_ALIGNMENT(location_entry_alignment_),
+ kTopMargin + kBorderThickness,
+ kBottomMargin + kBorderThickness,
+ 0, 0);
+ }
}
UpdateStarIcon();
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index f1bf435..43ccc7d 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -366,6 +366,9 @@ class LocationBarViewGtk : public AutocompleteEditController,
scoped_ptr<AutocompleteEditViewGtk> location_entry_;
+ // Alignment used to wrap |location_entry_|.
+ GtkWidget* location_entry_alignment_;
+
Profile* profile_;
CommandUpdater* command_updater_;
ToolbarModel* toolbar_model_;