Chromium Code Reviews| Index: ui/views/controls/styled_label.cc |
| diff --git a/ui/views/controls/styled_label.cc b/ui/views/controls/styled_label.cc |
| index fbd480f35adacc9b0c7b00aeb4575ba44155276d..02572053b94929018c97b9e9391a9db6434d974b 100644 |
| --- a/ui/views/controls/styled_label.cc |
| +++ b/ui/views/controls/styled_label.cc |
| @@ -42,7 +42,12 @@ std::unique_ptr<Label> CreateLabelRange( |
| if (style_info.is_link) { |
| Link* link = new Link(text); |
| link->set_listener(link_listener); |
| - link->SetUnderline((style_info.font_style & gfx::Font::UNDERLINE) != 0); |
| + |
| + // Ignore requests to change the default underline style on Link if that's |
| + // being used for the default focus style. |
| + if (Link::GetDefaultFocusStyle() != Link::FocusStyle::UNDERLINE) |
| + link->SetUnderline((style_info.font_style & gfx::Font::UNDERLINE) != 0); |
| + |
| result.reset(link); |
| } else { |
| result.reset(new Label(text)); |
| @@ -65,7 +70,6 @@ std::unique_ptr<Label> CreateLabelRange( |
| } // namespace |
| - |
| // StyledLabel::RangeStyleInfo ------------------------------------------------ |
| StyledLabel::RangeStyleInfo::RangeStyleInfo() |
| @@ -82,6 +86,12 @@ StyledLabel::RangeStyleInfo StyledLabel::RangeStyleInfo::CreateForLink() { |
| RangeStyleInfo result; |
| result.disable_line_wrapping = true; |
| result.is_link = true; |
| + |
| + // When focus isn't indicated by underline, default to making links underlined |
| + // by default. |
| + if (Link::GetDefaultFocusStyle() != Link::FocusStyle::UNDERLINE) |
| + result.font_style = gfx::Font::UNDERLINE; |
|
tapted
2017/04/19 12:28:45
Of course.. this will add underlines to some Style
tapted
2017/04/20 11:50:18
After my brute-force refactoring in crrev.com/2833
|
| + |
| return result; |
| } |
| @@ -178,16 +188,15 @@ const char* StyledLabel::GetClassName() const { |
| gfx::Insets StyledLabel::GetInsets() const { |
| gfx::Insets insets = View::GetInsets(); |
| + if (Link::GetDefaultFocusStyle() != Link::FocusStyle::RING) |
| + return insets; |
| // We need a focus border iff we contain a link that will have a focus border. |
| // That in turn will be true only if the link is non-empty. |
| for (StyleRanges::const_iterator i(style_ranges_.begin()); |
| i != style_ranges_.end(); ++i) { |
| if (i->style_info.is_link && !i->range.is_empty()) { |
| - const gfx::Insets focus_border_padding( |
| - Label::kFocusBorderPadding, Label::kFocusBorderPadding, |
| - Label::kFocusBorderPadding, Label::kFocusBorderPadding); |
| - insets += focus_border_padding; |
| + insets += gfx::Insets(Link::kFocusBorderPadding); |
| break; |
| } |
| } |
| @@ -350,22 +359,31 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
| label->SetBackgroundColor(displayed_on_background_color_); |
| label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_); |
| - // Calculate the size of the optional focus border, and overlap by that |
| - // amount. Otherwise, "<a>link</a>," will render as "link ,". |
| - gfx::Insets focus_border_insets(label->GetInsets()); |
| - focus_border_insets -= label->View::GetInsets(); |
| const gfx::Size view_size = label->GetPreferredSize(); |
| const gfx::Insets insets = GetInsets(); |
| - label->SetBoundsRect(gfx::Rect( |
| - gfx::Point( |
| - insets.left() + x - focus_border_insets.left(), |
| - insets.top() + line * line_height - focus_border_insets.top()), |
| - view_size)); |
| - x += view_size.width() - focus_border_insets.width(); |
| + gfx::Point view_origin(insets.left() + x, |
| + insets.top() + line * line_height); |
| + if (Link::GetDefaultFocusStyle() == Link::FocusStyle::RING) { |
| + // Calculate the size of the optional focus border, and overlap by that |
| + // amount. Otherwise, "<a>link</a>," will render as "link ,". |
| + gfx::Insets focus_border_insets(label->GetInsets()); |
| + focus_border_insets -= label->View::GetInsets(); |
| + view_origin.Offset(-focus_border_insets.left(), |
| + -focus_border_insets.top()); |
| + label->SetBoundsRect(gfx::Rect(view_origin, view_size)); |
| + x += view_size.width() - focus_border_insets.width(); |
| + used_width = std::max(used_width, x); |
| + total_height = |
| + std::max(total_height, label->bounds().bottom() + insets.bottom() - |
| + focus_border_insets.bottom()); |
| + } else { |
| + label->SetBoundsRect(gfx::Rect(view_origin, view_size)); |
| + x += view_size.width(); |
| + total_height = |
| + std::max(total_height, label->bounds().bottom() + insets.bottom()); |
| + } |
| used_width = std::max(used_width, x); |
| - total_height = |
| - std::max(total_height, label->bounds().bottom() + insets.bottom() - |
| - focus_border_insets.bottom()); |
| + |
| if (!dry_run) |
| AddChildView(label.release()); |