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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // use it to calculate a reasonable text height. | 131 // use it to calculate a reasonable text height. |
132 int height = std::numeric_limits<int>::max(); | 132 int height = std::numeric_limits<int>::max(); |
133 if (lines > 0) { | 133 if (lines > 0) { |
134 int line_height = std::max(font_list().GetHeight(), | 134 int line_height = std::max(font_list().GetHeight(), |
135 2); // At least 2 pixels. | 135 2); // At least 2 pixels. |
136 int max_lines = std::numeric_limits<int>::max() / line_height - 1; | 136 int max_lines = std::numeric_limits<int>::max() / line_height - 1; |
137 lines = std::min(lines, max_lines); | 137 lines = std::min(lines, max_lines); |
138 height = (lines + 1) * line_height; | 138 height = (lines + 1) * line_height; |
139 } | 139 } |
140 | 140 |
141 // Try to ensure that the width is no smaller than the width of the text's | |
142 // characters to avoid the http://crbug.com/237700 infinite loop. | |
143 // TODO(dharcourt): Remove when http://crbug.com/237700 is fixed. | |
144 width = std::max(width, | |
145 2 * gfx::GetStringWidth(base::UTF8ToUTF16("W"), | |
146 font_list())); | |
147 | |
148 // Wrap, using INT_MAX for -1 widths that indicate no wrapping. | 141 // Wrap, using INT_MAX for -1 widths that indicate no wrapping. |
149 std::vector<base::string16> wrapped; | 142 std::vector<base::string16> wrapped; |
150 gfx::ElideRectangleText(text(), font_list(), | 143 gfx::ElideRectangleText(text(), font_list(), |
151 (width < 0) ? std::numeric_limits<int>::max() : width, | 144 (width < 0) ? std::numeric_limits<int>::max() : width, |
152 height, gfx::WRAP_LONG_WORDS, &wrapped); | 145 height, gfx::WRAP_LONG_WORDS, &wrapped); |
153 | 146 |
154 // Elide if necessary. | 147 // Elide if necessary. |
155 if (lines > 0 && wrapped.size() > static_cast<unsigned int>(lines)) { | 148 if (lines > 0 && wrapped.size() > static_cast<unsigned int>(lines)) { |
156 // Add an ellipsis to the last line. If this ellipsis makes the last line | 149 // Add an ellipsis to the last line. If this ellipsis makes the last line |
157 // too wide, that line will be further elided by the gfx::ElideText below, | 150 // too wide, that line will be further elided by the gfx::ElideText below, |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 336 |
344 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 337 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
345 label_->SetNativeTheme(theme); | 338 label_->SetNativeTheme(theme); |
346 } | 339 } |
347 | 340 |
348 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { | 341 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { |
349 return JoinString(label_->GetWrappedText(width, lines), '\n'); | 342 return JoinString(label_->GetWrappedText(width, lines), '\n'); |
350 } | 343 } |
351 | 344 |
352 } // namespace message_center | 345 } // namespace message_center |
OLD | NEW |