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

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: selfnits 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 ee72e83bd6153321e93688f17804ae72f10813aa..3d001cd55851d379ed1718316bb61ab1aa8e9eff 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) {
+ Init(text);
+}
- SetAccessibleName(text);
+LabelButton::~LabelButton() {
}
-LabelButton::~LabelButton() {}
+void LabelButton::InitAsButton(const base::string16& text) {
+ SetDefaultStyle(STYLE_BUTTON);
+ Init(text);
+}
+
+void LabelButton::Init(const base::string16& text) {
+ SetText(text);
+ SetStyle(style_ == STYLE_COUNT ? STYLE_TEXTBUTTON : style_);
+}
const gfx::ImageSkia& LabelButton::GetImage(ButtonState for_state) {
if (for_state != STATE_NORMAL && button_state_images_[for_state].isNull())
@@ -351,11 +361,16 @@ void LabelButton::SetBorder(scoped_ptr<Border> border) {
ResetCachedPreferredSize();
}
+void LabelButton::SetDefaultStyle(ButtonStyle style) {
+ style_ = style;
+}
+
gfx::Rect LabelButton::GetChildAreaBounds() {
return GetLocalBounds();
}
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());
}

Powered by Google App Engine
This is Rietveld 408576698