Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(747)

Unified Diff: ui/views/controls/label.cc

Issue 1029593004: Do not break lines when width is not specified. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/label.cc
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc
index 3d0cf30192cb2c64104f535e1dbf4f5aa824624b..e627c7afc8ae30b3b8e52625da230b09103c0669 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -499,10 +499,17 @@ gfx::Rect Label::GetFocusBounds() {
std::vector<base::string16> Label::GetLinesForWidth(int width) const {
std::vector<base::string16> lines;
- const gfx::WordWrapBehavior wrap =
- allow_character_break_ ? gfx::WRAP_LONG_WORDS : gfx::TRUNCATE_LONG_WORDS;
- gfx::ElideRectangleText(render_text_->GetDisplayText(), font_list(), width,
- std::numeric_limits<int>::max(), wrap, &lines);
+ // |width| can be 0 when getting the default text size, in that case
+ // the ideal lines (i.e. broken at newline characters) are wanted.
+ if (width <= 0) {
+ base::SplitString(render_text_->GetDisplayText(), '\n', &lines);
+ } else {
+ const gfx::WordWrapBehavior wrap = allow_character_break_
+ ? gfx::WRAP_LONG_WORDS
+ : gfx::TRUNCATE_LONG_WORDS;
+ gfx::ElideRectangleText(render_text_->GetDisplayText(), font_list(), width,
+ std::numeric_limits<int>::max(), wrap, &lines);
+ }
return lines;
}
« no previous file with comments | « no previous file | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698