From b7878ad5af389c084b09c270bf774aa73b238125 Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Fri, 4 Dec 2009 23:32:04 +0000 Subject: Fixes bug in textfield on views/gtk where we weren't properly accounting for border size if not specified by style. Also changes button on views/gtk not to fix the pref height at 29. There is no reason for us to do this. BUG=none TEST=none Review URL: http://codereview.chromium.org/462036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33882 0039d316-1c4b-4281-b951-d872f2087c98 --- views/controls/button/native_button_gtk.cc | 3 +- views/controls/textfield/native_textfield_gtk.cc | 41 +++++++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'views') diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc index e663db6..317e6bd 100644 --- a/views/controls/button/native_button_gtk.cc +++ b/views/controls/button/native_button_gtk.cc @@ -88,8 +88,7 @@ gfx::Size NativeButtonGtk::GetPreferredSize() { if (preferred_size_.IsEmpty()) { GtkRequisition size_request = { 0, 0 }; gtk_widget_size_request(native_view(), &size_request); - preferred_size_.SetSize(size_request.width, - std::max(size_request.height, 29)); + preferred_size_.SetSize(size_request.width, size_request.height); } return preferred_size_; } diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index 9728a1d..026a6b7 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -6,6 +6,7 @@ #include "views/controls/textfield/native_textfield_gtk.h" +#include "app/gfx/insets.h" #include "app/gfx/gtk_util.h" #include "base/string_util.h" #include "skia/ext/skia_utils_gtk.h" @@ -139,23 +140,29 @@ gfx::Insets NativeTextfieldGtk::CalculateInsets() { GtkWidget* widget = native_view(); GtkEntry* entry = GTK_ENTRY(widget); - const GtkBorder* inner_border = gtk_entry_get_inner_border(entry); - int left = 0, right = 0, top = 0, bottom = 0; - if (!inner_border) - gtk_widget_style_get(widget, "inner-border", &inner_border, NULL); + gfx::Insets insets; + const GtkBorder* inner_border = gtk_entry_get_inner_border(entry); if (inner_border) { - left += inner_border->left; - right += inner_border->right; - top += inner_border->top; - bottom += inner_border->bottom; + insets += gfx::Insets(*inner_border); + } else { + // No explicit border set, try the style. + GtkBorder* style_border; + gtk_widget_style_get(widget, "inner-border", &style_border, NULL); + if (style_border) { + insets += gfx::Insets(*style_border); + gtk_border_free(style_border); + } else { + // If border is null, Gtk uses 2 on all sides. + insets += gfx::Insets(2, 2, 2, 2); + } } if (entry->has_frame) { - left += widget->style->xthickness; - right += widget->style->xthickness; - top += widget->style->ythickness; - bottom += widget->style->ythickness; + insets += gfx::Insets(widget->style->ythickness, + widget->style->xthickness, + widget->style->ythickness, + widget->style->xthickness); } gboolean interior_focus; @@ -164,14 +171,10 @@ gfx::Insets NativeTextfieldGtk::CalculateInsets() { "focus-line-width", &focus_width, "interior-focus", &interior_focus, NULL); - if (!interior_focus) { - left += focus_width; - right += focus_width; - top += focus_width; - bottom += focus_width; - } + if (!interior_focus) + insets += gfx::Insets(focus_width, focus_width, focus_width, focus_width); - return gfx::Insets(top, left, bottom, right); + return insets; } void NativeTextfieldGtk::SetHorizontalMargins(int left, int right) { -- cgit v1.1