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

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: self review 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..e9375e7bf5ab949f670ca09b4a7b869277e8a29c 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -83,10 +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_);
-
- SetAccessibleName(text);
tapted 2015/07/13 07:41:22 After updating the Init tests, it seemed silly to
+ // Inset the button focus rect from the actual border; roughly match Windows.
+ SetFocusPainter(
+ Painter::CreateDashedFocusPainterWithInsets(gfx::Insets(3, 3, 3, 3)));
}
LabelButton::~LabelButton() {}
@@ -189,22 +188,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