| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 gfx::Size size; | 897 gfx::Size size; |
| 898 if (text().empty()) { | 898 if (text().empty()) { |
| 899 size = gfx::Size(0, std::max(line_height(), font_list().GetHeight())); | 899 size = gfx::Size(0, std::max(line_height(), font_list().GetHeight())); |
| 900 } else if (!multi_line() || render_text_->MultilineSupported()) { | 900 } else if (!multi_line() || render_text_->MultilineSupported()) { |
| 901 // Cancel the display rect of |render_text_|. The display rect may be | 901 // Cancel the display rect of |render_text_|. The display rect may be |
| 902 // specified in GetHeightForWidth(), and specifying empty Rect cancels | 902 // specified in GetHeightForWidth(), and specifying empty Rect cancels |
| 903 // its effect. See also the comment in GetHeightForWidth(). | 903 // its effect. See also the comment in GetHeightForWidth(). |
| 904 // TODO(mukai): use gfx::Rect() to compute the ideal size rather than | 904 // TODO(mukai): use gfx::Rect() to compute the ideal size rather than |
| 905 // the current width(). See crbug.com/468494, crbug.com/467526, and | 905 // the current width(). See crbug.com/468494, crbug.com/467526, and |
| 906 // the comment for MultilinePreferredSizeTest in label_unittest.cc. | 906 // the comment for MultilinePreferredSizeTest in label_unittest.cc. |
| 907 render_text_->SetDisplayRect(gfx::Rect(0, 0, width(), 0)); | 907 const int available_width = width() - GetInsets().width(); |
| 908 render_text_->SetDisplayRect(gfx::Rect(0, 0, available_width, 0)); |
| 908 size = render_text_->GetStringSize(); | 909 size = render_text_->GetStringSize(); |
| 909 } else { | 910 } else { |
| 910 // Get the natural text size, unelided and only wrapped on newlines. | 911 // Get the natural text size, unelided and only wrapped on newlines. |
| 911 std::vector<base::string16> lines = GetLinesForWidth(width()); | 912 std::vector<base::string16> lines = GetLinesForWidth(width()); |
| 912 std::unique_ptr<gfx::RenderText> render_text( | 913 std::unique_ptr<gfx::RenderText> render_text( |
| 913 gfx::RenderText::CreateInstance()); | 914 gfx::RenderText::CreateInstance()); |
| 914 render_text->SetFontList(font_list()); | 915 render_text->SetFontList(font_list()); |
| 915 for (size_t i = 0; i < lines.size(); ++i) { | 916 for (size_t i = 0; i < lines.size(); ++i) { |
| 916 render_text->SetText(lines[i]); | 917 render_text->SetText(lines[i]); |
| 917 const gfx::Size line = render_text->GetStringSize(); | 918 const gfx::Size line = render_text->GetStringSize(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 .WriteText(GetSelectedText()); | 1015 .WriteText(GetSelectedText()); |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1017 void Label::BuildContextMenuContents() { | 1018 void Label::BuildContextMenuContents() { |
| 1018 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1019 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1019 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1020 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1020 IDS_APP_SELECT_ALL); | 1021 IDS_APP_SELECT_ALL); |
| 1021 } | 1022 } |
| 1022 | 1023 |
| 1023 } // namespace views | 1024 } // namespace views |
| OLD | NEW |