| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 void SetNativeTheme(const ui::NativeTheme* theme); | 39 void SetNativeTheme(const ui::NativeTheme* theme); |
| 40 | 40 |
| 41 // Pass in a -1 width to use the preferred width, a -1 limit to skip limits. | 41 // Pass in a -1 width to use the preferred width, a -1 limit to skip limits. |
| 42 int GetLinesForWidthAndLimit(int width, int limit); | 42 int GetLinesForWidthAndLimit(int width, int limit); |
| 43 gfx::Size GetSizeForWidthAndLines(int width, int lines); | 43 gfx::Size GetSizeForWidthAndLines(int width, int lines); |
| 44 std::vector<base::string16> GetWrappedText(int width, int lines); | 44 std::vector<base::string16> GetWrappedText(int width, int lines); |
| 45 | 45 |
| 46 // Overridden from views::Label. | 46 // Overridden from views::Label. |
| 47 void SetText(const base::string16& text) override; | 47 void SetText(const base::string16& text) override; |
| 48 void OnPaint(gfx::Canvas* canvas) override; |
| 48 | 49 |
| 49 protected: | 50 protected: |
| 50 // Overridden from views::Label. | 51 // Overridden from views::Label. |
| 51 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 52 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
| 52 void OnPaint(gfx::Canvas* canvas) override; | |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 int GetTextFlags(); | 55 int GetTextFlags(); |
| 56 | 56 |
| 57 void ClearCaches(); | 57 void ClearCaches(); |
| 58 int GetCachedLines(int width); | 58 int GetCachedLines(int width); |
| 59 void SetCachedLines(int width, int lines); | 59 void SetCachedLines(int width, int lines); |
| 60 gfx::Size GetCachedSize(const std::pair<int, int>& width_and_lines); | 60 gfx::Size GetCachedSize(const std::pair<int, int>& width_and_lines); |
| 61 void SetCachedSize(std::pair<int, int> width_and_lines, gfx::Size size); | 61 void SetCachedSize(std::pair<int, int> width_and_lines, gfx::Size size); |
| 62 | 62 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 312 |
| 313 gfx::Size BoundedLabel::GetPreferredSize() const { | 313 gfx::Size BoundedLabel::GetPreferredSize() const { |
| 314 return visible() ? label_->GetSizeForWidthAndLines(-1, -1) : gfx::Size(); | 314 return visible() ? label_->GetSizeForWidthAndLines(-1, -1) : gfx::Size(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 int BoundedLabel::GetHeightForWidth(int width) const { | 317 int BoundedLabel::GetHeightForWidth(int width) const { |
| 318 return visible() ? | 318 return visible() ? |
| 319 label_->GetSizeForWidthAndLines(width, line_limit_).height() : 0; | 319 label_->GetSizeForWidthAndLines(width, line_limit_).height() : 0; |
| 320 } | 320 } |
| 321 | 321 |
| 322 void BoundedLabel::Paint(gfx::Canvas* canvas, const views::CullSet& cull_set) { | 322 void BoundedLabel::OnPaint(gfx::Canvas* canvas) { |
| 323 if (visible()) | 323 label_->OnPaint(canvas); |
| 324 label_->Paint(canvas, cull_set); | |
| 325 } | 324 } |
| 326 | 325 |
| 327 bool BoundedLabel::CanProcessEventsWithinSubtree() const { | 326 bool BoundedLabel::CanProcessEventsWithinSubtree() const { |
| 328 return label_->CanProcessEventsWithinSubtree(); | 327 return label_->CanProcessEventsWithinSubtree(); |
| 329 } | 328 } |
| 330 | 329 |
| 331 void BoundedLabel::GetAccessibleState(ui::AXViewState* state) { | 330 void BoundedLabel::GetAccessibleState(ui::AXViewState* state) { |
| 332 label_->GetAccessibleState(state); | 331 label_->GetAccessibleState(state); |
| 333 } | 332 } |
| 334 | 333 |
| 335 void BoundedLabel::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 334 void BoundedLabel::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 336 label_->SetBoundsRect(bounds()); | 335 label_->SetBoundsRect(bounds()); |
| 337 views::View::OnBoundsChanged(previous_bounds); | 336 views::View::OnBoundsChanged(previous_bounds); |
| 338 } | 337 } |
| 339 | 338 |
| 340 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 339 void BoundedLabel::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 341 label_->SetNativeTheme(theme); | 340 label_->SetNativeTheme(theme); |
| 342 } | 341 } |
| 343 | 342 |
| 344 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { | 343 base::string16 BoundedLabel::GetWrappedTextForTest(int width, int lines) { |
| 345 return JoinString(label_->GetWrappedText(width, lines), '\n'); | 344 return JoinString(label_->GetWrappedText(width, lines), '\n'); |
| 346 } | 345 } |
| 347 | 346 |
| 348 } // namespace message_center | 347 } // namespace message_center |
| OLD | NEW |