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

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

Issue 2348433002: Make styled-label trimming less agressive, allowing whitespace (Closed)
Patch Set: Code style fixes - part 2 Created 4 years 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 | « components/autofill/core/browser/legal_message_line.h ('k') | ui/views/controls/styled_label_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « components/autofill/core/browser/legal_message_line.h ('k') | ui/views/controls/styled_label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698