Chromium Code Reviews| Index: ui/views/controls/label.cc |
| =================================================================== |
| --- ui/views/controls/label.cc (revision 239550) |
| +++ ui/views/controls/label.cc (working copy) |
| @@ -27,8 +27,6 @@ |
| namespace { |
| -// The padding for the focus border when rendering focused text. |
| -const int kFocusBorderPadding = 1; |
| const int kCachedSizeLimit = 10; |
| gfx::FontList GetDefaultFontList() { |
| @@ -42,6 +40,7 @@ |
| // static |
| const char Label::kViewClassName[] = "Label"; |
| +const int Label::kFocusBorderPadding = 1; |
| Label::Label() { |
| Init(string16(), GetDefaultFontList()); |
| @@ -201,17 +200,9 @@ |
| SizeToPreferredSize(); |
| } |
| -void Label::SetHasFocusBorder(bool has_focus_border) { |
| - has_focus_border_ = has_focus_border; |
| - if (is_multi_line_) { |
| - ResetCachedSize(); |
| - PreferredSizeChanged(); |
| - } |
| -} |
| - |
| gfx::Insets Label::GetInsets() const { |
| gfx::Insets insets = View::GetInsets(); |
| - if (focusable() || has_focus_border_) { |
| + if (IsFocusable()) { |
|
sky
2013/12/10 17:18:00
Why do you want IsFocusable() here rather than foc
|
| insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, |
| kFocusBorderPadding, kFocusBorderPadding); |
| } |
| @@ -231,12 +222,25 @@ |
| if (!visible() && collapse_when_hidden_) |
| return gfx::Size(); |
| - gfx::Size prefsize(GetTextSize()); |
| + gfx::Size size(GetTextSize()); |
| gfx::Insets insets = GetInsets(); |
| - prefsize.Enlarge(insets.width(), insets.height()); |
| - return prefsize; |
| + size.Enlarge(insets.width(), insets.height()); |
| + return size; |
| } |
| +gfx::Size Label::GetMinimumSize() { |
| + gfx::Size text_size(GetTextSize()); |
| + if ((!visible() && collapse_when_hidden_) || text_size.IsEmpty()) |
| + return gfx::Size(); |
| + |
| + gfx::Size size(font_list_.GetStringWidth(string16(gfx::kEllipsisUTF16)), |
| + font_list_.GetHeight()); |
| + size.SetToMin(text_size); // The actual text may be shorter than an ellipsis. |
| + gfx::Insets insets = GetInsets(); |
| + size.Enlarge(insets.width(), insets.height()); |
| + return size; |
| +} |
| + |
| int Label::GetHeightForWidth(int w) { |
| if (!is_multi_line_) |
| return View::GetHeightForWidth(w); |
| @@ -381,7 +385,6 @@ |
| elide_behavior_ = ELIDE_AT_END; |
| collapse_when_hidden_ = false; |
| directionality_mode_ = USE_UI_DIRECTIONALITY; |
| - has_focus_border_ = false; |
| enabled_shadow_color_ = 0; |
| disabled_shadow_color_ = 0; |
| shadow_offset_.SetPoint(1, 1); |