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

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

Issue 1015533016: Move allow_character_break property to RenderText. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test fix Created 5 years, 9 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
« ui/gfx/text_constants.h ('K') | « ui/views/controls/label.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/label.cc
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc
index e627c7afc8ae30b3b8e52625da230b09103c0669..cff72612a978a5295da8e7fbd189b1286915d5b9 100644
--- a/ui/views/controls/label.cc
+++ b/ui/views/controls/label.cc
@@ -150,10 +150,12 @@ void Label::SetObscured(bool obscured) {
}
void Label::SetAllowCharacterBreak(bool allow_character_break) {
- if (allow_character_break_ == allow_character_break)
+ const gfx::WordWrapBehavior behavior =
+ allow_character_break ? gfx::WRAP_LONG_WORDS : gfx::TRUNCATE_LONG_WORDS;
+ if (render_text_->word_wrap_behavior() == behavior)
return;
is_first_paint_text_ = true;
- allow_character_break_ = allow_character_break;
+ render_text_->SetWordWrapBehavior(behavior);
ResetLayout();
msw 2015/03/26 19:36:30 nit: perhaps the layout shouldn't be reset (nor sh
Jun Mukai 2015/03/26 22:47:39 Done.
}
@@ -258,9 +260,7 @@ int Label::GetHeightForWidth(int w) const {
return std::max(line_height(), font_list().GetHeight());
int height = 0;
- // RenderText doesn't support character breaks.
- // TODO(mukai): remove this restriction.
- if (render_text_->MultilineSupported() && !allow_character_break_) {
+ if (render_text_->MultilineSupported()) {
// SetDisplayRect() has a side effect for later calls of GetStringSize().
// Be careful to invoke |render_text_->SetDisplayRect(gfx::Rect())| to
// cancel this effect before the next time GetStringSize() is called.
@@ -384,6 +384,7 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
render_text_->SetElideBehavior(gfx::NO_ELIDE);
render_text_->SetFontList(font_list);
render_text_->SetCursorEnabled(false);
+ render_text_->SetWordWrapBehavior(gfx::TRUNCATE_LONG_WORDS);
elide_behavior_ = gfx::ELIDE_TAIL;
enabled_color_set_ = disabled_color_set_ = background_color_set_ = false;
@@ -393,7 +394,6 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
UpdateColorsFromTheme(ui::NativeTheme::instance());
handles_tooltips_ = true;
collapse_when_hidden_ = false;
- allow_character_break_ = false;
max_width_ = 0;
is_first_paint_text_ = true;
SetText(text);
@@ -451,12 +451,12 @@ void Label::MaybeBuildRenderTextLines() {
// TODO(mukai): Add multi-lined elided text support.
gfx::ElideBehavior elide_behavior =
multi_line() ? gfx::NO_ELIDE : elide_behavior_;
- if (!multi_line() ||
- (render_text_->MultilineSupported() && !allow_character_break_)) {
+ if (!multi_line() || render_text_->MultilineSupported()) {
scoped_ptr<gfx::RenderText> render_text =
CreateRenderText(text(), alignment, directionality, elide_behavior);
render_text->SetDisplayRect(rect);
render_text->SetMultiline(multi_line());
+ render_text->SetWordWrapBehavior(render_text_->word_wrap_behavior());
lines_.push_back(render_text.release());
} else {
std::vector<base::string16> lines = GetLinesForWidth(rect.width());
@@ -504,11 +504,9 @@ std::vector<base::string16> Label::GetLinesForWidth(int width) const {
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);
+ std::numeric_limits<int>::max(),
+ render_text_->word_wrap_behavior(), &lines);
}
return lines;
}
@@ -517,8 +515,7 @@ gfx::Size Label::GetTextSize() const {
gfx::Size size;
if (text().empty()) {
size = gfx::Size(0, std::max(line_height(), font_list().GetHeight()));
- } else if (!multi_line() ||
- (render_text_->MultilineSupported() && !allow_character_break_)) {
+ } else if (!multi_line() || render_text_->MultilineSupported()) {
// Cancel the display rect of |render_text_|. The display rect may be
// specified in GetHeightForWidth(), and specifying empty Rect cancels
// its effect. See also the comment in GetHeightForWidth().
« ui/gfx/text_constants.h ('K') | « ui/views/controls/label.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698