Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: ui/views/controls/label.cc

Issue 111023004: Add GetMinimumSize() for Labels and ensure it's zero for empty Links. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698