Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6492)

Unified Diff: chrome/browser/ui/gtk/location_bar_view_gtk.cc

Issue 10834279: Give request-to-act badges a grey background, and increase spacing to make it fit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final (??) Windows and GTK support Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/gtk/location_bar_view_gtk.cc
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
index 821460f39a4db14f5c5d0747fd6351e5f0fde239..199649cdb563633585baa6f2382b9d1cb46dc041 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/api/commands/command_service_factory.h"
+#include "chrome/browser/extensions/extension_action_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/location_bar_controller.h"
@@ -122,9 +123,7 @@ const int kHboxBorder = 2;
// Padding between the elements in the bar.
const int kInnerPadding = 2;
-
-// Padding between the right of the star and the edge of the URL entry.
-const int kStarRightPadding = 2;
+const int kScriptBadgeInnerPadding = 9;
// Colors used to draw the EV certificate rounded bubble.
const GdkColor kEvSecureTextColor = GDK_COLOR_RGB(0x07, 0x95, 0x00);
@@ -164,6 +163,11 @@ const GdkColor kGrayBorderColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0);
const GdkColor kTopColorGray = GDK_COLOR_RGB(0xe5, 0xe5, 0xe5);
const GdkColor kBottomColorGray = GDK_COLOR_RGB(0xd0, 0xd0, 0xd0);
+inline int InnerPadding() {
+ return extensions::switch_utils::AreScriptBadgesEnabled() ?
+ kScriptBadgeInnerPadding : kInnerPadding;
+}
+
// If widget is visible, increment the int pointed to by count.
// Suitible for use with gtk_container_foreach.
void CountVisibleWidgets(GtkWidget* widget, gpointer count) {
@@ -439,7 +443,7 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
theme_service_ = GtkThemeService::GetFrom(profile);
// Create the widget first, so we can pass it to the OmniboxViewGtk.
- hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
+ hbox_.Own(gtk_hbox_new(FALSE, InnerPadding()));
gtk_container_set_border_width(GTK_CONTAINER(hbox_.get()), kHboxBorder);
// We will paint for the alignment, to paint the background and border.
gtk_widget_set_app_paintable(hbox_.get(), TRUE);
@@ -460,7 +464,7 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
// Put |tab_to_search_box_|, |location_entry_|, and |tab_to_search_hint_| into
// a sub hbox, so that we can make this part horizontally shrinkable without
// affecting other elements in the location bar.
- entry_box_ = gtk_hbox_new(FALSE, kInnerPadding);
+ entry_box_ = gtk_hbox_new(FALSE, InnerPadding());
gtk_widget_show(entry_box_);
gtk_widget_set_size_request(entry_box_, 0, -1);
gtk_box_pack_start(GTK_BOX(hbox_.get()), entry_box_, TRUE, TRUE, 0);
@@ -553,7 +557,7 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1);
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
0, kMagicActionBoxYOffset,
- 0, kInnerPadding);
+ 0, InnerPadding());
gtk_container_add(GTK_CONTAINER(alignment), action_box_button_->widget());
gtk_box_pack_end(GTK_BOX(hbox_.get()), alignment,
@@ -569,7 +573,7 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
CreateZoomButton();
gtk_box_pack_end(GTK_BOX(hbox_.get()), zoom_.get(), FALSE, FALSE, 0);
- content_setting_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding + 1));
+ content_setting_hbox_.Own(gtk_hbox_new(FALSE, InnerPadding() + 1));
gtk_widget_set_name(content_setting_hbox_.get(),
"chrome-content-setting-hbox");
gtk_box_pack_end(GTK_BOX(hbox_.get()), content_setting_hbox_.get(),
@@ -584,13 +588,13 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
content_setting_view->widget(), FALSE, FALSE, 0);
}
- page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
+ page_action_hbox_.Own(gtk_hbox_new(FALSE, InnerPadding()));
gtk_widget_set_name(page_action_hbox_.get(),
"chrome-page-action-hbox");
gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(),
FALSE, FALSE, 0);
- web_intents_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
+ web_intents_hbox_.Own(gtk_hbox_new(FALSE, InnerPadding()));
gtk_widget_set_name(web_intents_hbox_.get(),
"chrome-web-intents-hbox");
gtk_box_pack_end(GTK_BOX(hbox_.get()), web_intents_hbox_.get(),
@@ -808,7 +812,7 @@ GtkWidget* LocationBarViewGtk::CreateIconButton(
GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1);
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0,
- 0, kInnerPadding);
+ 0, InnerPadding());
gtk_container_add(GTK_CONTAINER(alignment), *image);
GtkWidget* result = gtk_event_box_new();
@@ -988,6 +992,7 @@ void LocationBarViewGtk::UpdatePageActions() {
page_action_views_[i]->UpdateVisibility(
toolbar_model_->input_in_progress() ? NULL : contents, url);
}
+ gtk_widget_queue_draw(hbox_.get());
}
// If there are no visible page actions, hide the hbox too, so that it does
@@ -1181,6 +1186,38 @@ gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
background.RenderToWidget(widget);
}
+ // Draw ExtensionAction backgrounds and borders, if necessary. The borders
+ // appear exactly between the elements, so they can't draw the borders
+ // themselves.
+ gfx::CanvasSkiaPaint canvas(event, /*opaque=*/false);
+ for (ScopedVector<PageActionViewGtk>::const_iterator
+ page_action_view = page_action_views_.begin();
+ page_action_view != page_action_views_.end();
+ ++page_action_view) {
+ if ((*page_action_view)->IsVisible()) {
+ // Figure out where the page action is drawn so we can draw
+ // borders to its left and right.
+ GtkAllocation allocation;
+ gtk_widget_get_allocation((*page_action_view)->widget(), &allocation);
+ ExtensionAction* action = (*page_action_view)->page_action();
+ gfx::Rect bounds(allocation);
+ // Make the bounding rectangle include the whole vertical range of the
+ // location bar, and the mid-point pixels between adjacent page actions.
+ //
+ // For odd InnerPadding()s, "InnerPadding() + 1" includes the mid-point
+ // between two page actions in the bounding rectangle. For even paddings,
+ // the +1 is dropped, which is right since there is no pixel at the
+ // mid-point.
+ bounds.Inset(-(InnerPadding() + 1) / 2,
+ theme_service_->UsingNativeTheme() ? -1 : 0);
+ extensions::PaintExtensionActionBackground(
+ *action, SessionID::IdForTab(GetTabContents()),
+ &canvas, bounds,
+ theme_service_->get_location_bar_text_color(),
+ theme_service_->get_location_bar_bg_color());
+ }
+ }
+
return FALSE; // Continue propagating the expose.
}
@@ -1580,7 +1617,7 @@ bool LocationBarViewGtk::ShouldOnlyShowLocation() {
void LocationBarViewGtk::AdjustChildrenVisibility() {
int text_width = location_entry_->TextWidth();
- int available_width = entry_box_width_ - text_width - kInnerPadding;
+ int available_width = entry_box_width_ - text_width - InnerPadding();
// Only one of |tab_to_search_alignment_| and |tab_to_search_hint_| can be
// visible at the same time.
@@ -1608,7 +1645,7 @@ void LocationBarViewGtk::AdjustChildrenVisibility() {
full_box_width = partial_box_width + full_partial_width_diff;
}
- if (partial_box_width >= entry_box_width_ - kInnerPadding) {
+ if (partial_box_width >= entry_box_width_ - InnerPadding()) {
gtk_widget_hide(tab_to_search_alignment_);
} else if (full_box_width >= available_width) {
gtk_widget_hide(tab_to_search_full_label_);
@@ -1626,7 +1663,7 @@ void LocationBarViewGtk::AdjustChildrenVisibility() {
gtk_widget_size_request(tab_to_search_hint_trailing_label_, &trailing);
int full_width = leading.width + icon.width + trailing.width;
- if (icon.width >= entry_box_width_ - kInnerPadding) {
+ if (icon.width >= entry_box_width_ - InnerPadding()) {
gtk_widget_hide(tab_to_search_hint_);
} else if (full_width >= available_width) {
gtk_widget_hide(tab_to_search_hint_leading_label_);
@@ -1647,7 +1684,7 @@ LocationBarViewGtk::PageToolViewGtk::PageToolViewGtk(
const LocationBarViewGtk* parent)
: alignment_(gtk_alignment_new(0, 0, 1, 1)),
event_box_(gtk_event_box_new()),
- hbox_(gtk_hbox_new(FALSE, kInnerPadding)),
+ hbox_(gtk_hbox_new(FALSE, InnerPadding())),
image_(gtk_image_new()),
label_(gtk_label_new(NULL)),
parent_(parent),

Powered by Google App Engine
This is Rietveld 408576698