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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 // Text eliding is not supported for multi-lined Labels. | 444 // Text eliding is not supported for multi-lined Labels. |
445 // TODO(mukai): Add multi-lined elided text support. | 445 // TODO(mukai): Add multi-lined elided text support. |
446 gfx::ElideBehavior elide_behavior = | 446 gfx::ElideBehavior elide_behavior = |
447 multi_line() ? gfx::NO_ELIDE : elide_behavior_; | 447 multi_line() ? gfx::NO_ELIDE : elide_behavior_; |
448 if (!multi_line() || render_text_->MultilineSupported()) { | 448 if (!multi_line() || render_text_->MultilineSupported()) { |
449 scoped_ptr<gfx::RenderText> render_text = | 449 scoped_ptr<gfx::RenderText> render_text = |
450 CreateRenderText(text(), alignment, directionality, elide_behavior); | 450 CreateRenderText(text(), alignment, directionality, elide_behavior); |
451 render_text->SetDisplayRect(rect); | 451 render_text->SetDisplayRect(rect); |
452 render_text->SetMultiline(multi_line()); | 452 render_text->SetMultiline(multi_line()); |
453 render_text->SetWordWrapBehavior(render_text_->word_wrap_behavior()); | 453 render_text->SetWordWrapBehavior(render_text_->word_wrap_behavior()); |
454 lines_.push_back(render_text.release()); | 454 lines_.push_back(render_text.Pass()); |
455 } else { | 455 } else { |
456 std::vector<base::string16> lines = GetLinesForWidth(rect.width()); | 456 std::vector<base::string16> lines = GetLinesForWidth(rect.width()); |
457 if (lines.size() > 1) | 457 if (lines.size() > 1) |
458 rect.set_height(std::max(line_height(), font_list().GetHeight())); | 458 rect.set_height(std::max(line_height(), font_list().GetHeight())); |
459 | 459 |
460 const int bottom = GetContentsBounds().bottom(); | 460 const int bottom = GetContentsBounds().bottom(); |
461 for (size_t i = 0; i < lines.size() && rect.y() <= bottom; ++i) { | 461 for (size_t i = 0; i < lines.size() && rect.y() <= bottom; ++i) { |
462 scoped_ptr<gfx::RenderText> line = | 462 scoped_ptr<gfx::RenderText> line = |
463 CreateRenderText(lines[i], alignment, directionality, elide_behavior); | 463 CreateRenderText(lines[i], alignment, directionality, elide_behavior); |
464 line->SetDisplayRect(rect); | 464 line->SetDisplayRect(rect); |
465 lines_.push_back(line.release()); | 465 lines_.push_back(line.Pass()); |
466 rect.set_y(rect.y() + rect.height()); | 466 rect.set_y(rect.y() + rect.height()); |
467 } | 467 } |
468 // Append the remaining text to the last visible line. | 468 // Append the remaining text to the last visible line. |
469 for (size_t i = lines_.size(); i < lines.size(); ++i) | 469 for (size_t i = lines_.size(); i < lines.size(); ++i) |
470 lines_.back()->SetText(lines_.back()->text() + lines[i]); | 470 lines_.back()->SetText(lines_.back()->text() + lines[i]); |
471 } | 471 } |
472 RecalculateColors(); | 472 RecalculateColors(); |
473 } | 473 } |
474 | 474 |
475 gfx::Rect Label::GetFocusBounds() { | 475 gfx::Rect Label::GetFocusBounds() { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 } | 572 } |
573 | 573 |
574 bool Label::ShouldShowDefaultTooltip() const { | 574 bool Label::ShouldShowDefaultTooltip() const { |
575 const gfx::Size text_size = GetTextSize(); | 575 const gfx::Size text_size = GetTextSize(); |
576 const gfx::Size size = GetContentsBounds().size(); | 576 const gfx::Size size = GetContentsBounds().size(); |
577 return !obscured() && (text_size.width() > size.width() || | 577 return !obscured() && (text_size.width() > size.width() || |
578 (multi_line() && text_size.height() > size.height())); | 578 (multi_line() && text_size.height() > size.height())); |
579 } | 579 } |
580 | 580 |
581 } // namespace views | 581 } // namespace views |
OLD | NEW |