diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 20:45:17 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 20:45:17 +0000 |
commit | 0209eacee2b017cf5bd3aa9cf01153bae7c5db3e (patch) | |
tree | 582597a228454e496a7b93072da6914ef46e8f6a /views | |
parent | a0b180896694d3e5ff73b3cacad3d0593840703a (diff) | |
download | chromium_src-0209eacee2b017cf5bd3aa9cf01153bae7c5db3e.zip chromium_src-0209eacee2b017cf5bd3aa9cf01153bae7c5db3e.tar.gz chromium_src-0209eacee2b017cf5bd3aa9cf01153bae7c5db3e.tar.bz2 |
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
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/label.cc | 29 |
1 files changed, 18 insertions, 11 deletions
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 <math.h> -#include <limits> +#include <cmath> #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<int>::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 |