| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 271 |
| 270 const size_t position = text_.size() - remaining_string.size(); | 272 const size_t position = text_.size() - remaining_string.size(); |
| 271 | 273 |
| 272 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); | 274 const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height); |
| 273 std::vector<base::string16> substrings; | 275 std::vector<base::string16> substrings; |
| 274 gfx::FontList text_font_list = font_list_; | 276 gfx::FontList text_font_list = font_list_; |
| 275 // If the start of the remaining text is inside a styled range, the font | 277 // If the start of the remaining text is inside a styled range, the font |
| 276 // style may differ from the base font. The font specified by the range | 278 // style may differ from the base font. The font specified by the range |
| 277 // should be used when eliding text. | 279 // should be used when eliding text. |
| 278 if (position >= range.start()) { | 280 if (position >= range.start()) { |
| 279 text_font_list = text_font_list.DeriveWithStyle( | 281 text_font_list = |
| 280 current_range->style_info.font_style); | 282 text_font_list.Derive(0, current_range->style_info.font_style, |
| 283 current_range->style_info.weight); |
| 281 } | 284 } |
| 282 gfx::ElideRectangleText(remaining_string, | 285 gfx::ElideRectangleText(remaining_string, |
| 283 text_font_list, | 286 text_font_list, |
| 284 chunk_bounds.width(), | 287 chunk_bounds.width(), |
| 285 chunk_bounds.height(), | 288 chunk_bounds.height(), |
| 286 gfx::WRAP_LONG_WORDS, | 289 gfx::WRAP_LONG_WORDS, |
| 287 &substrings); | 290 &substrings); |
| 288 | 291 |
| 289 if (substrings.empty() || substrings[0].empty()) { | 292 if (substrings.empty() || substrings[0].empty()) { |
| 290 // Nothing fits on this line. Start a new line. | 293 // Nothing fits on this line. Start a new line. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 DCHECK_LE(used_width, width); | 376 DCHECK_LE(used_width, width); |
| 374 // The user-specified line height only applies to interline spacing, so the | 377 // The user-specified line height only applies to interline spacing, so the |
| 375 // final line's height is unaffected. | 378 // final line's height is unaffected. |
| 376 int total_height = line * line_height + | 379 int total_height = line * line_height + |
| 377 CalculateLineHeight(font_list_) + GetInsets().height(); | 380 CalculateLineHeight(font_list_) + GetInsets().height(); |
| 378 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); | 381 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); |
| 379 return calculated_size_; | 382 return calculated_size_; |
| 380 } | 383 } |
| 381 | 384 |
| 382 } // namespace views | 385 } // namespace views |
| OLD | NEW |