summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 23:23:25 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 23:23:25 +0000
commit7e9c5769dd8aaa4a72f2d272d17fbe57703cd143 (patch)
tree5a8f8cc41710d53c2d8d0a52c8e7dd45a3f23135 /chrome/browser
parentf7a684345d7bfa3ebcabdadecef3c720c7ac6812 (diff)
downloadchromium_src-7e9c5769dd8aaa4a72f2d272d17fbe57703cd143.zip
chromium_src-7e9c5769dd8aaa4a72f2d272d17fbe57703cd143.tar.gz
chromium_src-7e9c5769dd8aaa4a72f2d272d17fbe57703cd143.tar.bz2
GTK Themes: Native omnibox part 2.
Put the star and go/stop buttons inside the location bar drawing. Reverts my changes to location_bar_view_gtk.cc in the previous patch. (Showed mocks of this to Ben and Glen.) Also fixes rendering of the location bar background under Crux and other themes that draw an entry_bg. Review URL: http://codereview.chromium.org/159610 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22018 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc95
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h7
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc33
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h4
4 files changed, 91 insertions, 48 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index a628394..f10d605 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -9,8 +9,9 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
-#include "base/logging.h"
#include "base/base_paths_linux.h"
+#include "base/gfx/gtk_util.h"
+#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
@@ -62,6 +63,10 @@ const int kPopupTopMargin = 0;
// to leave 1 pixel on both side here so that the borders line up.
const int kPopupLeftRightMargin = 1;
+// The color used as the base[] color of the location entry during a secure
+// connection.
+const GdkColor kSecureColor = GDK_COLOR_RGB(255, 245, 195);
+
} // namespace
// BrowserToolbarGtk, public ---------------------------------------------------
@@ -88,6 +93,8 @@ BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window)
}
BrowserToolbarGtk::~BrowserToolbarGtk() {
+ offscreen_entry_.Destroy();
+
// When we created our MenuGtk objects, we pass them a pointer to our accel
// group. Make sure to tear them down before |accel_group_|.
page_menu_.reset();
@@ -130,6 +137,7 @@ void BrowserToolbarGtk::Init(Profile* profile,
SetProfile(profile);
theme_provider_ = GtkThemeProvider::GetFrom(profile);
+ offscreen_entry_.Own(gtk_entry_new());
show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this);
@@ -189,6 +197,8 @@ 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);
@@ -389,17 +399,12 @@ void BrowserToolbarGtk::UpdateTabContents(TabContents* contents,
gfx::Rect BrowserToolbarGtk::GetPopupBounds() const {
GtkWidget* left;
GtkWidget* right;
- if (theme_provider_->UseGtkTheme()) {
- left = location_bar_->widget();
- right = location_bar_->widget();
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ left = go_->widget();
+ right = star_->widget();
} else {
- if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
- left = go_->widget();
- right = star_->widget();
- } else {
- left = star_->widget();
- right = go_->widget();
- }
+ left = star_->widget();
+ right = go_->widget();
}
// TODO(deanm): The go and star buttons probably share the same window,
@@ -521,6 +526,74 @@ 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 issue raw gtk
+ // painting commands to the theme engine. We figure out the region from the
+ // leftmost widget to the rightmost and then tell GTK to perform the same
+ // drawing commands that draw a GtkEntry on that region.
+ 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;
+
+ // Make sure our off screen entry has the correct base color if we're in
+ // secure mode.
+ gtk_widget_modify_base(
+ toolbar->offscreen_entry_.get(), GTK_STATE_NORMAL,
+ (toolbar->browser_->toolbar_model()->GetSchemeSecurityLevel() ==
+ 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, NULL,
+ location_hbox, "entry",
+ x, y, width, 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, NULL,
+ location_hbox, "entry_bg",
+ x + xborder, y + yborder,
+ width - 2 * xborder,
+ height - 2 * yborder);
+
+ g_object_unref(our_style);
+ }
+
+ 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 9875b79..bd8317c 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -114,6 +114,9 @@ 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);
@@ -205,6 +208,10 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
NotificationRegistrar registrar_;
+ // A GtkEntry that isn't part of the hierarchy. We keep this for native
+ // rendering.
+ OwnedWidgetGtk offscreen_entry_;
+
DISALLOW_COPY_AND_ASSIGN(BrowserToolbarGtk);
};
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index d2d1346..8988f47f 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -120,13 +120,9 @@ 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_,
@@ -445,35 +441,6 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
}
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 e241537..1ac1fa4 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -107,10 +107,6 @@ 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_;