Chromium Code Reviews| Index: ui/views/controls/styled_label.cc |
| diff --git a/ui/views/controls/styled_label.cc b/ui/views/controls/styled_label.cc |
| index 6c9ff2c522a8c53aa16b9d31bcee099bd908db7c..8d6f6a7225949557962974c7287f8b0833220eec 100644 |
| --- a/ui/views/controls/styled_label.cc |
| +++ b/ui/views/controls/styled_label.cc |
| @@ -281,11 +281,11 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| text_font_list, |
| chunk_bounds.width(), |
| chunk_bounds.height(), |
| - gfx::IGNORE_LONG_WORDS, |
| + gfx::TRUNCATE_LONG_WORDS, |
|
msw
2015/05/13 23:05:39
Why doesn't this use WRAP_LONG_WORDS?
tbarzic
2015/05/14 00:02:28
WRAP_LONG_WORDS didn't work in first patch because
|
| &substrings); |
| - DCHECK(!substrings.empty()); |
| - base::string16 chunk = substrings[0]; |
| + base::string16 chunk = |
| + substrings.empty() ? base::string16() : substrings[0]; |
| if (chunk.empty()) { |
|
msw
2015/05/13 23:05:39
nit: declare/assign |chunk| below this block and c
tbarzic
2015/05/14 00:02:28
Done.
|
| // Nothing fits on this line. Start a new line. |
| // If x is 0, first line may have leading whitespace that doesn't fit in a |
| @@ -306,6 +306,7 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| } |
| scoped_ptr<Label> label; |
| + bool whole_chunk_used = true; |
| if (position >= range.start()) { |
| const RangeStyleInfo& style_info = current_range->style_info; |
| @@ -318,7 +319,10 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| continue; |
| } |
| - chunk = chunk.substr(0, std::min(chunk.size(), range.end() - position)); |
| + if (chunk.size() > range.end() - position) { |
| + whole_chunk_used = false; |
| + chunk = chunk.substr(0, range.end() - position); |
| + } |
| label = CreateLabelRange(chunk, font_list_, style_info, this); |
| @@ -329,8 +333,10 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| ++current_range; |
| } else { |
| // This chunk is normal text. |
| - if (position + chunk.size() > range.start()) |
| + if (position + chunk.size() > range.start()) { |
| + whole_chunk_used = false; |
| chunk = chunk.substr(0, range.start() - position); |
| + } |
| label = CreateLabelRange(chunk, font_list_, default_style_info_, this); |
| } |
| @@ -354,6 +360,11 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| x += view_size.width() - focus_border_insets.width(); |
| used_width = std::max(used_width, x); |
| + if (substrings.size() > 1 && whole_chunk_used) { |
|
msw
2015/05/13 23:05:39
I don't think you need |whole_chunk_used|, can you
tbarzic
2015/05/14 00:02:28
Done.
|
| + x = 0; |
| + ++line; |
| + } |
| + |
| remaining_string = remaining_string.substr(chunk.size()); |
| } |