OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/message_center/views/bounded_label.h" | 5 #include "ui/message_center/views/bounded_label.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (lines > 0) { | 136 if (lines > 0) { |
137 int line_height = std::max(font_list().GetHeight(), | 137 int line_height = std::max(font_list().GetHeight(), |
138 2); // At least 2 pixels. | 138 2); // At least 2 pixels. |
139 int max_lines = std::numeric_limits<int>::max() / line_height - 1; | 139 int max_lines = std::numeric_limits<int>::max() / line_height - 1; |
140 lines = std::min(lines, max_lines); | 140 lines = std::min(lines, max_lines); |
141 height = (lines + 1) * line_height; | 141 height = (lines + 1) * line_height; |
142 } | 142 } |
143 | 143 |
144 // Wrap, using INT_MAX for -1 widths that indicate no wrapping. | 144 // Wrap, using INT_MAX for -1 widths that indicate no wrapping. |
145 std::vector<base::string16> wrapped; | 145 std::vector<base::string16> wrapped; |
146 gfx::ElideRectangleText(text(), font_list(), | 146 gfx::ElideRectangleText(text(), |
| 147 font_list(), |
147 (width < 0) ? std::numeric_limits<int>::max() : width, | 148 (width < 0) ? std::numeric_limits<int>::max() : width, |
148 height, gfx::WRAP_LONG_WORDS, &wrapped); | 149 height, |
| 150 gfx::WRAP_LONG_WORDS, |
| 151 &wrapped, |
| 152 nullptr); |
149 | 153 |
150 // Elide if necessary. | 154 // Elide if necessary. |
151 if (lines > 0 && wrapped.size() > static_cast<unsigned int>(lines)) { | 155 if (lines > 0 && wrapped.size() > static_cast<unsigned int>(lines)) { |
152 // Add an ellipsis to the last line. If this ellipsis makes the last line | 156 // Add an ellipsis to the last line. If this ellipsis makes the last line |
153 // too wide, that line will be further elided by the gfx::ElideText below, | 157 // too wide, that line will be further elided by the gfx::ElideText below, |
154 // so for example "ABC" could become "ABC..." and then "AB...". | 158 // so for example "ABC" could become "ABC..." and then "AB...". |
155 base::string16 last = | 159 base::string16 last = |
156 wrapped[lines - 1] + base::UTF8ToUTF16(gfx::kEllipsis); | 160 wrapped[lines - 1] + base::UTF8ToUTF16(gfx::kEllipsis); |
157 if (width > 0 && gfx::GetStringWidth(last, font_list()) > width) | 161 if (width > 0 && gfx::GetStringWidth(last, font_list()) > width) |
158 last = gfx::ElideText(last, font_list(), width, gfx::ELIDE_TAIL); | 162 last = gfx::ElideText(last, font_list(), width, gfx::ELIDE_TAIL); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 347 |
344 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 348 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
345 label_->SetNativeTheme(theme); | 349 label_->SetNativeTheme(theme); |
346 } | 350 } |
347 | 351 |
348 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { | 352 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { |
349 return JoinString(label_->GetWrappedText(width, lines), '\n'); | 353 return JoinString(label_->GetWrappedText(width, lines), '\n'); |
350 } | 354 } |
351 | 355 |
352 } // namespace message_center | 356 } // namespace message_center |
OLD | NEW |