diff options
-rwxr-xr-x | base/gfx/gtk_util.cc | 15 | ||||
-rwxr-xr-x | base/gfx/gtk_util.h | 7 | ||||
-rwxr-xr-x | chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc | 14 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 43 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 12 |
5 files changed, 69 insertions, 22 deletions
diff --git a/base/gfx/gtk_util.cc b/base/gfx/gtk_util.cc index e12bb6e..0808193 100755 --- a/base/gfx/gtk_util.cc +++ b/base/gfx/gtk_util.cc @@ -5,6 +5,7 @@ #include "base/gfx/gtk_util.h" #include <gdk/gdk.h> +#include <gtk/gtk.h> #include "base/gfx/rect.h" #include "skia/include/SkBitmap.h" @@ -60,4 +61,18 @@ GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { return pixbuf; } +GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color, + int top, int bottom, int left, int right) { + // Use a GtkEventBox to get the background painted. However, we can't just + // use a container border, since it won't paint there. Use an alignment + // inside to get the sizes exactly of how we want the border painted. + GtkWidget* ebox = gtk_event_box_new(); + gtk_widget_modify_bg(ebox, GTK_STATE_NORMAL, color); + GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1); + gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), top, bottom, left, right); + gtk_container_add(GTK_CONTAINER(alignment), child); + gtk_container_add(GTK_CONTAINER(ebox), alignment); + return ebox; +} + } // namespace gfx diff --git a/base/gfx/gtk_util.h b/base/gfx/gtk_util.h index 40a7855..02b1385 100755 --- a/base/gfx/gtk_util.h +++ b/base/gfx/gtk_util.h @@ -7,8 +7,10 @@ #include <vector> +typedef struct _GdkColor GdkColor; typedef struct _GdkPixbuf GdkPixbuf; typedef struct _GdkRegion GdkRegion; +typedef struct _GtkWidget GtkWidget; class SkBitmap; // Define a macro for creating GdkColors from RGB values. This is a macro to @@ -28,6 +30,11 @@ void SubtractRectanglesFromRegion(GdkRegion* region, // operation, all of the pixels must be copied and their order swapped. GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); +// Create a GtkBin with |child| as its child widget. This bin will paint a +// border of color |color| with the sizes specified in pixels. +GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color, + int top, int bottom, int left, int right); + } // namespace gfx #endif // BASE_GFX_GTK_UTIL_H_ diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index 94a5cdf..4cd305f 100755 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -41,7 +41,6 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk( // Set up a 1 pixel border around the popup. gtk_container_set_border_width(GTK_CONTAINER(window_), 1); gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &kPopupBorderColor); - gtk_widget_modify_base(window_, GTK_STATE_NORMAL, &kPopupBorderColor); } AutocompletePopupViewGtk::~AutocompletePopupViewGtk() { @@ -73,11 +72,14 @@ void AutocompletePopupViewGtk::UpdatePopupAppearance() { vbox_ = gtk_vbox_new(FALSE, 0); for (size_t i = 0; i < result.size(); ++i) { - std::string utf8; - utf8.append(WideToUTF8(result.match_at(i).contents)); - utf8.append(" - "); - utf8.append(WideToUTF8(result.match_at(i).description)); - GtkWidget* label = gtk_label_new(utf8.c_str()); + GtkWidget* label = gtk_label_new(NULL); + char* markup = g_markup_printf_escaped( + "%s <span weight=\"light\" size=\"small\">%s</span>", + WideToUTF8(result.match_at(i).contents).c_str(), + WideToUTF8(result.match_at(i).description).c_str()); + gtk_label_set_markup(GTK_LABEL(label), markup); + g_free (markup); + // We need to put the labels in an event box for background painting. GtkWidget* ebox = gtk_event_box_new(); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index f927092..4f6d623 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -7,6 +7,7 @@ #include <string> #include "base/basictypes.h" +#include "base/gfx/gtk_util.h" #include "base/logging.h" #include "base/string_util.h" #include "chrome/app/chrome_dll_resource.h" @@ -18,9 +19,22 @@ #include "skia/include/SkBitmap.h" #include "webkit/glue/window_open_disposition.h" +namespace { + +// We are positioned with a little bit of extra space that we don't use now. +const int kTopPadding = 1; +const int kBottomPadding = 2; + +// TODO(deanm): Eventually this should be painted with the background png +// image, but for now we get pretty close by just drawing a solid border. +const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4); + +} // namespace + LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater, ToolbarModel* toolbar_model) - : vbox_(NULL), + : outer_bin_(NULL), + inner_vbox_(NULL), profile_(NULL), command_updater_(command_updater), toolbar_model_(toolbar_model), @@ -29,9 +43,7 @@ LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater, } LocationBarViewGtk::~LocationBarViewGtk() { - // TODO(deanm): Should I destroy the widgets here, or leave it up to the - // embedder? When the embedder destroys their widget, if we're a child, we - // will also get destroyed, so the ownership is kinda unclear. + gtk_widget_destroy(outer_bin_); } void LocationBarViewGtk::Init() { @@ -41,17 +53,24 @@ void LocationBarViewGtk::Init() { command_updater_)); location_entry_->Init(); - vbox_ = gtk_vbox_new(false, 0); + inner_vbox_ = gtk_vbox_new(false, 0); + + // TODO(deanm): We use a bunch of widgets to get things to layout with a + // border, etc. This should eventually be custom paint using the correct + // background image, etc. + gtk_box_pack_start(GTK_BOX(inner_vbox_), location_entry_->widget(), + TRUE, TRUE, 0); - // Get the location bar to fit nicely in the toolbar, kinda ugly. - static const int kTopPadding = 2; - static const int kBottomPadding = 3; - GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1); - gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), + // Use an alignment to position our bordered location entry exactly. + outer_bin_ = gtk_alignment_new(0, 0, 1, 1); + gtk_alignment_set_padding(GTK_ALIGNMENT(outer_bin_), kTopPadding, kBottomPadding, 0, 0); - gtk_container_add(GTK_CONTAINER(alignment), location_entry_->widget()); + gtk_container_add( + GTK_CONTAINER(outer_bin_), + gfx::CreateGtkBorderBin(inner_vbox_, &kBorderColor, 1, 1, 0, 0)); - gtk_box_pack_start(GTK_BOX(vbox_), alignment, TRUE, TRUE, 0); + // Sink the ref so that we own the widget, and will destroy on destruction. + g_object_ref_sink(outer_bin_); } void LocationBarViewGtk::SetProfile(Profile* profile) { diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index 448bd5b..a970e34 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -33,9 +33,8 @@ class LocationBarViewGtk : public AutocompleteEditController, void SetProfile(Profile* profile); - // Return the native vbox widget. You must call Init() first, or the result - // will be NULL. This is the widget that an embedder should host. - GtkWidget* widget() { return vbox_; } + // Returns the widget the caller should host. You must call Init() first. + GtkWidget* widget() { return outer_bin_; } // Updates the location bar. We also reset the bar's permanent text and // security style, and, if |tab_for_state_restoring| is non-NULL, also @@ -64,7 +63,12 @@ class LocationBarViewGtk : public AutocompleteEditController, virtual void SaveStateToContents(TabContents* contents); private: - GtkWidget* vbox_; + // The outermost widget we want to be hosted. + GtkWidget* outer_bin_; + + // This is the widget you probably care about, our inner vbox (inside the + // the border) which holds the elements inside the location bar. + GtkWidget* inner_vbox_; scoped_ptr<AutocompleteEditViewGtk> location_entry_; |