summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 17:38:10 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 17:38:10 +0000
commit95ce56621a1202b00716136dc4a6d2664e3a3d07 (patch)
treec127718d01995f9ef0f1848869436f2a5bbc97ef /chrome/browser/gtk
parentd51c0705e8e387ed9451bfd5f769e4aa3a926620 (diff)
downloadchromium_src-95ce56621a1202b00716136dc4a6d2664e3a3d07.zip
chromium_src-95ce56621a1202b00716136dc4a6d2664e3a3d07.tar.gz
chromium_src-95ce56621a1202b00716136dc4a6d2664e3a3d07.tar.bz2
GTK Themes: Native location bar area.
The combined star/location bar/go construct doesn't look native. In GTK mode, make the star and go buttons act like toolbar buttons, and draw a GTK text entry widget onto the toolbar. The omnibox popup is just the size of the entry when in GTK theme mode. There's still a lot of work to be done on this; I want to properly draw focus rings, have the rest of the location box use theme colors, et cetera, but this is less broken then what's currently there. Review URL: http://codereview.chromium.org/159532 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21965 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc56
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h3
-rw-r--r--chrome/browser/gtk/go_button_gtk.cc10
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc67
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h4
-rw-r--r--chrome/browser/gtk/toolbar_star_toggle_gtk.cc10
6 files changed, 80 insertions, 70 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index bd1639d..a628394 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -189,8 +189,6 @@ void BrowserToolbarGtk::Init(Profile* profile,
go_.reset(new GoButtonGtk(location_bar_.get(), browser_));
gtk_box_pack_start(GTK_BOX(location_hbox), go_->widget(), FALSE, FALSE, 0);
- g_signal_connect(location_hbox, "expose-event",
- G_CALLBACK(OnLocationHboxExpose), this);
gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE,
ShouldOnlyShowLocation() ? 1 : 0);
@@ -391,12 +389,17 @@ void BrowserToolbarGtk::UpdateTabContents(TabContents* contents,
gfx::Rect BrowserToolbarGtk::GetPopupBounds() const {
GtkWidget* left;
GtkWidget* right;
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
- left = go_->widget();
- right = star_->widget();
+ if (theme_provider_->UseGtkTheme()) {
+ left = location_bar_->widget();
+ right = location_bar_->widget();
} else {
- left = star_->widget();
- right = go_->widget();
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ left = go_->widget();
+ right = star_->widget();
+ } else {
+ left = star_->widget();
+ right = go_->widget();
+ }
}
// TODO(deanm): The go and star buttons probably share the same window,
@@ -518,45 +521,6 @@ gboolean BrowserToolbarGtk::OnToolbarExpose(GtkWidget* widget,
}
// static
-gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox,
- GdkEventExpose* e,
- BrowserToolbarGtk* toolbar) {
- if (toolbar->theme_provider_->UseGtkTheme() &&
- !toolbar->ShouldOnlyShowLocation()) {
- // To get the proper look surrounding the location bar, we fake out the
- // theme engine into drawing a button. We fake out GTK by constructing a
- // box that's from the top left corner of the bookmark button to the bottom
- // right of the go button and fill it with a button's box (or the opposite
- // if in RTL mode).
- GtkWidget* star = toolbar->star_->widget();
- GtkWidget* left = NULL;
- GtkWidget* right = NULL;
- if (gtk_widget_get_direction(star) ==
- GTK_TEXT_DIR_LTR) {
- left = toolbar->star_->widget();
- right = toolbar->go_->widget();
- } else {
- left = toolbar->go_->widget();
- right = toolbar->star_->widget();
- }
-
- gint x = left->allocation.x;
- gint y = left->allocation.y;
- gint width = (right->allocation.x - left->allocation.x) +
- right->allocation.width;
- gint height = (right->allocation.y - left->allocation.y) +
- right->allocation.height;
-
- gtk_paint_box(star->style, location_hbox->window,
- GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL,
- location_hbox, "button",
- x, y, width, height);
- }
-
- return FALSE;
-}
-
-// static
void BrowserToolbarGtk::OnButtonClick(GtkWidget* button,
BrowserToolbarGtk* toolbar) {
int tag = -1;
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h
index 21bca5f..9875b79 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -114,9 +114,6 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
// Gtk callback for the "expose-event" signal.
static gboolean OnToolbarExpose(GtkWidget* widget, GdkEventExpose* e,
BrowserToolbarGtk* toolbar);
- static gboolean OnLocationHboxExpose(GtkWidget* omnibox_hbox,
- GdkEventExpose* e,
- BrowserToolbarGtk* toolbar);
// Gtk callback for the "clicked" signal.
static void OnButtonClick(GtkWidget* button, BrowserToolbarGtk* toolbar);
diff --git a/chrome/browser/gtk/go_button_gtk.cc b/chrome/browser/gtk/go_button_gtk.cc
index 43f3092..dfcae5e 100644
--- a/chrome/browser/gtk/go_button_gtk.cc
+++ b/chrome/browser/gtk/go_button_gtk.cc
@@ -9,6 +9,7 @@
#include "base/message_loop.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/gtk/gtk_chrome_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/browser/gtk/location_bar_view_gtk.h"
#include "chrome/browser/profile.h"
@@ -28,7 +29,7 @@ GoButtonGtk::GoButtonGtk(LocationBarViewGtk* location_bar, Browser* browser)
GtkThemeProvider::GetFrom(browser->profile()) : NULL),
go_(theme_provider_, IDR_GO, IDR_GO_P, IDR_GO_H, 0),
stop_(theme_provider_, IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0),
- widget_(gtk_button_new()) {
+ widget_(gtk_chrome_button_new()) {
gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(go_.pixbufs(0)),
gdk_pixbuf_get_height(go_.pixbufs(0)));
@@ -199,7 +200,9 @@ void GoButtonGtk::SetTooltip() {
}
void GoButtonGtk::UpdateThemeButtons() {
- if (theme_provider_ && theme_provider_->UseGtkTheme()) {
+ bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme();
+
+ if (use_gtk) {
// TODO(erg): Waiting for Glen to make a version of these that don't have a
// button border on it.
if (intended_mode_ == MODE_GO) {
@@ -224,4 +227,7 @@ void GoButtonGtk::UpdateThemeButtons() {
// We effectively double-buffer by virtue of having only one image...
gtk_widget_set_double_buffered(widget_.get(), FALSE);
}
+
+ gtk_chrome_button_set_use_gtk_rendering(
+ GTK_CHROME_BUTTON(widget_.get()), use_gtk);
}
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index b1c4e66..d2d1346 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -120,9 +120,13 @@ LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
LocationBarViewGtk::~LocationBarViewGtk() {
// All of our widgets should have be children of / owned by the alignment.
hbox_.Destroy();
+
+ offscreen_entry_.Destroy();
}
void LocationBarViewGtk::Init(bool popup_window_mode) {
+ offscreen_entry_.Own(gtk_entry_new());
+
popup_window_mode_ = popup_window_mode;
location_entry_.reset(new AutocompleteEditViewGtk(this,
toolbar_model_,
@@ -386,8 +390,6 @@ int LocationBarViewGtk::PageActionVisibleCount() {
gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
GdkEventExpose* event) {
GdkDrawable* drawable = GDK_DRAWABLE(event->window);
- GdkGC* gc = gdk_gc_new(drawable);
-
GdkRectangle* alloc_rect = &hbox_->allocation;
// The area outside of our margin, which includes the border.
@@ -397,23 +399,25 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
alloc_rect->width,
alloc_rect->height - kTopMargin - kBottomMargin};
- // Some of our calculations are a bit sloppy. Since we draw on our parent
- // window, set a clip to make sure that we don't draw outside.
- gdk_gc_set_clip_rectangle(gc, &inner_rect);
-
- // Draw the background.
- gdk_gc_set_rgb_fg_color(gc,
- &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]);
- gdk_draw_rectangle(drawable, gc, TRUE,
- inner_rect.x,
- inner_rect.y,
- inner_rect.width,
- inner_rect.height);
-
// If we're not using GTK theming, draw our own border over the edge pixels
// of the background.
if (!profile_ ||
!GtkThemeProvider::GetFrom(profile_)->UseGtkTheme()) {
+ GdkGC* gc = gdk_gc_new(drawable);
+
+ // Some of our calculations are a bit sloppy. Since we draw on our parent
+ // window, set a clip to make sure that we don't draw outside.
+ gdk_gc_set_clip_rectangle(gc, &inner_rect);
+
+ // Draw the background.
+ gdk_gc_set_rgb_fg_color(gc,
+ &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]);
+ gdk_draw_rectangle(drawable, gc, TRUE,
+ inner_rect.x,
+ inner_rect.y,
+ inner_rect.width,
+ inner_rect.height);
+
// Draw our 1px border. TODO(deanm): Maybe this would be cleaner as an
// overdrawn stroked rect with a clip to the allocation?
gdk_gc_set_rgb_fg_color(gc, &kBorderColor);
@@ -439,9 +443,38 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
kBorderThickness,
inner_rect.height);
}
- }
- g_object_unref(gc);
+ g_object_unref(gc);
+ } else {
+ // Make sure our fake entry has the correct base color if we're in secure
+ // mode.
+ gtk_widget_modify_base(
+ offscreen_entry_.get(), GTK_STATE_NORMAL,
+ (toolbar_model_->GetSchemeSecurityLevel() == ToolbarModel::SECURE) ?
+ &kBackgroundColorByLevel[ToolbarModel::SECURE] : NULL);
+
+ GtkStyle* gtk_owned_style = gtk_rc_get_style(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, 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, hbox_->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL,
+ hbox_.get(), "entry",
+ inner_rect.x, inner_rect.y, inner_rect.width,
+ inner_rect.height);
+
+ // TODO(erg): The above works for Clearlooks and most theme engines, but
+ // doesn't draw a background in Crux and some other engines. This requires
+ // a separate gtk_paint_flat_box() call, and some math to calculate where
+ // to draw the flat box.
+
+ g_object_unref(our_style);
+ }
return FALSE; // Continue propagating the expose.
}
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index 1ac1fa4..e241537 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -107,6 +107,10 @@ class LocationBarViewGtk : public AutocompleteEditController,
// The outermost widget we want to be hosted.
OwnedWidgetGtk hbox_;
+ // A GtkEntry that isn't part of the hierarchy. We keep this for native
+ // rendering.
+ OwnedWidgetGtk offscreen_entry_;
+
// SSL icons.
GtkWidget* security_icon_align_;
GtkWidget* security_lock_icon_image_;
diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
index 631ad2c..9e844d7 100644
--- a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
+++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
@@ -8,6 +8,7 @@
#include "base/gfx/rect.h"
#include "chrome/browser/gtk/bookmark_bubble_gtk.h"
#include "chrome/browser/gtk/browser_toolbar_gtk.h"
+#include "chrome/browser/gtk/gtk_chrome_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_service.h"
@@ -15,7 +16,7 @@
ToolbarStarToggleGtk::ToolbarStarToggleGtk(BrowserToolbarGtk* host)
: host_(host),
- widget_(gtk_button_new()),
+ widget_(gtk_chrome_button_new()),
is_starred_(false),
theme_provider_(GtkThemeProvider::GetFrom(host->profile())),
unstarred_(theme_provider_, IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D),
@@ -90,7 +91,9 @@ gboolean ToolbarStarToggleGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e,
}
void ToolbarStarToggleGtk::UpdateGTKButton() {
- if (theme_provider_->UseGtkTheme()) {
+ bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme();
+
+ if (use_gtk) {
GdkPixbuf* pixbuf = NULL;
if (is_starred_) {
pixbuf = theme_provider_->GetPixbufNamed(IDR_STARRED_NOBORDER);
@@ -114,4 +117,7 @@ void ToolbarStarToggleGtk::UpdateGTKButton() {
// We effectively double-buffer by virtue of having only one image...
gtk_widget_set_double_buffered(widget_.get(), FALSE);
}
+
+ gtk_chrome_button_set_use_gtk_rendering(
+ GTK_CHROME_BUTTON(widget_.get()), use_gtk);
}