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

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

Issue 1216673005: views::LabelButton should not call virtual methods from its constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150703-Views-ButtonBorderRefactor
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
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | ui/views/controls/button/label_button_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ee72e83bd6153321e93688f17804ae72f10813aa..347d2d755f9e1e0a565c661e73a5e780a701b4d5 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -59,7 +59,7 @@ const int LabelButton::kHoverAnimationDurationMs = 170;
// static
const char LabelButton::kViewClassName[] = "LabelButton";
-LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
+LabelButton::LabelButton(ButtonListener* listener)
: CustomButton(listener),
image_(new ImageView()),
label_(new Label()),
@@ -69,11 +69,10 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
button_state_colors_(),
explicitly_set_colors_(),
is_default_(false),
- style_(STYLE_TEXTBUTTON),
+ style_(STYLE_COUNT), // Something invalid to ensure Init() is called.
border_is_themed_border_(true),
image_label_spacing_(kSpacing) {
SetAnimationDuration(kHoverAnimationDurationMs);
- SetText(text);
AddChildView(image_);
image_->set_interactive(false);
@@ -82,14 +81,25 @@ LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
label_->SetFontList(cached_normal_font_list_);
label_->SetAutoColorReadabilityEnabled(false);
label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+}
- // Initialize the colors, border, and layout.
- SetStyle(style_);
+LabelButton::LabelButton(ButtonListener* listener, const base::string16& text)
+ : LabelButton(listener) {
+ InitAsTextbutton(text);
+}
- SetAccessibleName(text);
+LabelButton::~LabelButton() {
}
-LabelButton::~LabelButton() {}
+void LabelButton::InitAsTextbutton(const base::string16& text) {
+ SetText(text);
+ SetStyle(STYLE_TEXTBUTTON);
+}
+
+void LabelButton::InitAsButton(const base::string16& text) {
+ SetText(text);
+ SetStyle(STYLE_BUTTON);
+}
const gfx::ImageSkia& LabelButton::GetImage(ButtonState for_state) {
if (for_state != STATE_NORMAL && button_state_images_[for_state].isNull())
@@ -356,6 +366,7 @@ gfx::Rect LabelButton::GetChildAreaBounds() {
}
void LabelButton::OnPaint(gfx::Canvas* canvas) {
+ DCHECK_NE(STYLE_COUNT, style_) << "LabelButton::Init() not called.";
View::OnPaint(canvas);
Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
}
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | ui/views/controls/button/label_button_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698