Commit 3c0c1556 authored by mattm@chromium.org's avatar mattm@chromium.org

Simplify the gtk location bar padding and make it more consistent.

Sets the container border and box padding values, so that each widget doesn't need an alignment to pad itself.

With this the horizontal padding is almost the same as windows (in a few cases we have 1 more pixel between elements.)
The vertical padding should be unchanged.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/195048

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25831 0039d316-1c4b-4281-b951-d872f2087c98
parent d8a6b458
...@@ -48,25 +48,14 @@ const int kFirstRunBubbleTopMargin = 1; ...@@ -48,25 +48,14 @@ const int kFirstRunBubbleTopMargin = 1;
// Task delay (in milliseconds) to show first run bubble. // Task delay (in milliseconds) to show first run bubble.
const int kFirstRunBubbleTaskDelay = 200; const int kFirstRunBubbleTaskDelay = 200;
// Left and right padding/margin. // The padding around the top, bottom, and sides of the location bar hbox.
// no icon/text : 4px url_text 4px // We don't want to edit control's text to be right against the edge,
// [4px|url text|4px] <hide ssl icon> <hide ev text> // as well the tab to search box and other widgets need to have the padding on
// with icon : 4px url_text 6px ssl_icon 8px // top and bottom to avoid drawing larger than the location bar space.
// [4px|url text|4px] [2px|ssl icon|8px] <hide ev text> const int kHboxBorder = 4;
// with icon/text: 4px url_text 6px ssl_icon 8px ev_text 4px]
// [4px|url text|4px] [2px|ssl icon|8px] [ev text|4px]
// We don't want to edit control's text to be right against the edge. // Padding between the elements in the bar.
const int kEditLeftRightPadding = 4; static const int kInnerPadding = 4;
// Padding around the security icon.
const int kSecurityIconPaddingLeft = 0;
const int kSecurityIconPaddingRight = 6;
const int kEvTextPaddingRight = 4;
const int kKeywordTopBottomPadding = 4;
const int kKeywordLeftRightPadding = 4;
// TODO(deanm): Eventually this should be painted with the background png // 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. // image, but for now we get pretty close by just drawing a solid border.
...@@ -102,12 +91,10 @@ const GdkColor LocationBarViewGtk::kBackgroundColorByLevel[3] = { ...@@ -102,12 +91,10 @@ const GdkColor LocationBarViewGtk::kBackgroundColorByLevel[3] = {
LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater, LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
ToolbarModel* toolbar_model, AutocompletePopupPositioner* popup_positioner) ToolbarModel* toolbar_model, AutocompletePopupPositioner* popup_positioner)
: security_icon_align_(NULL), : security_icon_event_box_(NULL),
security_lock_icon_image_(NULL), security_lock_icon_image_(NULL),
security_warning_icon_image_(NULL), security_warning_icon_image_(NULL),
info_label_align_(NULL),
info_label_(NULL), info_label_(NULL),
tab_to_search_(NULL),
tab_to_search_box_(NULL), tab_to_search_box_(NULL),
tab_to_search_label_(NULL), tab_to_search_label_(NULL),
tab_to_search_hint_(NULL), tab_to_search_hint_(NULL),
...@@ -140,7 +127,8 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { ...@@ -140,7 +127,8 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
popup_positioner_)); popup_positioner_));
location_entry_->Init(); location_entry_->Init();
hbox_.Own(gtk_hbox_new(FALSE, 0)); hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
gtk_container_set_border_width(GTK_CONTAINER(hbox_.get()), kHboxBorder);
// We will paint for the alignment, to paint the background and border. // We will paint for the alignment, to paint the background and border.
gtk_widget_set_app_paintable(hbox_.get(), TRUE); gtk_widget_set_app_paintable(hbox_.get(), TRUE);
// Have GTK double buffer around the expose signal. // Have GTK double buffer around the expose signal.
...@@ -167,20 +155,14 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { ...@@ -167,20 +155,14 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
// Tab to search (the keyword box on the left hand side). // Tab to search (the keyword box on the left hand side).
tab_to_search_label_ = gtk_label_new(NULL); tab_to_search_label_ = gtk_label_new(NULL);
// We need an alignment to pad our box inside the edit area.
tab_to_search_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); // This creates a box around the keyword text with a border, background color,
gtk_alignment_set_padding(GTK_ALIGNMENT(tab_to_search_), // and padding around the text.
kKeywordTopBottomPadding, kKeywordTopBottomPadding,
kKeywordLeftRightPadding, kKeywordLeftRightPadding);
// This crazy stack of alignments and event boxes creates a box around the
// keyword text with a border, background color, and padding around the text.
tab_to_search_box_ = gtk_util::CreateGtkBorderBin( tab_to_search_box_ = gtk_util::CreateGtkBorderBin(
tab_to_search_label_, NULL, 1, 1, 2, 2); tab_to_search_label_, NULL, 1, 1, 2, 2);
gtk_util::ActAsRoundedWindow(tab_to_search_box_, kBorderColor, kCornerSize, gtk_util::ActAsRoundedWindow(tab_to_search_box_, kBorderColor, kCornerSize,
gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL);
gtk_container_add(GTK_CONTAINER(tab_to_search_), tab_to_search_box_); gtk_box_pack_start(GTK_BOX(hbox_.get()), tab_to_search_box_, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox_.get()), tab_to_search_, FALSE, FALSE, 0);
GtkWidget* align = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); GtkWidget* align = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
// TODO(erg): Like in BrowserToolbarGtk, this used to have a code path on // TODO(erg): Like in BrowserToolbarGtk, this used to have a code path on
...@@ -191,13 +173,13 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { ...@@ -191,13 +173,13 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
gtk_alignment_set_padding(GTK_ALIGNMENT(align), gtk_alignment_set_padding(GTK_ALIGNMENT(align),
kTopMargin + kBorderThickness, kTopMargin + kBorderThickness,
kBottomMargin + kBorderThickness, kBottomMargin + kBorderThickness,
kEditLeftRightPadding + kBorderThickness, kBorderThickness,
kEditLeftRightPadding + kBorderThickness); kBorderThickness);
} else { } else {
gtk_alignment_set_padding(GTK_ALIGNMENT(align), gtk_alignment_set_padding(GTK_ALIGNMENT(align),
kTopMargin + kBorderThickness, kTopMargin + kBorderThickness,
kBottomMargin + kBorderThickness, kBottomMargin + kBorderThickness,
kEditLeftRightPadding, kEditLeftRightPadding); 0, 0);
} }
gtk_container_add(GTK_CONTAINER(align), location_entry_->widget()); gtk_container_add(GTK_CONTAINER(align), location_entry_->widget());
gtk_box_pack_start(GTK_BOX(hbox_.get()), align, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_.get()), align, TRUE, TRUE, 0);
...@@ -223,13 +205,7 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { ...@@ -223,13 +205,7 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
// Pack info_label_ and security icons in hbox. We hide/show them // Pack info_label_ and security icons in hbox. We hide/show them
// by SetSecurityIcon() and SetInfoText(). // by SetSecurityIcon() and SetInfoText().
info_label_align_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); gtk_box_pack_end(GTK_BOX(hbox_.get()), info_label_, FALSE, FALSE, 0);
gtk_alignment_set_padding(GTK_ALIGNMENT(info_label_align_),
kTopMargin + kBorderThickness,
kBottomMargin + kBorderThickness,
0, kEvTextPaddingRight);
gtk_container_add(GTK_CONTAINER(info_label_align_), info_label_);
gtk_box_pack_end(GTK_BOX(hbox_.get()), info_label_align_, FALSE, FALSE, 0);
GtkWidget* security_icon_box = gtk_hbox_new(FALSE, 0); GtkWidget* security_icon_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(security_icon_box), gtk_box_pack_start(GTK_BOX(security_icon_box),
...@@ -237,23 +213,18 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { ...@@ -237,23 +213,18 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
gtk_box_pack_start(GTK_BOX(security_icon_box), gtk_box_pack_start(GTK_BOX(security_icon_box),
security_warning_icon_image_, FALSE, FALSE, 0); security_warning_icon_image_, FALSE, FALSE, 0);
security_icon_align_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
gtk_alignment_set_padding(GTK_ALIGNMENT(security_icon_align_),
kTopMargin + kBorderThickness,
kBottomMargin + kBorderThickness,
kSecurityIconPaddingLeft,
kSecurityIconPaddingRight);
// GtkImage is a "no window" widget and requires a GtkEventBox to receive // GtkImage is a "no window" widget and requires a GtkEventBox to receive
// events. // events.
GtkWidget* event_box = gtk_event_box_new(); security_icon_event_box_ = gtk_event_box_new();
// Make the event box not visible so it does not paint a background. // Make the event box not visible so it does not paint a background.
gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE); gtk_event_box_set_visible_window(GTK_EVENT_BOX(security_icon_event_box_),
g_signal_connect(event_box, "button-press-event", FALSE);
g_signal_connect(security_icon_event_box_, "button-press-event",
G_CALLBACK(&OnSecurityIconPressed), this); G_CALLBACK(&OnSecurityIconPressed), this);
gtk_container_add(GTK_CONTAINER(event_box), security_icon_box); gtk_container_add(GTK_CONTAINER(security_icon_event_box_), security_icon_box);
gtk_container_add(GTK_CONTAINER(security_icon_align_), event_box); gtk_box_pack_end(GTK_BOX(hbox_.get()), security_icon_event_box_,
gtk_box_pack_end(GTK_BOX(hbox_.get()), security_icon_align_, FALSE, FALSE, 0); FALSE, FALSE, 0);
registrar_.Add(this, registrar_.Add(this,
NotificationType::BROWSER_THEME_CHANGED, NotificationType::BROWSER_THEME_CHANGED,
...@@ -323,9 +294,9 @@ void LocationBarViewGtk::OnChanged() { ...@@ -323,9 +294,9 @@ void LocationBarViewGtk::OnChanged() {
if (show_selected_keyword) { if (show_selected_keyword) {
SetKeywordLabel(keyword); SetKeywordLabel(keyword);
gtk_widget_show_all(tab_to_search_); gtk_widget_show_all(tab_to_search_box_);
} else { } else {
gtk_widget_hide_all(tab_to_search_); gtk_widget_hide_all(tab_to_search_box_);
} }
if (show_keyword_hint) { if (show_keyword_hint) {
...@@ -510,9 +481,9 @@ void LocationBarViewGtk::SetSecurityIcon(ToolbarModel::Icon icon) { ...@@ -510,9 +481,9 @@ void LocationBarViewGtk::SetSecurityIcon(ToolbarModel::Icon icon) {
gtk_widget_hide(GTK_WIDGET(security_lock_icon_image_)); gtk_widget_hide(GTK_WIDGET(security_lock_icon_image_));
gtk_widget_hide(GTK_WIDGET(security_warning_icon_image_)); gtk_widget_hide(GTK_WIDGET(security_warning_icon_image_));
if (icon != ToolbarModel::NO_ICON) if (icon != ToolbarModel::NO_ICON)
gtk_widget_show(GTK_WIDGET(security_icon_align_)); gtk_widget_show(GTK_WIDGET(security_icon_event_box_));
else else
gtk_widget_hide(GTK_WIDGET(security_icon_align_)); gtk_widget_hide(GTK_WIDGET(security_icon_event_box_));
switch (icon) { switch (icon) {
case ToolbarModel::LOCK_ICON: case ToolbarModel::LOCK_ICON:
gtk_widget_show(GTK_WIDGET(security_lock_icon_image_)); gtk_widget_show(GTK_WIDGET(security_lock_icon_image_));
...@@ -535,12 +506,12 @@ void LocationBarViewGtk::SetInfoText() { ...@@ -535,12 +506,12 @@ void LocationBarViewGtk::SetInfoText() {
if (info_text_type == ToolbarModel::INFO_EV_TEXT) { if (info_text_type == ToolbarModel::INFO_EV_TEXT) {
gtk_widget_modify_fg(GTK_WIDGET(info_label_), GTK_STATE_NORMAL, gtk_widget_modify_fg(GTK_WIDGET(info_label_), GTK_STATE_NORMAL,
&kEvTextColor); &kEvTextColor);
gtk_widget_show(GTK_WIDGET(info_label_align_)); gtk_widget_show(GTK_WIDGET(info_label_));
} else { } else {
DCHECK_EQ(info_text_type, ToolbarModel::INFO_NO_INFO); DCHECK_EQ(info_text_type, ToolbarModel::INFO_NO_INFO);
DCHECK(info_text.empty()); DCHECK(info_text.empty());
// Clear info_text. Should we reset the fg here? // Clear info_text. Should we reset the fg here?
gtk_widget_hide(GTK_WIDGET(info_label_align_)); gtk_widget_hide(GTK_WIDGET(info_label_));
} }
gtk_label_set_text(GTK_LABEL(info_label_), WideToUTF8(info_text).c_str()); gtk_label_set_text(GTK_LABEL(info_label_), WideToUTF8(info_text).c_str());
gtk_widget_set_tooltip_text(GTK_WIDGET(info_label_), gtk_widget_set_tooltip_text(GTK_WIDGET(info_label_),
......
...@@ -123,15 +123,13 @@ class LocationBarViewGtk : public AutocompleteEditController, ...@@ -123,15 +123,13 @@ class LocationBarViewGtk : public AutocompleteEditController,
OwnedWidgetGtk hbox_; OwnedWidgetGtk hbox_;
// SSL icons. // SSL icons.
GtkWidget* security_icon_align_; GtkWidget* security_icon_event_box_;
GtkWidget* security_lock_icon_image_; GtkWidget* security_lock_icon_image_;
GtkWidget* security_warning_icon_image_; GtkWidget* security_warning_icon_image_;
// Toolbar info text (EV cert info). // Toolbar info text (EV cert info).
GtkWidget* info_label_align_;
GtkWidget* info_label_; GtkWidget* info_label_;
// Area on the left shown when in tab to search mode. // Area on the left shown when in tab to search mode.
GtkWidget* tab_to_search_;
GtkWidget* tab_to_search_box_; GtkWidget* tab_to_search_box_;
GtkWidget* tab_to_search_label_; GtkWidget* tab_to_search_label_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment