| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/label.h" | 5 #include "views/controls/label.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 mouse_over_background_.reset(background); | 134 mouse_over_background_.reset(background); |
| 135 } | 135 } |
| 136 | 136 |
| 137 const Background* Label::GetMouseOverBackground() const { | 137 const Background* Label::GetMouseOverBackground() const { |
| 138 return mouse_over_background_.get(); | 138 return mouse_over_background_.get(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void Label::SizeToFit(int max_width) { | 141 void Label::SizeToFit(int max_width) { |
| 142 DCHECK(is_multi_line_); | 142 DCHECK(is_multi_line_); |
| 143 | 143 |
| 144 std::vector<std::wstring> lines; | 144 std::vector<string16> lines; |
| 145 base::SplitString(UTF16ToWideHack(text_), L'\n', &lines); | 145 base::SplitString(text_, '\n', &lines); |
| 146 | 146 |
| 147 int label_width = 0; | 147 int label_width = 0; |
| 148 for (std::vector<std::wstring>::const_iterator iter = lines.begin(); | 148 for (std::vector<string16>::const_iterator iter = lines.begin(); |
| 149 iter != lines.end(); ++iter) { | 149 iter != lines.end(); ++iter) { |
| 150 label_width = std::max(label_width, | 150 label_width = std::max(label_width, font_.GetStringWidth(*iter)); |
| 151 font_.GetStringWidth(WideToUTF16Hack(*iter))); | |
| 152 } | 151 } |
| 153 | 152 |
| 154 label_width += GetInsets().width(); | 153 label_width += GetInsets().width(); |
| 155 | 154 |
| 156 if (max_width > 0) | 155 if (max_width > 0) |
| 157 label_width = std::min(label_width, max_width); | 156 label_width = std::min(label_width, max_width); |
| 158 | 157 |
| 159 SetBounds(x(), y(), label_width, 0); | 158 SetBounds(x(), y(), label_width, 0); |
| 160 SizeToPreferredSize(); | 159 SizeToPreferredSize(); |
| 161 } | 160 } |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 font_, GetAvailableRect().width(), true)); | 454 font_, GetAvailableRect().width(), true)); |
| 456 } else { | 455 } else { |
| 457 *paint_text = UTF16ToWideHack(text_); | 456 *paint_text = UTF16ToWideHack(text_); |
| 458 } | 457 } |
| 459 | 458 |
| 460 *text_bounds = GetTextBounds(); | 459 *text_bounds = GetTextBounds(); |
| 461 *flags = ComputeMultiLineFlags(); | 460 *flags = ComputeMultiLineFlags(); |
| 462 } | 461 } |
| 463 | 462 |
| 464 } // namespace views | 463 } // namespace views |
| OLD | NEW |