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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } else { | 47 } else { |
48 result.reset(new Label(text)); | 48 result.reset(new Label(text)); |
49 } | 49 } |
50 | 50 |
51 if (style_info.color != SK_ColorTRANSPARENT) | 51 if (style_info.color != SK_ColorTRANSPARENT) |
52 result->SetEnabledColor(style_info.color); | 52 result->SetEnabledColor(style_info.color); |
53 result->SetFontList(font_list); | 53 result->SetFontList(font_list); |
54 | 54 |
55 if (!style_info.tooltip.empty()) | 55 if (!style_info.tooltip.empty()) |
56 result->SetTooltipText(style_info.tooltip); | 56 result->SetTooltipText(style_info.tooltip); |
57 if (style_info.font_style != gfx::Font::NORMAL) { | 57 if (style_info.font_style != gfx::Font::NORMAL || |
58 result->SetFontList( | 58 style_info.weight != gfx::Font::Weight::NORMAL) { |
59 result->font_list().DeriveWithStyle(style_info.font_style)); | 59 result->SetFontList(result->font_list().Derive(0, style_info.font_style, |
| 60 style_info.weight)); |
60 } | 61 } |
61 | 62 |
62 return result; | 63 return result; |
63 } | 64 } |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 | 67 |
67 | 68 |
68 // StyledLabel::RangeStyleInfo ------------------------------------------------ | 69 // StyledLabel::RangeStyleInfo ------------------------------------------------ |
69 | 70 |
70 StyledLabel::RangeStyleInfo::RangeStyleInfo() | 71 StyledLabel::RangeStyleInfo::RangeStyleInfo() |
71 : font_style(gfx::Font::NORMAL), | 72 : font_style(gfx::Font::NORMAL), |
| 73 weight(gfx::Font::Weight::NORMAL), |
72 color(SK_ColorTRANSPARENT), | 74 color(SK_ColorTRANSPARENT), |
73 disable_line_wrapping(false), | 75 disable_line_wrapping(false), |
74 is_link(false) {} | 76 is_link(false) {} |
75 | 77 |
76 StyledLabel::RangeStyleInfo::~RangeStyleInfo() {} | 78 StyledLabel::RangeStyleInfo::~RangeStyleInfo() {} |
77 | 79 |
78 // static | 80 // static |
79 StyledLabel::RangeStyleInfo StyledLabel::RangeStyleInfo::CreateForLink() { | 81 StyledLabel::RangeStyleInfo StyledLabel::RangeStyleInfo::CreateForLink() { |
80 RangeStyleInfo result; | 82 RangeStyleInfo result; |
81 result.disable_line_wrapping = true; | 83 result.disable_line_wrapping = true; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 270 |
269 const size_t position = text_.size() - remaining_string.size(); | 271 const size_t position = text_.size() - remaining_string.size(); |
270 | 272 |
271 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); | 273 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); |
272 std::vector<base::string16> substrings; | 274 std::vector<base::string16> substrings; |
273 gfx::FontList text_font_list = font_list_; | 275 gfx::FontList text_font_list = font_list_; |
274 // If the start of the remaining text is inside a styled range, the font | 276 // If the start of the remaining text is inside a styled range, the font |
275 // style may differ from the base font. The font specified by the range | 277 // style may differ from the base font. The font specified by the range |
276 // should be used when eliding text. | 278 // should be used when eliding text. |
277 if (position >= range.start()) { | 279 if (position >= range.start()) { |
278 text_font_list = text_font_list.DeriveWithStyle( | 280 text_font_list = |
279 current_range->style_info.font_style); | 281 text_font_list.Derive(0, current_range->style_info.font_style, |
| 282 current_range->style_info.weight); |
280 } | 283 } |
281 gfx::ElideRectangleText(remaining_string, | 284 gfx::ElideRectangleText(remaining_string, |
282 text_font_list, | 285 text_font_list, |
283 chunk_bounds.width(), | 286 chunk_bounds.width(), |
284 chunk_bounds.height(), | 287 chunk_bounds.height(), |
285 gfx::WRAP_LONG_WORDS, | 288 gfx::WRAP_LONG_WORDS, |
286 &substrings); | 289 &substrings); |
287 | 290 |
288 if (substrings.empty() || substrings[0].empty()) { | 291 if (substrings.empty() || substrings[0].empty()) { |
289 // Nothing fits on this line. Start a new line. | 292 // Nothing fits on this line. Start a new line. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 DCHECK_LE(used_width, width); | 375 DCHECK_LE(used_width, width); |
373 // The user-specified line height only applies to interline spacing, so the | 376 // The user-specified line height only applies to interline spacing, so the |
374 // final line's height is unaffected. | 377 // final line's height is unaffected. |
375 int total_height = line * line_height + | 378 int total_height = line * line_height + |
376 CalculateLineHeight(font_list_) + GetInsets().height(); | 379 CalculateLineHeight(font_list_) + GetInsets().height(); |
377 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); | 380 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); |
378 return calculated_size_; | 381 return calculated_size_; |
379 } | 382 } |
380 | 383 |
381 } // namespace views | 384 } // namespace views |
OLD | NEW |