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..44e42ed6549d271288d9aeefd5b50c4c6bad50d4 100644 |
--- a/ui/views/controls/styled_label.cc |
+++ b/ui/views/controls/styled_label.cc |
@@ -96,6 +96,8 @@ StyledLabel::StyledLabel(const base::string16& text, |
StyledLabelListener* listener) |
: specified_line_height_(0), |
listener_(listener), |
+ width_at_last_layout_(0), |
+ displayed_on_background_color_(SkColorSetRGB(0xFF, 0xFF, 0xFF)), |
displayed_on_background_color_set_(false), |
auto_color_readability_enabled_(true) { |
base::TrimWhitespace(text, base::TRIM_TRAILING, &text_); |
@@ -140,8 +142,18 @@ void StyledLabel::SetLineHeight(int line_height) { |
} |
void StyledLabel::SetDisplayedOnBackgroundColor(SkColor color) { |
+ if (displayed_on_background_color_ == color && |
+ displayed_on_background_color_set_) |
+ return; |
+ |
displayed_on_background_color_ = color; |
displayed_on_background_color_set_ = true; |
+ |
+ for (int i = 0, count = child_count(); i < count; ++i) { |
+ DCHECK((child_at(i)->GetClassName() == Label::kViewClassName) || |
+ (child_at(i)->GetClassName() == Link::kViewClassName)); |
+ static_cast<Label*>(child_at(i))->SetBackgroundColor(color); |
+ } |
} |
gfx::Insets StyledLabel::GetInsets() const { |
@@ -164,19 +176,18 @@ 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. |
+ calculated_size_ = |
+ const_cast<StyledLabel*>(this)->CalculateAndDoLayout(w, true); |
return calculated_size_.height(); |
} |
void StyledLabel::Layout() { |
calculated_size_ = CalculateAndDoLayout(GetLocalBounds().width(), false); |
+ width_at_last_layout_ = calculated_size_.width(); |
} |
void StyledLabel::PreferredSizeChanged() { |
@@ -190,12 +201,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 || width_at_last_layout_ == width)) |
+ return calculated_size_; |
+ |
if (!dry_run) { |
RemoveAllChildViews(true); |
link_targets_.clear(); |
} |
- width -= GetInsets().width(); |
if (width <= 0 || text_.empty()) |
return gfx::Size(); |