diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 23:18:54 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 23:18:54 +0000 |
commit | 767eed2cb4dfbdd57b14aafb85ab0a7570f71a7c (patch) | |
tree | 7c96818400ac6c68bead8b60188cdf9a51de5b20 /chrome/browser/gtk | |
parent | 9eb85f5502b8e304e008a4e3465efbff6e158296 (diff) | |
download | chromium_src-767eed2cb4dfbdd57b14aafb85ab0a7570f71a7c.zip chromium_src-767eed2cb4dfbdd57b14aafb85ab0a7570f71a7c.tar.gz chromium_src-767eed2cb4dfbdd57b14aafb85ab0a7570f71a7c.tar.bz2 |
GTK Themes: Fix the find bar so the match count is inside the entry.
In addition, only draw the dirty rectangle area when manually drawing a gtk entry.
http://crbug.com/17962
Review URL: http://codereview.chromium.org/174577
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24558 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 30 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 109 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.h | 8 |
3 files changed, 104 insertions, 43 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 4397220..89d23d9 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -597,33 +597,9 @@ gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, ToolbarModel::SECURE) ? &kSecureColor : NULL); - GtkStyle* gtk_owned_style = - gtk_rc_get_style(toolbar->offscreen_entry_.get()); - // GTK owns the above and we're going to have to make our own copy of it - // that we can edit. - GtkStyle* our_style = gtk_style_copy(gtk_owned_style); - our_style = gtk_style_attach(our_style, location_hbox->window); - - // TODO(erg): Draw the focus ring if appropriate... - - // We're using GTK rendering; draw a GTK entry widget onto the background. - gtk_paint_shadow(our_style, location_hbox->window, - GTK_STATE_NORMAL, GTK_SHADOW_IN, &rec, - location_hbox, "entry", - rec.x, rec.y, rec.width, rec.height); - - // Draw the interior background (not all themes draw the entry background - // above; this is a noop on themes that do). - gint xborder = our_style->xthickness; - gint yborder = our_style->ythickness; - gtk_paint_flat_box(our_style, location_hbox->window, - GTK_STATE_NORMAL, GTK_SHADOW_NONE, &rec, - location_hbox, "entry_bg", - rec.x + xborder, rec.y + yborder, - rec.width - 2 * xborder, - rec.height - 2 * yborder); - - g_object_unref(our_style); + gtk_util::DrawTextEntryBackground(toolbar->offscreen_entry_.get(), + location_hbox, &e->area, + &rec); } return FALSE; diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index ac67614..0bf856a 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -138,6 +138,26 @@ const NineBox* GetDialogBorder() { return dialog_border; } +// Like gtk_util::CreateGtkBorderBin, but allows control over the alignment and +// returns both the event box and the alignment so we can modify it during its +// lifetime (i.e. during a theme change). +void BuildBorder(GtkWidget* child, + bool center, + int padding_top, int padding_bottom, int padding_left, + int padding_right, + GtkWidget** ebox, GtkWidget** alignment) { + *ebox = gtk_event_box_new(); + if (center) + *alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); + else + *alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); + gtk_alignment_set_padding(GTK_ALIGNMENT(*alignment), + padding_top, padding_bottom, padding_left, + padding_right); + gtk_container_add(GTK_CONTAINER(*alignment), child); + gtk_container_add(GTK_CONTAINER(*ebox), *alignment); +} + } // namespace FindBarGtk::FindBarGtk(Browser* browser) @@ -242,6 +262,7 @@ void FindBarGtk::InitWidgets() { gtk_widget_set_size_request(content_hbox, kTextEntryWidth, -1); text_entry_ = gtk_entry_new(); + gtk_entry_set_has_frame(GTK_ENTRY(text_entry_), FALSE); match_count_label_ = gtk_label_new(NULL); // This line adds padding on the sides so that the label has even padding on @@ -262,16 +283,19 @@ void FindBarGtk::InitWidgets() { FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(content_hbox), text_entry_, TRUE, TRUE, 0); - // This event box is necessary to color in the area above and below the - // match count label. - content_event_box_ = gtk_event_box_new(); - gtk_container_add(GTK_CONTAINER(content_event_box_), content_hbox); + // This event box is necessary to color in the area above and below the match + // count label, and is where we draw the entry background onto in GTK mode. + BuildBorder(content_hbox, true, 0, 0, 0, 0, + &content_event_box_, &content_alignment_); + gtk_widget_set_app_paintable(content_event_box_, TRUE); + g_signal_connect(content_event_box_, "expose-event", + G_CALLBACK(OnContentEventBoxExpose), this); // We fake anti-aliasing by having two borders. - border_bin_ = gtk_util::CreateGtkBorderBin(content_event_box_, NULL, - 1, 1, 1, 0); - border_bin_aa_ = gtk_util::CreateGtkBorderBin(border_bin_, NULL, - 1, 1, 1, 0); + BuildBorder(content_event_box_, false, 1, 1, 1, 0, + &border_bin_, &border_bin_alignment_); + BuildBorder(border_bin_, false, 1, 1, 1, 0, + &border_bin_aa_, &border_bin_aa_alignment_); gtk_util::CenterWidgetInHBox(hbox, border_bin_aa_, true, 0); theme_provider_->InitThemesFor(this); @@ -448,21 +472,34 @@ void FindBarGtk::Observe(NotificationType type, GdkColor color = theme_provider_->GetBorderColor(); gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &color); - gtk_entry_set_has_frame(GTK_ENTRY(text_entry_), TRUE); gtk_widget_modify_base(text_entry_, GTK_STATE_NORMAL, NULL); gtk_widget_modify_text(text_entry_, GTK_STATE_NORMAL, NULL); gtk_widget_set_size_request(content_event_box_, -1, -1); gtk_widget_modify_bg(content_event_box_, GTK_STATE_NORMAL, NULL); + // Replicate the normal GtkEntry behaviour by drawing the entry + // background. We set the fake alignment to be the frame thickness. + GtkStyle* style = gtk_rc_get_style(text_entry_); + gint xborder = style->xthickness; + gint yborder = style->ythickness; + gtk_alignment_set_padding(GTK_ALIGNMENT(content_alignment_), + yborder, yborder, xborder, xborder); + gtk_widget_modify_bg(border_bin_, GTK_STATE_NORMAL, NULL); gtk_widget_modify_bg(border_bin_aa_, GTK_STATE_NORMAL, NULL); + // We leave left padding on the left, even in GTK mode, as it's required + // for the left margin to be equivalent to the bottom margin. + gtk_alignment_set_padding(GTK_ALIGNMENT(border_bin_alignment_), + 0, 0, 1, 0); + gtk_alignment_set_padding(GTK_ALIGNMENT(border_bin_aa_alignment_), + 0, 0, 0, 0); + gtk_misc_set_alignment(GTK_MISC(match_count_label_), 0.5, 0.5); } else { gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &kFrameBorderColor); - gtk_entry_set_has_frame(GTK_ENTRY(text_entry_), FALSE); gtk_widget_modify_base(text_entry_, GTK_STATE_NORMAL, &kEntryBackgroundColor); gtk_widget_modify_text(text_entry_, GTK_STATE_NORMAL, @@ -474,9 +511,17 @@ void FindBarGtk::Observe(NotificationType type, gtk_widget_modify_bg(content_event_box_, GTK_STATE_NORMAL, &kEntryBackgroundColor); + gtk_alignment_set_padding(GTK_ALIGNMENT(content_alignment_), + 0.0, 0.0, 0.0, 0.0); + gtk_widget_modify_bg(border_bin_, GTK_STATE_NORMAL, &kTextBorderColor); gtk_widget_modify_bg(border_bin_aa_, GTK_STATE_NORMAL, &kTextBorderColorAA); + gtk_alignment_set_padding(GTK_ALIGNMENT(border_bin_alignment_), + 1, 1, 1, 0); + gtk_alignment_set_padding(GTK_ALIGNMENT(border_bin_aa_alignment_), + 1, 1, 1, 0); + gtk_misc_set_alignment(GTK_MISC(match_count_label_), 0.5, 1.0); } @@ -511,12 +556,24 @@ void FindBarGtk::UpdateMatchLabelAppearance(bool failure) { match_label_failure_ = failure; bool use_gtk = theme_provider_->UseGtkTheme(); - gtk_widget_modify_bg(match_count_event_box_, GTK_STATE_NORMAL, - failure ? &kFindFailureBackgroundColor : - (use_gtk ? NULL : &kEntryBackgroundColor)); - gtk_widget_modify_fg(match_count_label_, GTK_STATE_NORMAL, - failure ? &kEntryTextColor : - (use_gtk ? NULL : &kFindSuccessTextColor)); + if (use_gtk) { + GtkStyle* style = gtk_rc_get_style(text_entry_); + GdkColor normal_bg = style->base[GTK_STATE_NORMAL]; + GdkColor normal_text = gtk_util::AverageColors( + style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); + + gtk_widget_modify_bg(match_count_event_box_, GTK_STATE_NORMAL, + failure ? &kFindFailureBackgroundColor : + &normal_bg); + gtk_widget_modify_fg(match_count_label_, GTK_STATE_NORMAL, + failure ? &kEntryTextColor : &normal_text); + } else { + gtk_widget_modify_bg(match_count_event_box_, GTK_STATE_NORMAL, + failure ? &kFindFailureBackgroundColor : + &kEntryBackgroundColor); + gtk_widget_modify_fg(match_count_label_, GTK_STATE_NORMAL, + failure ? &kEntryTextColor : &kFindSuccessTextColor); + } } void FindBarGtk::Reposition() { @@ -617,6 +674,26 @@ void FindBarGtk::OnClicked(GtkWidget* button, FindBarGtk* find_bar) { } // static +gboolean FindBarGtk::OnContentEventBoxExpose(GtkWidget* widget, + GdkEventExpose* event, + FindBarGtk* bar) { + if (bar->theme_provider_->UseGtkTheme()) { + // Draw the text entry background around where we input stuff. + GdkRectangle rec = { + widget->allocation.x, + widget->allocation.y, + widget->allocation.width, + widget->allocation.height + }; + + gtk_util::DrawTextEntryBackground(bar->text_entry_, widget, + &event->area, &rec); + } + + return FALSE; +} + +// static void FindBarGtk::OnFixedSizeAllocate(GtkWidget* fixed, GtkAllocation* allocation, FindBarGtk* findbar) { diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h index e26fd07..336316d 100644 --- a/chrome/browser/gtk/find_bar_gtk.h +++ b/chrome/browser/gtk/find_bar_gtk.h @@ -115,6 +115,11 @@ class FindBarGtk : public FindBar, static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* event, FindBarGtk* bar); + // Expose that draws the text entry background in GTK mode. + static gboolean OnContentEventBoxExpose(GtkWidget* widget, + GdkEventExpose* event, + FindBarGtk* bar); + // These are both used for focus management. static gboolean OnFocus(GtkWidget* text_entry, GtkDirectionType focus, FindBarGtk* find_bar); @@ -151,10 +156,13 @@ class FindBarGtk : public FindBar, // An event box and alignment that wrap the entry area and the count label. GtkWidget* content_event_box_; + GtkWidget* content_alignment_; // The border around the text entry area. GtkWidget* border_bin_; + GtkWidget* border_bin_alignment_; GtkWidget* border_bin_aa_; + GtkWidget* border_bin_aa_alignment_; // The next and previous match buttons. scoped_ptr<CustomDrawButton> find_previous_button_; |