Commit 4672257a authored by mukai's avatar mukai Committed by Commit bot

Do not break lines when width is not specified.

In case SetAllowCharacterBreak(true) is specified but width is not
specified yet, nobody can stop gfx::ElideRectangleText() to wrap
the text at very narrow width. But when the width is not specified,
the ideal lines is expected (so that the label can be layouted
based on the size).

BUG=469559
R=sky@chromium.org
TEST=the new test case covers

Review URL: https://codereview.chromium.org/1029593004

Cr-Commit-Position: refs/heads/master@{#321854}
parent 57c88499
......@@ -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;
}
......
......@@ -358,6 +358,17 @@ TEST_F(LabelTest, MultilineSmallAvailableWidthSizing) {
EXPECT_GT(label.GetHeightForWidth(i), 0);
}
// Verifies if SetAllowCharacterBreak(true) doesn't change the preferred size.
// See crbug.com/469559
TEST_F(LabelTest, PreferredSizeForAllowCharacterBreak) {
Label label(base::ASCIIToUTF16("Example"));
gfx::Size preferred_size = label.GetPreferredSize();
label.SetMultiLine(true);
label.SetAllowCharacterBreak(true);
EXPECT_EQ(preferred_size, label.GetPreferredSize());
}
TEST_F(LabelTest, MultiLineSizing) {
Label label;
label.SetFocusable(false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment