diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 23:36:06 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 23:36:06 +0000 |
commit | 1c4f28f1b6d4cb4e1b0e5a655067271494dc5cbf (patch) | |
tree | c0d73438b46862d0274841c08744e7d78c41c694 /ui | |
parent | d1136ca7224f43ac51bb5f87945af93a5679b7a0 (diff) | |
download | chromium_src-1c4f28f1b6d4cb4e1b0e5a655067271494dc5cbf.zip chromium_src-1c4f28f1b6d4cb4e1b0e5a655067271494dc5cbf.tar.gz chromium_src-1c4f28f1b6d4cb4e1b0e5a655067271494dc5cbf.tar.bz2 |
Fix Views LabelButton centered multi-line label width.
Labels do not elide multi-line text correctly.
I've added a TODO there and will follow up.
BUG=155363
TEST=Centered LabelButtons with images and multi-line text look better; no eliding regressions. (see views examples)
R=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11190058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/controls/button/label_button.cc | 15 | ||||
-rw-r--r-- | ui/views/controls/label.cc | 1 |
2 files changed, 6 insertions, 10 deletions
diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc index 75e6c4f..a408240 100644 --- a/ui/views/controls/button/label_button.cc +++ b/ui/views/controls/button/label_button.cc @@ -45,7 +45,6 @@ LabelButton::LabelButton(ButtonListener* listener, const string16& text) AddChildView(label_); label_->SetAutoColorReadabilityEnabled(false); label_->SetHorizontalAlignment(Label::ALIGN_LEFT); - label_->SetElideBehavior(Label::ELIDE_AT_END); // Initialize the colors, border, and layout for a Views-themed button. SetNativeTheme(false); @@ -143,9 +142,6 @@ void LabelButton::StateChanged() { gfx::Size LabelButton::GetPreferredSize() { gfx::Size size(label_->GetPreferredSize()); - // TODO(msw): Multi-line labels are cut off at their preferred bounds. - // This apparent bug in CanvasSkia requires investigation. - size.set_width(size.width() * (GetTextMultiLine() ? 2 : 1)); const gfx::Size image_size(image_->GetPreferredSize()); if (image_size.width() > 0 && size.width() > 0) size.Enlarge(kSpacing, 0); @@ -173,16 +169,15 @@ void LabelButton::Layout() { image_size.set_width(std::min(image_size.width(), child_area.width())); image_size.set_height(std::min(image_size.height(), child_area.height())); - // The label takes any remaining width after sizing the image. + // The label takes any remaining width after sizing the image, unless both + // views are centered. In that case, using the tighter preferred label width + // avoids wasted space within the label that would look like awkward padding. gfx::Size label_size(child_area.size()); if (!image_size.IsEmpty() && !label_size.IsEmpty()) { label_size.set_width(child_area.width() - image_size.width() - kSpacing); if (GetHorizontalAlignment() == Label::ALIGN_CENTER) { - gfx::Size preferred(label_->GetPreferredSize()); - // TODO(msw): Multi-line labels are cut off at their preferred bounds. - // This apparent bug in CanvasSkia requires investigation. - preferred.set_width(preferred.width() * (GetTextMultiLine() ? 2 : 1)); - label_size.set_width(std::min(label_size.width(), preferred.width())); + label_size.set_width(std::min(label_size.width(), + label_->GetPreferredSize().width())); } } diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc index a9a9abe..f4af0a2 100644 --- a/ui/views/controls/label.cc +++ b/ui/views/controls/label.cc @@ -480,6 +480,7 @@ void Label::CalculateDrawStringParams(string16* paint_text, int* flags) const { DCHECK(paint_text && text_bounds && flags); + // TODO(msw): Use ElideRectangleText to support eliding multi-line text. if (is_email_) { *paint_text = ui::ElideEmail(text_, font_, GetAvailableRect().width()); } else if (elide_behavior_ == ELIDE_IN_MIDDLE) { |