Index: ui/views/controls/styled_label.cc |
diff --git a/ui/views/controls/styled_label.cc b/ui/views/controls/styled_label.cc |
index 700e62a392115963ae77adb8abb4a2fb60aa0205..d2d6ec07906d7d313d3f5c1b77117f7b17484ed6 100644 |
--- a/ui/views/controls/styled_label.cc |
+++ b/ui/views/controls/styled_label.cc |
@@ -97,7 +97,8 @@ StyledLabel::StyledLabel(const base::string16& text, |
: specified_line_height_(0), |
listener_(listener), |
displayed_on_background_color_set_(false), |
- auto_color_readability_enabled_(true) { |
+ auto_color_readability_enabled_(true), |
+ layout_built_for_width_(0) { |
base::TrimWhitespace(text, base::TRIM_TRAILING, &text_); |
} |
@@ -140,8 +141,16 @@ void StyledLabel::SetLineHeight(int line_height) { |
} |
void StyledLabel::SetDisplayedOnBackgroundColor(SkColor color) { |
+ if (displayed_on_background_color_ == color) |
+ return; |
+ |
displayed_on_background_color_ = color; |
displayed_on_background_color_set_ = true; |
+ |
+ for (int i = 0, count = child_count(); i < count; ++i) { |
+ static_cast<Label*>(child_at(i))-> |
sky
2014/12/11 15:48:54
DCHECK the class name of the child is Label::kView
edjomin
2014/12/12 08:58:23
Done.
|
+ SetBackgroundColor(displayed_on_background_color_); |
+ } |
} |
gfx::Insets StyledLabel::GetInsets() const { |
@@ -164,19 +173,23 @@ gfx::Insets StyledLabel::GetInsets() const { |
} |
int StyledLabel::GetHeightForWidth(int w) const { |
- if (w != calculated_size_.width()) { |
- // TODO(erg): Munge the const-ness of the style label. CalculateAndDoLayout |
- // doesn't actually make any changes to member variables when |dry_run| is |
- // set to true. In general, the mutating and non-mutating parts shouldn't |
- // be in the same codepath. |
- calculated_size_ = |
- const_cast<StyledLabel*>(this)->CalculateAndDoLayout(w, true); |
- } |
+ // TODO(erg): Munge the const-ness of the style label. CalculateAndDoLayout |
+ // doesn't actually make any changes to member variables when |dry_run| is |
+ // set to true. In general, the mutating and non-mutating parts shouldn't |
+ // be in the same codepath. |
+ |
+ // do not store calculated_size_ for dry_run call. |
sky
2014/12/11 15:48:53
Update your comment, and make sure you capitalize
edjomin
2014/12/12 08:58:23
Done.
edjomin
2014/12/12 08:58:23
Removed this comment because it's useless now, sor
|
+ // calculated_size_ should be cached for non-dry calls only, |
+ // because they create controls alongside with size calculation |
+ // otherwise all caching is useless |
+ calculated_size_ = |
+ const_cast<StyledLabel*>(this)->CalculateAndDoLayout(w, true); |
return calculated_size_.height(); |
} |
void StyledLabel::Layout() { |
calculated_size_ = CalculateAndDoLayout(GetLocalBounds().width(), false); |
+ layout_built_for_width_ = calculated_size_.width(); |
} |
void StyledLabel::PreferredSizeChanged() { |
@@ -190,12 +203,16 @@ void StyledLabel::LinkClicked(Link* source, int event_flags) { |
} |
gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
+ width -= GetInsets().width(); |
+ if (width == calculated_size_.width() && |
+ (dry_run || layout_built_for_width_ == width)) |
+ return calculated_size_; |
+ |
if (!dry_run) { |
RemoveAllChildViews(true); |
link_targets_.clear(); |
} |
- width -= GetInsets().width(); |
if (width <= 0 || text_.empty()) |
return gfx::Size(); |