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

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

Issue 1140083002: Make StyledLabel wrap long words (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests Created 5 years, 7 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
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..a4c34b568e354f8c741b0ef0cce4a9223c989744 100644
--- a/ui/views/controls/styled_label.cc
+++ b/ui/views/controls/styled_label.cc
@@ -281,12 +281,10 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
text_font_list,
chunk_bounds.width(),
chunk_bounds.height(),
- gfx::IGNORE_LONG_WORDS,
+ gfx::WRAP_LONG_WORDS,
&substrings);
- DCHECK(!substrings.empty());
- base::string16 chunk = substrings[0];
- if (chunk.empty()) {
+ 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
@@ -305,6 +303,8 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
continue;
}
+ base::string16 chunk = substrings[0];
+
scoped_ptr<Label> label;
if (position >= range.start()) {
const RangeStyleInfo& style_info = current_range->style_info;
@@ -318,7 +318,8 @@ 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)
+ chunk = chunk.substr(0, range.end() - position);
label = CreateLabelRange(chunk, font_list_, style_info, this);
@@ -354,6 +355,16 @@ 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 |gfx::ElideRectangleText| returned more than one substring, that
+ // means the whole text did not fit into remaining line width, with text
+ // after |susbtring[0]| spilling into next line. If whole |substring[0]|
+ // was added to the current line (this may not be the case if part of the
+ // substring has different style), proceed to the next line.
+ if (substrings.size() > 1 && chunk.size() == substrings[0].size()) {
+ x = 0;
+ ++line;
+ }
+
remaining_string = remaining_string.substr(chunk.size());
}
« no previous file with comments | « no previous file | ui/views/controls/styled_label_unittest.cc » ('j') | ui/views/controls/styled_label_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698