| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/styled_label.h" | 5 #include "ui/views/controls/styled_label.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // Calculates the height of a line of text. Currently returns the height of | 27 // Calculates the height of a line of text. Currently returns the height of |
| 28 // a label. | 28 // a label. |
| 29 int CalculateLineHeight(const gfx::FontList& font_list) { | 29 int CalculateLineHeight(const gfx::FontList& font_list) { |
| 30 Label label; | 30 Label label; |
| 31 label.SetFontList(font_list); | 31 label.SetFontList(font_list); |
| 32 return label.GetPreferredSize().height(); | 32 return label.GetPreferredSize().height(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 scoped_ptr<Label> CreateLabelRange( | 35 std::unique_ptr<Label> CreateLabelRange( |
| 36 const base::string16& text, | 36 const base::string16& text, |
| 37 const gfx::FontList& font_list, | 37 const gfx::FontList& font_list, |
| 38 const StyledLabel::RangeStyleInfo& style_info, | 38 const StyledLabel::RangeStyleInfo& style_info, |
| 39 views::LinkListener* link_listener) { | 39 views::LinkListener* link_listener) { |
| 40 scoped_ptr<Label> result; | 40 std::unique_ptr<Label> result; |
| 41 | 41 |
| 42 if (style_info.is_link) { | 42 if (style_info.is_link) { |
| 43 Link* link = new Link(text); | 43 Link* link = new Link(text); |
| 44 link->set_listener(link_listener); | 44 link->set_listener(link_listener); |
| 45 link->SetUnderline((style_info.font_style & gfx::Font::UNDERLINE) != 0); | 45 link->SetUnderline((style_info.font_style & gfx::Font::UNDERLINE) != 0); |
| 46 result.reset(link); | 46 result.reset(link); |
| 47 } else { | 47 } else { |
| 48 result.reset(new Label(text)); | 48 result.reset(new Label(text)); |
| 49 } | 49 } |
| 50 | 50 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 break; | 300 break; |
| 301 } | 301 } |
| 302 | 302 |
| 303 x = 0; | 303 x = 0; |
| 304 line++; | 304 line++; |
| 305 continue; | 305 continue; |
| 306 } | 306 } |
| 307 | 307 |
| 308 base::string16 chunk = substrings[0]; | 308 base::string16 chunk = substrings[0]; |
| 309 | 309 |
| 310 scoped_ptr<Label> label; | 310 std::unique_ptr<Label> label; |
| 311 if (position >= range.start()) { | 311 if (position >= range.start()) { |
| 312 const RangeStyleInfo& style_info = current_range->style_info; | 312 const RangeStyleInfo& style_info = current_range->style_info; |
| 313 | 313 |
| 314 if (style_info.disable_line_wrapping && chunk.size() < range.length() && | 314 if (style_info.disable_line_wrapping && chunk.size() < range.length() && |
| 315 position == range.start() && x != 0) { | 315 position == range.start() && x != 0) { |
| 316 // If the chunk should not be wrapped, try to fit it entirely on the | 316 // If the chunk should not be wrapped, try to fit it entirely on the |
| 317 // next line. | 317 // next line. |
| 318 x = 0; | 318 x = 0; |
| 319 line++; | 319 line++; |
| 320 continue; | 320 continue; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 DCHECK_LE(used_width, width); | 373 DCHECK_LE(used_width, width); |
| 374 // The user-specified line height only applies to interline spacing, so the | 374 // The user-specified line height only applies to interline spacing, so the |
| 375 // final line's height is unaffected. | 375 // final line's height is unaffected. |
| 376 int total_height = line * line_height + | 376 int total_height = line * line_height + |
| 377 CalculateLineHeight(font_list_) + GetInsets().height(); | 377 CalculateLineHeight(font_list_) + GetInsets().height(); |
| 378 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); | 378 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); |
| 379 return calculated_size_; | 379 return calculated_size_; |
| 380 } | 380 } |
| 381 | 381 |
| 382 } // namespace views | 382 } // namespace views |
| OLD | NEW |