| 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 438 } |
| 439 | 439 |
| 440 // Text eliding is not supported for multi-lined Labels. | 440 // Text eliding is not supported for multi-lined Labels. |
| 441 // TODO(mukai): Add multi-lined elided text support. | 441 // TODO(mukai): Add multi-lined elided text support. |
| 442 gfx::ElideBehavior elide_behavior = | 442 gfx::ElideBehavior elide_behavior = |
| 443 multi_line() ? gfx::NO_ELIDE : elide_behavior_; | 443 multi_line() ? gfx::NO_ELIDE : elide_behavior_; |
| 444 if (!multi_line() || | 444 if (!multi_line() || |
| 445 (render_text_->MultilineSupported() && !allow_character_break_)) { | 445 (render_text_->MultilineSupported() && !allow_character_break_)) { |
| 446 scoped_ptr<gfx::RenderText> render_text = | 446 scoped_ptr<gfx::RenderText> render_text = |
| 447 CreateRenderText(text(), alignment, directionality, elide_behavior); | 447 CreateRenderText(text(), alignment, directionality, elide_behavior); |
| 448 render_text->SetMultiline(multi_line()); |
| 448 render_text->SetDisplayRect(rect); | 449 render_text->SetDisplayRect(rect); |
| 449 render_text->SetMultiline(multi_line()); | |
| 450 lines_.push_back(render_text.release()); | 450 lines_.push_back(render_text.release()); |
| 451 // lines_.back()->SetText(lines_[0]->GetDisplayText()); |
| 451 } else { | 452 } else { |
| 452 std::vector<base::string16> lines = GetLinesForWidth(rect.width()); | 453 std::vector<base::string16> lines = GetLinesForWidth(rect.width()); |
| 453 if (lines.size() > 1) | 454 if (lines.size() > 1) |
| 454 rect.set_height(std::max(line_height(), font_list().GetHeight())); | 455 rect.set_height(std::max(line_height(), font_list().GetHeight())); |
| 455 | 456 |
| 456 const int bottom = GetContentsBounds().bottom(); | 457 const int bottom = GetContentsBounds().bottom(); |
| 457 for (size_t i = 0; i < lines.size() && rect.y() <= bottom; ++i) { | 458 for (size_t i = 0; i < lines.size() && rect.y() <= bottom; ++i) { |
| 458 scoped_ptr<gfx::RenderText> line = | 459 scoped_ptr<gfx::RenderText> line = |
| 459 CreateRenderText(lines[i], alignment, directionality, elide_behavior); | 460 CreateRenderText(lines[i], alignment, directionality, elide_behavior); |
| 460 line->SetDisplayRect(rect); | 461 line->SetDisplayRect(rect); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 } | 544 } |
| 544 | 545 |
| 545 bool Label::ShouldShowDefaultTooltip() const { | 546 bool Label::ShouldShowDefaultTooltip() const { |
| 546 const gfx::Size text_size = GetTextSize(); | 547 const gfx::Size text_size = GetTextSize(); |
| 547 const gfx::Size size = GetContentsBounds().size(); | 548 const gfx::Size size = GetContentsBounds().size(); |
| 548 return !obscured() && (text_size.width() > size.width() || | 549 return !obscured() && (text_size.width() > size.width() || |
| 549 (multi_line() && text_size.height() > size.height())); | 550 (multi_line() && text_size.height() > size.height())); |
| 550 } | 551 } |
| 551 | 552 |
| 552 } // namespace views | 553 } // namespace views |
| OLD | NEW |