From 0209eacee2b017cf5bd3aa9cf01153bae7c5db3e Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Wed, 24 Mar 2010 20:45:17 +0000 Subject: Fix regression from Label fixes -- I forgot to make GetHeightForWidth() actually care about the provided width for multi-line text. Oops. BUG=39104 TEST=About box should not be inordinately large Review URL: http://codereview.chromium.org/1293003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42527 0039d316-1c4b-4281-b951-d872f2087c98 --- views/controls/label.cc | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'views') diff --git a/views/controls/label.cc b/views/controls/label.cc index 3a21509..f73740e 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -4,8 +4,7 @@ #include "views/controls/label.h" -#include -#include +#include #include "app/l10n_util.h" #include "app/resource_bundle.h" @@ -62,9 +61,13 @@ int Label::GetBaseline() { } int Label::GetHeightForWidth(int w) { - return is_multi_line_ ? - (GetTextSize().height() + GetInsets().height()) : - View::GetHeightForWidth(w); + if (!is_multi_line_) + return View::GetHeightForWidth(w); + + w = std::max(0, w - GetInsets().width()); + int h = font_.height(); + gfx::Canvas::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); + return h + GetInsets().height(); } void Label::DidChangeBounds(const gfx::Rect& previous, @@ -371,10 +374,14 @@ gfx::Rect Label::GetTextBounds() const { gfx::Size Label::GetTextSize() const { if (!text_size_valid_) { - int w = is_multi_line_ ? - GetAvailableRect().width() : std::numeric_limits::max(); + int w = GetAvailableRect().width(); int h = font_.height(); - gfx::Canvas::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); + // For single-line strings, ignore the available width and calculate how + // wide the text wants to be. + int flags = ComputeMultiLineFlags(); + if (!is_multi_line_) + flags |= gfx::Canvas::NO_ELLIPSIS; + gfx::Canvas::SizeStringInt(text_, font_, &w, &h, flags); text_size_.SetSize(w, h); text_size_valid_ = true; } @@ -388,10 +395,10 @@ int Label::ComputeMultiLineFlags() const { int flags = gfx::Canvas::MULTI_LINE; #if !defined(OS_WIN) - // Don't ellide multiline labels on Linux. - // Todo(davemoore): Do we depend on elliding multiline text? + // Don't elide multiline labels on Linux. + // Todo(davemoore): Do we depend on eliding multiline text? // Pango insists on limiting the number of lines to one if text is - // ellided. You can get around this if you can pass a maximum height + // elided. You can get around this if you can pass a maximum height // but we don't currently have that data when we call the pango code. flags |= gfx::Canvas::NO_ELLIPSIS; #endif -- cgit v1.1