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 1b4cf1c93aaa038342e0949d9ce75ff1a78478d3..604c95fad213ad6b111cf11f700831c0cf798d8a 100644 |
| --- a/ui/views/controls/styled_label.cc |
| +++ b/ui/views/controls/styled_label.cc |
| @@ -259,11 +259,17 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| // Iterate over the text, creating a bunch of labels and links and laying them |
| // out in the appropriate positions. |
| while (!remaining_string.empty()) { |
| - // Don't put whitespace at beginning of a line with an exception for the |
| - // first line (so the text's leading whitespace is respected). |
| if (x == 0 && line > 0) { |
| - base::TrimWhitespace(remaining_string, base::TRIM_LEADING, |
| - &remaining_string); |
| + if (remaining_string.front() == L'\n') { |
| + // Wrapped to the next line on \n, remove it. Other whitespace, |
| + // eg, spaces to indent next line, are preserved. |
| + remaining_string.erase(0, 1); |
| + } else { |
| + // Wrapped on whitespace character or characters in the middle of the |
| + // line - none of them are needed at the beginning of the next line. |
| + base::TrimWhitespace(remaining_string, base::TRIM_LEADING, |
| + &remaining_string); |
| + } |
| } |
| gfx::Range range(gfx::Range::InvalidRange()); |
| @@ -293,19 +299,22 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| if (substrings.empty() || substrings[0].empty()) { |
| // 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 |
| - // single line, so try trimming those. Otherwise there is no room for |
| - // anything; abort. |
| + // single line, so try trimming those. When first remaining char is \n, |
| + // otput it as an empty line. |
| + // Otherwise there is no room for anything; abort. |
|
Evan Stade
2016/12/09 18:41:58
When I rewrite this portion of the function (L299-
|
| if (x == 0) { |
| if (line == 0) { |
| base::TrimWhitespace(remaining_string, base::TRIM_LEADING, |
| &remaining_string); |
| continue; |
| + } else if (remaining_string.empty() || |
| + remaining_string.front() != L'\n') { |
| + break; |
| } |
| - break; |
| } |
| x = 0; |
| - line++; |
| + ++line; |
| continue; |
| } |
| @@ -320,7 +329,7 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| // If the chunk should not be wrapped, try to fit it entirely on the |
| // next line. |
| x = 0; |
| - line++; |
| + ++line; |
| continue; |
| } |