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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (width == 0 || lines == 0) | 106 if (width == 0 || lines == 0) |
107 return gfx::Size(); | 107 return gfx::Size(); |
108 std::pair<int, int> key(width, lines); | 108 std::pair<int, int> key(width, lines); |
109 gfx::Size size = GetCachedSize(key); | 109 gfx::Size size = GetCachedSize(key); |
110 if (size.height() == std::numeric_limits<int>::max()) { | 110 if (size.height() == std::numeric_limits<int>::max()) { |
111 gfx::Insets insets = owner_->GetInsets(); | 111 gfx::Insets insets = owner_->GetInsets(); |
112 int text_width = (width < 0) ? std::numeric_limits<int>::max() : | 112 int text_width = (width < 0) ? std::numeric_limits<int>::max() : |
113 std::max(width - insets.width(), 0); | 113 std::max(width - insets.width(), 0); |
114 int text_height = std::numeric_limits<int>::max(); | 114 int text_height = std::numeric_limits<int>::max(); |
115 std::vector<base::string16> wrapped = GetWrappedText(text_width, lines); | 115 std::vector<base::string16> wrapped = GetWrappedText(text_width, lines); |
116 gfx::Canvas::SizeStringInt(JoinString(wrapped, '\n'), font_list(), | 116 gfx::Canvas::SizeStringInt( |
117 &text_width, &text_height, | 117 base::JoinString(wrapped, base::ASCIIToUTF16("\n")), |
118 owner_->GetLineHeight(), | 118 font_list(), &text_width, &text_height, owner_->GetLineHeight(), |
119 GetTextFlags()); | 119 GetTextFlags()); |
120 size.set_width(text_width + insets.width()); | 120 size.set_width(text_width + insets.width()); |
121 size.set_height(text_height + insets.height()); | 121 size.set_height(text_height + insets.height()); |
122 SetCachedSize(key, size); | 122 SetCachedSize(key, size); |
123 } | 123 } |
124 return size; | 124 return size; |
125 } | 125 } |
126 | 126 |
127 std::vector<base::string16> InnerBoundedLabel::GetWrappedText(int width, | 127 std::vector<base::string16> InnerBoundedLabel::GetWrappedText(int width, |
128 int lines) { | 128 int lines) { |
129 // Short circuit simple case. | 129 // Short circuit simple case. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 void InnerBoundedLabel::OnPaint(gfx::Canvas* canvas) { | 171 void InnerBoundedLabel::OnPaint(gfx::Canvas* canvas) { |
172 views::Label::OnPaintBackground(canvas); | 172 views::Label::OnPaintBackground(canvas); |
173 views::Label::OnPaintBorder(canvas); | 173 views::Label::OnPaintBorder(canvas); |
174 int lines = owner_->GetLineLimit(); | 174 int lines = owner_->GetLineLimit(); |
175 int height = GetSizeForWidthAndLines(width(), lines).height(); | 175 int height = GetSizeForWidthAndLines(width(), lines).height(); |
176 if (height > 0) { | 176 if (height > 0) { |
177 gfx::Rect bounds(width(), height); | 177 gfx::Rect bounds(width(), height); |
178 bounds.Inset(owner_->GetInsets()); | 178 bounds.Inset(owner_->GetInsets()); |
179 if (bounds.width() != wrapped_text_width_ || lines != wrapped_text_lines_) { | 179 if (bounds.width() != wrapped_text_width_ || lines != wrapped_text_lines_) { |
180 wrapped_text_ = JoinString(GetWrappedText(bounds.width(), lines), '\n'); | 180 wrapped_text_ = base::JoinString(GetWrappedText(bounds.width(), lines), |
| 181 base::ASCIIToUTF16("\n")); |
181 wrapped_text_width_ = bounds.width(); | 182 wrapped_text_width_ = bounds.width(); |
182 wrapped_text_lines_ = lines; | 183 wrapped_text_lines_ = lines; |
183 } | 184 } |
184 bounds.set_x(GetMirroredXForRect(bounds)); | 185 bounds.set_x(GetMirroredXForRect(bounds)); |
185 canvas->DrawStringRectWithFlags( | 186 canvas->DrawStringRectWithFlags( |
186 wrapped_text_, font_list(), enabled_color(), bounds, GetTextFlags()); | 187 wrapped_text_, font_list(), enabled_color(), bounds, GetTextFlags()); |
187 } | 188 } |
188 } | 189 } |
189 | 190 |
190 void InnerBoundedLabel::SetText(const base::string16& new_text) { | 191 void InnerBoundedLabel::SetText(const base::string16& new_text) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 void BoundedLabel::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 337 void BoundedLabel::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
337 label_->SetBoundsRect(bounds()); | 338 label_->SetBoundsRect(bounds()); |
338 views::View::OnBoundsChanged(previous_bounds); | 339 views::View::OnBoundsChanged(previous_bounds); |
339 } | 340 } |
340 | 341 |
341 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 342 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
342 label_->SetNativeTheme(theme); | 343 label_->SetNativeTheme(theme); |
343 } | 344 } |
344 | 345 |
345 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { | 346 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { |
346 return JoinString(label_->GetWrappedText(width, lines), '\n'); | 347 return base::JoinString(label_->GetWrappedText(width, lines), |
| 348 base::ASCIIToUTF16("\n")); |
347 } | 349 } |
348 | 350 |
349 } // namespace message_center | 351 } // namespace message_center |
OLD | NEW |