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

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

Issue 14077011: Views: Use the new button style instead of native-styled buttons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Accomodate bold text for STYLE_BUTTON default buttons. Created 7 years, 8 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 | « no previous file | no next file » | 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 5063715320d0c5fbd8a5c3375e7568b0db245167..0915a9b45e0d1d3b011765881789166d3b86a4be 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -120,18 +120,30 @@ void LabelButton::SetIsDefault(bool is_default) {
is_default_ = is_default;
ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE);
is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel);
+
+ // STYLE_BUTTON uses bold text to indicate default buttons.
+ if (style_ == STYLE_BUTTON) {
+ int style = label_->font().GetStyle();
+ style = is_default ? style | gfx::Font::BOLD : style & !gfx::Font::BOLD;
+ label_->SetFont(label_->font().DeriveFont(0, style));
+ }
}
void LabelButton::SetStyle(ButtonStyle style) {
+ // Use the new button style instead of the native button style.
+ // TODO(msw): Officialy deprecate and remove STYLE_NATIVE_TEXTBUTTON.
+ if (style == STYLE_NATIVE_TEXTBUTTON)
+ style = STYLE_BUTTON;
+
style_ = style;
set_border(new LabelButtonBorder(style));
// Inset the button focus rect from the actual border; roughly match Windows.
if (style == STYLE_TEXTBUTTON || style == STYLE_NATIVE_TEXTBUTTON)
set_focus_border(FocusBorder::CreateDashedFocusBorder(3, 3, 3, 3));
- if (style == STYLE_BUTTON || style == STYLE_NATIVE_TEXTBUTTON)
+ if (style == STYLE_BUTTON || style == STYLE_NATIVE_TEXTBUTTON) {
label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
- if (style == STYLE_NATIVE_TEXTBUTTON)
set_focusable(true);
+ }
if (style == STYLE_BUTTON) {
set_min_size(gfx::Size(70, 31));
const SkColor color = GetNativeTheme()->GetSystemColor(
@@ -145,6 +157,11 @@ void LabelButton::SetStyle(ButtonStyle style) {
}
gfx::Size LabelButton::GetPreferredSize() {
+ // Accomodate bold text in case this STYLE_BUTTON button is ever made default.
+ const gfx::Font font = label_->font();
+ if (style_ == STYLE_BUTTON)
+ label_->SetFont(font.DeriveFont(0, font.GetStyle() | gfx::Font::BOLD));
+
// Resize multi-line labels paired with images to use their available width.
const gfx::Size image_size(image_->GetPreferredSize());
if (GetTextMultiLine() && !image_size.IsEmpty() && !GetText().empty() &&
@@ -159,6 +176,10 @@ gfx::Size LabelButton::GetPreferredSize() {
size.set_height(std::max(size.height(), image_size.height()));
size.Enlarge(image_size.width() + GetInsets().width(), GetInsets().height());
+ // Restore the label's original font without the temporary bold style.
+ if (style_ == STYLE_BUTTON)
+ label_->SetFont(font);
+
// Increase the minimum size monotonically with the preferred size.
size.SetSize(std::max(min_size_.width(), size.width()),
std::max(min_size_.height(), size.height()));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698