OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/controls/label.h" | 5 #include "ui/views/controls/label.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); | 495 focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); |
496 focus_bounds.Intersect(GetLocalBounds()); | 496 focus_bounds.Intersect(GetLocalBounds()); |
497 return focus_bounds; | 497 return focus_bounds; |
498 } | 498 } |
499 | 499 |
500 std::vector<base::string16> Label::GetLinesForWidth(int width) const { | 500 std::vector<base::string16> Label::GetLinesForWidth(int width) const { |
501 std::vector<base::string16> lines; | 501 std::vector<base::string16> lines; |
502 const gfx::WordWrapBehavior wrap = | 502 // |width| can be 0 when getting the default text size, in that case |
503 allow_character_break_ ? gfx::WRAP_LONG_WORDS : gfx::TRUNCATE_LONG_WORDS; | 503 // the ideal lines (i.e. broken at newline characters) are wanted. |
504 gfx::ElideRectangleText(render_text_->GetDisplayText(), font_list(), width, | 504 if (width <= 0) { |
505 std::numeric_limits<int>::max(), wrap, &lines); | 505 base::SplitString(render_text_->GetDisplayText(), '\n', &lines); |
| 506 } else { |
| 507 const gfx::WordWrapBehavior wrap = allow_character_break_ |
| 508 ? gfx::WRAP_LONG_WORDS |
| 509 : gfx::TRUNCATE_LONG_WORDS; |
| 510 gfx::ElideRectangleText(render_text_->GetDisplayText(), font_list(), width, |
| 511 std::numeric_limits<int>::max(), wrap, &lines); |
| 512 } |
506 return lines; | 513 return lines; |
507 } | 514 } |
508 | 515 |
509 gfx::Size Label::GetTextSize() const { | 516 gfx::Size Label::GetTextSize() const { |
510 gfx::Size size; | 517 gfx::Size size; |
511 if (text().empty()) { | 518 if (text().empty()) { |
512 size = gfx::Size(0, std::max(line_height(), font_list().GetHeight())); | 519 size = gfx::Size(0, std::max(line_height(), font_list().GetHeight())); |
513 } else if (!multi_line() || | 520 } else if (!multi_line() || |
514 (render_text_->MultilineSupported() && !allow_character_break_)) { | 521 (render_text_->MultilineSupported() && !allow_character_break_)) { |
515 // Cancel the display rect of |render_text_|. The display rect may be | 522 // Cancel the display rect of |render_text_|. The display rect may be |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 581 } |
575 | 582 |
576 bool Label::ShouldShowDefaultTooltip() const { | 583 bool Label::ShouldShowDefaultTooltip() const { |
577 const gfx::Size text_size = GetTextSize(); | 584 const gfx::Size text_size = GetTextSize(); |
578 const gfx::Size size = GetContentsBounds().size(); | 585 const gfx::Size size = GetContentsBounds().size(); |
579 return !obscured() && (text_size.width() > size.width() || | 586 return !obscured() && (text_size.width() > size.width() || |
580 (multi_line() && text_size.height() > size.height())); | 587 (multi_line() && text_size.height() > size.height())); |
581 } | 588 } |
582 | 589 |
583 } // namespace views | 590 } // namespace views |
OLD | NEW |