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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_ = JoinString(GetWrappedText(bounds.width(), lines), '\n'); |
181 wrapped_text_width_ = bounds.width(); | 181 wrapped_text_width_ = bounds.width(); |
182 wrapped_text_lines_ = lines; | 182 wrapped_text_lines_ = lines; |
183 } | 183 } |
184 bounds.set_x(GetMirroredXForRect(bounds)); | 184 bounds.set_x(GetMirroredXForRect(bounds)); |
185 PaintText(canvas, wrapped_text_, bounds, GetTextFlags()); | 185 canvas->DrawStringRectWithFlags( |
| 186 wrapped_text_, font_list(), enabled_color(), bounds, GetTextFlags()); |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 void InnerBoundedLabel::SetText(const base::string16& text) { | 190 void InnerBoundedLabel::SetText(const base::string16& text) { |
190 views::Label::SetText(text); | 191 views::Label::SetText(text); |
191 ClearCaches(); | 192 ClearCaches(); |
192 } | 193 } |
193 | 194 |
194 int InnerBoundedLabel::GetTextFlags() { | 195 int InnerBoundedLabel::GetTextFlags() { |
195 int flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::CHARACTER_BREAK; | 196 int flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::CHARACTER_BREAK; |
196 | 197 |
197 // We can't use subpixel rendering if the background is non-opaque. | 198 // We can't use subpixel rendering if the background is non-opaque. |
198 if (SkColorGetA(background_color()) != 0xFF) | 199 if (SkColorGetA(background_color()) != 0xFF) |
199 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; | 200 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; |
200 | 201 |
201 if (directionality_mode() == gfx::DIRECTIONALITY_FORCE_LTR) { | 202 const base::i18n::TextDirection direction = |
202 flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 203 base::i18n::GetFirstStrongCharacterDirection(text()); |
203 } else if (directionality_mode() == gfx::DIRECTIONALITY_FORCE_RTL) { | 204 if (direction == base::i18n::RIGHT_TO_LEFT) |
204 flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; | 205 return flags | gfx::Canvas::FORCE_RTL_DIRECTIONALITY; |
205 } else if (directionality_mode() == gfx::DIRECTIONALITY_FROM_TEXT) { | 206 return flags | gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
206 base::i18n::TextDirection direction = | |
207 base::i18n::GetFirstStrongCharacterDirection(text()); | |
208 if (direction == base::i18n::RIGHT_TO_LEFT) | |
209 flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; | |
210 else | |
211 flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | |
212 } | |
213 | |
214 return flags; | |
215 } | 207 } |
216 | 208 |
217 void InnerBoundedLabel::ClearCaches() { | 209 void InnerBoundedLabel::ClearCaches() { |
218 wrapped_text_width_ = 0; | 210 wrapped_text_width_ = 0; |
219 wrapped_text_lines_ = 0; | 211 wrapped_text_lines_ = 0; |
220 lines_cache_.clear(); | 212 lines_cache_.clear(); |
221 lines_widths_.clear(); | 213 lines_widths_.clear(); |
222 size_cache_.clear(); | 214 size_cache_.clear(); |
223 size_widths_and_lines_.clear(); | 215 size_widths_and_lines_.clear(); |
224 } | 216 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 343 |
352 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 344 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
353 label_->SetNativeTheme(theme); | 345 label_->SetNativeTheme(theme); |
354 } | 346 } |
355 | 347 |
356 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { | 348 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { |
357 return JoinString(label_->GetWrappedText(width, lines), '\n'); | 349 return JoinString(label_->GetWrappedText(width, lines), '\n'); |
358 } | 350 } |
359 | 351 |
360 } // namespace message_center | 352 } // namespace message_center |
OLD | NEW |