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

Unified Diff: ui/views/controls/button/label_button.cc

Issue 1228213003: Just set borders once when creating a views::LabelButton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix BookmarkBarViewTest and GlobalErrorServiceBrowserTest Created 5 years, 5 months 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/button/label_button.cc
diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc
index b09a2d821cccd017b62a3006bf32eabbd705614e..72d814b21c7d2d19c7409c45e71bdc227a507ff4 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -83,9 +83,9 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
label_->SetAutoColorReadabilityEnabled(false);
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- // Initialize the colors, border, and layout.
- SetStyle(style_);
-
+ // Inset the button focus rect from the actual border; roughly match Windows.
+ SetFocusPainter(
+ Painter::CreateDashedFocusPainterWithInsets(gfx::Insets(3, 3, 3, 3)));
SetAccessibleName(text);
}
@@ -189,22 +189,21 @@ void LabelButton::SetIsDefault(bool is_default) {
}
void LabelButton::SetStyle(ButtonStyle style) {
+ // All callers currently pass STYLE_BUTTON, and should only call this once, to
+ // change from the default style.
+ DCHECK_EQ(style, STYLE_BUTTON);
+ DCHECK_EQ(style_, STYLE_TEXTBUTTON);
+ DCHECK(!GetWidget()) << "Can't change button style after adding to a Widget.";
+
style_ = style;
- // Inset the button focus rect from the actual border; roughly match Windows.
- if (style == STYLE_BUTTON) {
- SetFocusPainter(nullptr);
- } else {
- SetFocusPainter(Painter::CreateDashedFocusPainterWithInsets(
- gfx::Insets(3, 3, 3, 3)));
- }
- if (style == STYLE_BUTTON) {
- label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
- SetFocusable(true);
- }
- if (style == STYLE_BUTTON)
- SetMinSize(gfx::Size(70, 33));
- OnNativeThemeChanged(GetNativeTheme());
- ResetCachedPreferredSize();
+
+ SetFocusPainter(nullptr);
+ label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
+ SetFocusable(true);
+ SetMinSize(gfx::Size(70, 33));
+
+ // Themed borders will be set once the button is added to a Widget, since that
+ // provides the value of GetNativeTheme().
}
void LabelButton::SetImageLabelSpacing(int spacing) {

Powered by Google App Engine
This is Rietveld 408576698