summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc68
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.h4
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc128
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h17
6 files changed, 95 insertions, 126 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index b8a73f0..b74ec0a 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -118,7 +118,7 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
#if defined(TOOLKIT_VIEWS)
const views::View* location_bar)
#else
- const GtkWidget* location_bar)
+ GtkWidget* location_bar)
#endif
: text_view_(NULL),
tag_table_(NULL),
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 7f11f7a..6dc5bea 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -58,7 +58,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
#if defined(TOOLKIT_VIEWS)
const views::View* location_bar);
#else
- const GtkWidget* location_bar);
+ GtkWidget* location_bar);
#endif
~AutocompleteEditViewGtk();
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 6225dc6..dfaa31b 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -46,26 +46,40 @@ const GdkColor kDescriptionSelectedTextColor = GDK_COLOR_RGB(0x78, 0x82, 0xb1);
// We have a 1 pixel border around the entire results popup.
const int kBorderThickness = 1;
+
// The vertical height of each result.
const int kHeightPerResult = 24;
+
// Width of the icons.
const int kIconWidth = 17;
+
// We want to vertically center the image in the result space.
const int kIconTopPadding = 4;
+
// Space between the left edge (including the border) and the text.
const int kIconLeftPadding = 5 + kBorderThickness;
+
// Space between the image and the text.
const int kIconRightPadding = 7;
+
// Space between the left edge (including the border) and the text.
const int kIconAreaWidth =
kIconLeftPadding + kIconWidth + kIconRightPadding;
+
// Space between the right edge (including the border) and the text.
const int kRightPadding = 3;
+
// When we have both a content and description string, we don't want the
// content to push the description off. Limit the content to a percentage of
// the total width.
const float kContentWidthPercentage = 0.7;
+// How much to offset the popup from the bottom of the location bar in gtk mode.
+const int kGtkVerticalOffset = 3;
+
+// How much we shrink the popup on the left/right in gtk mode.
+const int kGtkHorizontalOffset = 1;
+
// UTF-8 Left-to-right embedding.
const char* kLRE = "\xe2\x80\xaa";
@@ -222,7 +236,7 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk(
AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
- const GtkWidget* location_bar)
+ GtkWidget* location_bar)
: model_(new AutocompletePopupModel(this, edit_model, profile)),
edit_view_(edit_view),
location_bar_(location_bar),
@@ -373,12 +387,30 @@ void AutocompletePopupViewGtk::Observe(NotificationType type,
void AutocompletePopupViewGtk::Show(size_t num_results) {
gint origin_x, origin_y;
gdk_window_get_origin(location_bar_->window, &origin_x, &origin_y);
- const GtkAllocation& allocation = location_bar_->allocation;
+ GtkAllocation allocation = location_bar_->allocation;
+ int vertical_offset = 0;
+ int horizontal_offset = 0;
+ if (theme_provider_->UseGtkTheme()) {
+ // Shrink the popup by 1 pixel on both sides in gtk mode. The darkest line
+ // is usually one pixel in, and is almost always +/-1 pixel from this,
+ // meaning the vertical offset will hide (hopefully) problems when this is
+ // wrong.
+ horizontal_offset = kGtkHorizontalOffset;
+
+ // We offset the the popup from the bottom of the location bar in gtk
+ // mode. The background color between the bottom of the location bar and
+ // the popup helps hide the fact that we can't really reliably match what
+ // the user would otherwise preceive as the left/right edges of the
+ // location bar.
+ vertical_offset = kGtkVerticalOffset;
+ }
+
gtk_window_move(GTK_WINDOW(window_),
- origin_x + allocation.x - kBorderThickness,
- origin_y + allocation.y + allocation.height - kBorderThickness - 1);
+ origin_x + allocation.x - kBorderThickness + horizontal_offset,
+ origin_y + allocation.y + allocation.height - kBorderThickness - 1 +
+ vertical_offset);
gtk_widget_set_size_request(window_,
- allocation.width + (kBorderThickness * 2),
+ allocation.width + (kBorderThickness * 2) - (horizontal_offset * 2),
(num_results * kHeightPerResult) + (kBorderThickness * 2));
gtk_widget_show(window_);
StackWindow();
@@ -488,6 +520,17 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
pango_layout_set_height(layout_, kHeightPerResult * PANGO_SCALE);
+ // An offset to align text in gtk mode. The hard coded constants in this file
+ // are all created for the chrome-theme. In an effort to make this look good
+ // on the majority of gtk themes, we shrink the popup by one pixel on each
+ // side and push it downwards a bit so there's space between the drawn
+ // location bar and the popup so we don't touch it (contrast with
+ // chrome-theme where that's exactly what we want). Because of that, we need
+ // to shift the content inside the popup by one pixel.
+ int gtk_offset = 0;
+ if (theme_provider_->UseGtkTheme())
+ gtk_offset = kGtkHorizontalOffset;
+
for (size_t i = 0; i < result.size(); ++i) {
gfx::Rect line_rect = GetRectForLine(i, window_rect.width());
// Only repaint and layout damaged lines.
@@ -506,8 +549,8 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
line_rect.width(), line_rect.height());
}
- int icon_start_x = ltr ? kIconLeftPadding :
- line_rect.width() - kIconLeftPadding - kIconWidth;
+ int icon_start_x = ltr ? (kIconLeftPadding - gtk_offset) :
+ (line_rect.width() - kIconLeftPadding - kIconWidth + gtk_offset);
// Draw the icon for this result.
DrawFullPixbuf(drawable, gc,
IconForMatch(theme_provider_, match, is_selected),
@@ -542,7 +585,8 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
line_rect.y() + ((kHeightPerResult - actual_content_height) / 2));
gdk_draw_layout(drawable, gc,
- ltr ? kIconAreaWidth : text_width - actual_content_width,
+ ltr ? (kIconAreaWidth - gtk_offset) :
+ (text_width - actual_content_width + gtk_offset),
content_y, layout_);
if (has_description) {
@@ -556,10 +600,10 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
std::string(" - "));
gint actual_description_width;
pango_layout_get_size(layout_, &actual_description_width, NULL);
- gdk_draw_layout(drawable, gc,
- ltr ? kIconAreaWidth + actual_content_width :
- text_width - actual_content_width -
- actual_description_width / PANGO_SCALE,
+ gdk_draw_layout(drawable, gc, ltr ?
+ (kIconAreaWidth - gtk_offset + actual_content_width) :
+ (text_width - actual_content_width + gtk_offset -
+ (actual_description_width / PANGO_SCALE)),
content_y, layout_);
}
}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
index 555b531..90cd2c9 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
@@ -27,7 +27,7 @@ class AutocompletePopupViewGtk : public AutocompletePopupView,
AutocompletePopupViewGtk(AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
- const GtkWidget* location_bar);
+ GtkWidget* location_bar);
~AutocompletePopupViewGtk();
// Overridden from AutocompletePopupView:
@@ -88,7 +88,7 @@ class AutocompletePopupViewGtk : public AutocompletePopupView,
scoped_ptr<AutocompletePopupModel> model_;
AutocompleteEditView* edit_view_;
- const GtkWidget* location_bar_;
+ GtkWidget* location_bar_;
// Our popup window, which is the only widget used, and we paint it on our
// own. This widget shouldn't be exposed outside of this class.
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index de012d3..1d34f78 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -101,7 +101,6 @@ BrowserToolbarGtk::~BrowserToolbarGtk() {
browser_->command_updater()->RemoveCommandObserver(IDC_HOME, this);
browser_->command_updater()->RemoveCommandObserver(IDC_BOOKMARK_PAGE, this);
- reload_.Destroy();
offscreen_entry_.Destroy();
page_menu_.reset();
@@ -163,23 +162,25 @@ void BrowserToolbarGtk::Init(Profile* profile,
gtk_util::SetButtonTriggersNavigation(home_->widget());
SetUpDragForHomeButton();
- // Group the reload, omnibox, and go button into an hbox.
- GtkWidget* location_hbox = gtk_hbox_new(FALSE, 0);
- BuildReloadButton();
- gtk_box_pack_start(GTK_BOX(location_hbox), reload_.get(), FALSE, FALSE, 0);
+ reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0,
+ IDR_BUTTON_MASK,
+ l10n_util::GetStringUTF8(IDS_TOOLTIP_RELOAD),
+ GTK_STOCK_REFRESH));
+
+ location_hbox_ = gtk_hbox_new(FALSE, 0);
location_bar_->Init(ShouldOnlyShowLocation());
- gtk_box_pack_start(GTK_BOX(location_hbox), location_bar_->widget(), TRUE,
+ gtk_box_pack_start(GTK_BOX(location_hbox_), location_bar_->widget(), TRUE,
TRUE, 0);
- 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_signal_connect(location_hbox_, "expose-event",
G_CALLBACK(OnLocationHboxExposeThunk), this);
- gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE,
+ gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox_, TRUE, TRUE,
kToolbarWidgetSpacing + (ShouldOnlyShowLocation() ? 1 : 0));
+ go_.reset(new GoButtonGtk(location_bar_.get(), browser_));
+ gtk_box_pack_start(GTK_BOX(toolbar_), go_->widget(), FALSE, FALSE, 0);
+
if (!ShouldOnlyShowLocation()) {
actions_toolbar_.reset(new BrowserActionsToolbarGtk(browser_));
gtk_box_pack_start(GTK_BOX(toolbar_), actions_toolbar_->widget(),
@@ -218,8 +219,8 @@ void BrowserToolbarGtk::Init(Profile* profile,
gtk_widget_show(event_box_);
gtk_widget_show(alignment_);
gtk_widget_show(toolbar_);
- gtk_widget_show_all(location_hbox);
- gtk_widget_hide(reload_.get());
+ gtk_widget_show_all(location_hbox_);
+ gtk_widget_hide(reload_->widget());
gtk_widget_hide(go_->widget());
} else {
gtk_widget_show_all(event_box_);
@@ -245,7 +246,7 @@ void BrowserToolbarGtk::SetViewIDs() {
ViewIDUtil::SetID(widget(), VIEW_ID_TOOLBAR);
ViewIDUtil::SetID(back_->widget(), VIEW_ID_BACK_BUTTON);
ViewIDUtil::SetID(forward_->widget(), VIEW_ID_FORWARD_BUTTON);
- ViewIDUtil::SetID(reload_.get(), VIEW_ID_RELOAD_BUTTON);
+ ViewIDUtil::SetID(reload_->widget(), VIEW_ID_RELOAD_BUTTON);
ViewIDUtil::SetID(home_->widget(), VIEW_ID_HOME_BUTTON);
ViewIDUtil::SetID(location_bar_->widget(), VIEW_ID_LOCATION_BAR);
ViewIDUtil::SetID(go_->widget(), VIEW_ID_GO_BUTTON);
@@ -293,7 +294,7 @@ void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) {
widget = forward_->widget();
break;
case IDC_RELOAD:
- widget = reload_.get();
+ widget = reload_->widget();
break;
case IDC_GO:
widget = go_->widget();
@@ -397,13 +398,24 @@ void BrowserToolbarGtk::Observe(NotificationType type,
gtk_image_set_from_pixbuf(GTK_IMAGE(app_menu_image_),
theme_provider_->GetRTLEnabledPixbufNamed(IDR_MENU_CHROME));
+ // Update the spacing between the reload button and the location bar.
+ gtk_box_set_child_packing(
+ GTK_BOX(toolbar_), reload_->widget(),
+ FALSE, FALSE,
+ theme_provider_->UseGtkTheme() ? kToolbarWidgetSpacing : 0,
+ GTK_PACK_START);
+ gtk_box_set_child_packing(
+ GTK_BOX(toolbar_), location_hbox_,
+ TRUE, TRUE,
+ (theme_provider_->UseGtkTheme() ? kToolbarWidgetSpacing : 0) +
+ (ShouldOnlyShowLocation() ? 1 : 0),
+ GTK_PACK_START);
+
// 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.
gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_),
theme_provider_->UseGtkTheme());
-
- UpdateReloadButton();
} else {
NOTREACHED();
}
@@ -480,48 +492,6 @@ void BrowserToolbarGtk::SetUpDragForHomeButton() {
G_CALLBACK(OnDragDataReceivedThunk), this);
}
-void BrowserToolbarGtk::BuildReloadButton() {
- reload_.Own(gtk_chrome_button_new());
- gtk_widget_set_tooltip_text(reload_.get(),
- l10n_util::GetStringUTF8(IDS_TOOLTIP_RELOAD).c_str());
-
- g_signal_connect(reload_.get(), "expose-event",
- G_CALLBACK(OnReloadExposeThunk), this);
- g_signal_connect(reload_.get(), "clicked",
- G_CALLBACK(OnButtonClickThunk), this);
- GTK_WIDGET_UNSET_FLAGS(reload_.get(), GTK_CAN_FOCUS);
-
- reload_painter_.reset(new CustomDrawButtonBase(theme_provider_,
- IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, IDR_RELOAD_MASK));
-
- reload_hover_controller_.Init(reload_.get());
-}
-
-void BrowserToolbarGtk::UpdateReloadButton() {
- bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme();
- GtkWidget* reload = reload_.get();
-
- if (use_gtk) {
- GdkPixbuf* pixbuf =
- theme_provider_->GetPixbufNamed(IDR_RELOAD_NOBORDER_CENTER);
- gtk_button_set_image(GTK_BUTTON(reload),
- gtk_image_new_from_pixbuf(pixbuf));
-
- gtk_widget_set_size_request(reload, -1, -1);
- gtk_widget_set_app_paintable(reload, FALSE);
- gtk_widget_set_double_buffered(reload, TRUE);
- } else {
- gtk_widget_set_size_request(reload, reload_painter_->Width(),
- reload_painter_->Height());
-
- gtk_widget_set_app_paintable(reload, TRUE);
- gtk_widget_set_double_buffered(reload, FALSE);
- }
-
- gtk_chrome_button_set_use_gtk_rendering(
- GTK_CHROME_BUTTON(reload), use_gtk);
-}
-
void BrowserToolbarGtk::ChangeActiveMenu(GtkWidget* active_menu,
guint timestamp) {
MenuGtk* old_menu;
@@ -566,35 +536,9 @@ gboolean BrowserToolbarGtk::OnAlignmentExpose(GtkWidget* widget,
gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox,
GdkEventExpose* e) {
if (theme_provider_->UseGtkTheme()) {
- // 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* reload = reload_.get();
- GtkWidget* go = go_->widget();
- GtkWidget* left = NULL;
- GtkWidget* right = NULL;
- if (ShouldOnlyShowLocation()) {
- left = location_hbox;
- right = location_hbox;
- } else if (gtk_widget_get_direction(location_hbox) == GTK_TEXT_DIR_LTR) {
- left = reload;
- right = go;
- } else {
- left = go;
- right = reload;
- }
-
- GdkRectangle rec = {
- left->allocation.x,
- left->allocation.y,
- (right->allocation.x - left->allocation.x) + right->allocation.width,
- (right->allocation.y - left->allocation.y) + right->allocation.height
- };
-
gtk_util::DrawTextEntryBackground(offscreen_entry_.get(),
location_hbox, &e->area,
- &rec);
+ &location_hbox->allocation);
}
return FALSE;
@@ -608,7 +552,7 @@ void BrowserToolbarGtk::OnButtonClick(GtkWidget* button) {
}
int tag = -1;
- if (button == reload_.get()) {
+ if (button == reload_->widget()) {
GdkModifierType modifier_state;
if (gtk_get_current_event_state(&modifier_state) &&
modifier_state & GDK_SHIFT_MASK) {
@@ -710,13 +654,3 @@ void BrowserToolbarGtk::PopupForButtonNextTo(GtkWidget* button,
app_menu_button_.get() : page_menu_button_.get();
PopupForButton(other_button);
}
-
-gboolean BrowserToolbarGtk::OnReloadExpose(GtkWidget* widget,
- GdkEventExpose* event) {
- if (theme_provider_->UseGtkTheme()) {
- return FALSE;
- } else {
- double hover_state = reload_hover_controller_.GetCurrentValue();
- return reload_painter_->OnExpose(widget, event, hover_state);
- }
-}
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h
index 53210dc..9c5f2c8 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -136,12 +136,6 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
// Connect signals for dragging a url onto the home button.
void SetUpDragForHomeButton();
- // Create the reload button.
- void BuildReloadButton();
-
- // Update the reload button following a themes change.
- void UpdateReloadButton();
-
// Helper for the PageAppMenu event handlers. Pops down the currently active
// meun and pops up the other menu.
void ChangeActiveMenu(GtkWidget* active_menu, guint timestamp);
@@ -152,8 +146,6 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
GdkEventExpose*);
CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnLocationHboxExpose,
GdkEventExpose*);
- CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnReloadExpose,
- GdkEventExpose*);
// Gtk callback for the "clicked" signal.
CHROMEGTK_CALLBACK_0(BrowserToolbarGtk, void, OnButtonClick);
@@ -189,21 +181,20 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
// toolbar placed side by side.
GtkWidget* toolbar_;
+ // Contains all the widgets of the location bar.
+ GtkWidget* location_hbox_;
+
// The location bar view.
scoped_ptr<LocationBarViewGtk> location_bar_;
// All the buttons in the toolbar.
scoped_ptr<BackForwardButtonGtk> back_, forward_;
scoped_ptr<CustomDrawButton> home_;
+ scoped_ptr<CustomDrawButton> reload_;
scoped_ptr<GoButtonGtk> go_;
scoped_ptr<BrowserActionsToolbarGtk> actions_toolbar_;
OwnedWidgetGtk page_menu_button_, app_menu_button_;
- // Reload button stuff.
- OwnedWidgetGtk reload_;
- scoped_ptr<CustomDrawButtonBase> reload_painter_;
- CustomDrawHoverController reload_hover_controller_;
-
// Keep a pointer to the menu button images because we change them when
// the theme changes.
GtkWidget* page_menu_image_;