From ba76b0341a80b98b0381f9f3715409cada4a93cb Mon Sep 17 00:00:00 2001 From: "vandebo@chromium.org" Date: Wed, 26 Feb 2014 05:04:23 +0000 Subject: Add ELIDE_AT_BEGINNING to views::Label BUG=NONE Review URL: https://codereview.chromium.org/177843007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253354 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/views/controls/label.cc | 6 +++++- ui/views/controls/label.h | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc index 7729835..f35d119 100644 --- a/ui/views/controls/label.cc +++ b/ui/views/controls/label.cc @@ -130,7 +130,8 @@ void Label::SetLineHeight(int height) { } void Label::SetMultiLine(bool multi_line) { - DCHECK(!multi_line || elide_behavior_ != ELIDE_IN_MIDDLE); + DCHECK(!multi_line || (elide_behavior_ != ELIDE_IN_MIDDLE && + elide_behavior_ != ELIDE_AT_BEGINNING)); if (multi_line != is_multi_line_) { is_multi_line_ = multi_line; ResetCachedSize(); @@ -481,6 +482,9 @@ void Label::CalculateDrawStringParams(base::string16* paint_text, // this is done, we can set NO_ELLIPSIS unconditionally at the bottom. if (is_multi_line_ || (elide_behavior_ == NO_ELIDE)) { *paint_text = text_; + } else if (elide_behavior_ == ELIDE_AT_BEGINNING) { + *paint_text = gfx::ElideText(text_, font_list_, GetAvailableRect().width(), + gfx::ELIDE_AT_BEGINNING); } else if (elide_behavior_ == ELIDE_IN_MIDDLE) { *paint_text = gfx::ElideText(text_, font_list_, GetAvailableRect().width(), gfx::ELIDE_IN_MIDDLE); diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h index 77b18e0..463afac 100644 --- a/ui/views/controls/label.h +++ b/ui/views/controls/label.h @@ -43,10 +43,12 @@ class VIEWS_EXPORT Label : public View { }; enum ElideBehavior { - NO_ELIDE, // Do not elide the label text; truncate as needed. - ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed. - ELIDE_AT_END, // Add ellipsis at the end of the string as needed. - ELIDE_AS_EMAIL, // Elide while retaining username/domain chars as needed. + NO_ELIDE, // Do not elide the label text; truncate as needed. + ELIDE_AT_BEGINNING, // Add ellipsis at the start of the string as needed. + ELIDE_IN_MIDDLE, // Add ellipsis in the middle of the string as needed. + ELIDE_AT_END, // Add ellipsis at the end of the string as needed. + ELIDE_AS_EMAIL, // Elide while retaining username/domain chars + // as needed. }; // Internal class name. -- cgit v1.1